Quantcast
Channel: All Revit API Forum posts
Viewing all 66860 articles
Browse latest View live

Retrieve data on RPC Tree/Shrub Content

$
0
0

We are currently replacing the RPC trees in our software, based on the RPC tree name (type) in Revit to determine what more visually pleasing replacement to render, however, we have found some architects simply have their trees named "Tree", along with the type, or other languages result in trees not called what we have catered for.

 

Just wondering if there is a way to grab the name for the RenderAppearance for the RPC Tree/shrub in the Revit API, as it seems the naming for these can never be changed, and that way we can more accurately determine what tree they are trying to place.

tree.PNGwant render appearance name, not type name.

 

Or if anyone can suggest where I can pull the RPC tree/shrub data in, from the Revit API that would be great :) So far, the replacement works with correct tree scale, but it is assuming the name of the RPC tree is the breed of tree, which is not always the case.

 

Kind Regards,

Joel 


如何判断一个构件属于哪个专业(建筑、结构、机械、电气、管道等)

$
0
0

我想知道一个构件是属于哪个专业的,revit本身的三维可见性设置功能(vv)里面,在过滤器列表中有显示这几个专业的过滤器(建筑、结构、机械、电气、管道),我想知道用revit api 怎么判断一个 Element是属于哪个专业的,或者用什么方法可以判断?

The type of CylindricalFace.Radius is XYZ. Why?

$
0
0

The type of CylindricalSurface.Radius is double.
 It is OK.
But the type of CylindricalFace.Radius is XYZ.
Document's description about this is  "Radii of the surface".
I don't understand it.


How to use it?

Re: Selecting in Linked Documents

$
0
0

Well, you can actually do that in Revit. I do it all the time by enabling links in the selection filters and using Tab. The problem is just that there is still no API to control the selection set in linked document scenarios (which are a standard practice in non-toy projects), e.g., by using unique IDs.

Re: Getting the shape of a FamilyInstance object

$
0
0

Hi,

You can use this method in SDK examples to extract the solids of Element:

public static IList<Solid> GetTargetSolids(Element element)
        {
            List<Solid> solids = new List<Solid>();


            Options options = new Options();
            options.DetailLevel = ViewDetailLevel.Fine;
            GeometryElement geomElem = element.get_Geometry(options);
            foreach (GeometryObject geomObj in geomElem)
            {
                if (geomObj is Solid)
                {
                    Solid solid = (Solid)geomObj;
                    if (solid.Faces.Size > 0 && solid.Volume > 0.0)
                    {
                        solids.Add(solid);
                    }
                    // Single-level recursive check of instances. If viable solids are more than
                    // one level deep, this example ignores them.
                }
                else if (geomObj is GeometryInstance)
                {
                    GeometryInstance geomInst = (GeometryInstance)geomObj;
                    GeometryElement instGeomElem = geomInst.GetInstanceGeometry();
                    foreach (GeometryObject instGeomObj in instGeomElem)
                    {
                        if (instGeomObj is Solid)
                        {
                            Solid solid = (Solid)instGeomObj;
                            if (solid.Faces.Size > 0 && solid.Volume > 0.0)
                            {
                                solids.Add(solid);
                            }
                        }
                    }
                }
            }
            return solids;
        }

Cheer,

Viet.

SetFloatingRectangle() does not work for Revit 2019 API

$
0
0

Hi, 

 

My floating dockable pane position is wrong  on Revit 2019. But the same code works for Revit 2017. Is it a bug on Revit 2019?

OS: win10 x64.

 

I set top, left rectangle: 200, 200,  but the initial position is on the screen’s top left corner. And the width/height is also wrong for the pane.

 

Code is as following:

public partial class CalculateResultDetail : Page, Autodesk.Revit.UI.IDockablePaneProvider

{

 

   public void SetupDockablePane(DockablePaneProviderData data)

    {

        data.FrameworkElement = this as FrameworkElement;

        data.InitialState = new DockablePaneState();

        data.InitialState.DockPosition = Autodesk.Revit.UI.DockPosition.Floating;

        Autodesk.Revit.DB.Rectangle rect = new Autodesk.Revit.DB.Rectangle(200, 200, 500, 1100);

       

        data.InitialState.SetFloatingRectangle(rect);

     }

}

1.png

Re: Get family which element belongs to

$
0
0

Hi

 

I am trying to obtain the Family Names of the instances and element types on my Revit model.

 

I used your suggestion

 (element as FamilySymbol).FamilyName

and was able to retrieve the FamilyName for the Element Types, however, it was not possible to retrive the FamilyName for the instances.

 

To obtain the FamilyName for the instances how would you do it?

 

Many thanks!

Re: Remove or Hide a Ribbon Tab

$
0
0

Thanks for your reply, but where do we find UIFramework?


Re: SendKeys not working for shortcuts in Revit 2019?

$
0
0

Yeah the PostCommand is Working i will use this as a temp solution. i know there must be a way to make it work since the Radial menu that comes with 3D Connection space mouse uses keyboard shortcuts and it does work in Revit 2019.

 

the reason i prefer key shortcuts is because i want to run it as an independent app from revit this way when users call the menu it does not matter if they are in sketch mode or similar, they can always use the tools on the radial menu.

 

but good call man Thanks!

Re: Get family which element belongs to

$
0
0

 

There may be a more straightforward way but this is what I usually do:

 

ElementId typeId = element.GetTypeId();
ElementType type = document.GetElement(typeId) as ElementType;
String familyName = type.FamilyName;

And of course you need to check for typeId being a valid element id and type being not null!

 

Revit RFA families missing thumbnail preview, showing preview in properties

$
0
0

Hello,

 

I have got some RFAs from a vendor that do not have any thumbnail previews appearing in File Explorer. And my utility cannot extract thumbnails from these files. My utility makes use of technique from the following blog,

 http://thebuildingcoder.typepad.com/blog/2010/06/open-revit-ole-storage.html

 

I have observed one interesting that that these files when loaded into Revit project and selected for placement show a preview image in Revit properties area as shown in the image below.

revit_properties_image.PNG

 

I was thinking if Revit generates this image dynamically or it is stored in RFA. If it is generated dynamically, can I make use of some Revit API to extract this image from RFA. Or if it is stored in RFA, how can I retrieve these images?

 

I currently have almost 400 files that do not have previews and in future I am going to get more of these files from the vendor.

 

Any help will be much appreciated.

 

Thanks,

Umar

Re: PromptForFamilyInstancePlacement Disables Some Menu Options

$
0
0

Hi Folks,

 

I found a solution for the item, previously as mentioned in previous post I had been using,

 

 

FamilySymbol symbol = HelperMethods.LoadFamilySymbol(familyFilePath, familySymbolName, revitUIApp.ActiveUIDocument.Document);

BCCSCore.Instance.RevitUIApp.ActiveUIDocument.PromptForFamilyInstancePlacement(symbol);

Instead of the above, now I am using,

 

 

FamilySymbol symbol = HelperMethods.LoadFamilySymbol(familyFilePath, familySymbolName, revitUIApp.ActiveUIDocument.Document);

ElementType elementType = symbol as ElementType;

BCCSCore.Instance.RevitUIApp.ActiveUIDocument.PostRequestForElementTypePlacement (elementType);

This way the execution does not stop at PostRequestForElementTypePlacement, I had to handle this workflow, but it does not disable any of the menus.

 

In my above codes BCCSCore is a singleton class and has an instance of UIApplication class (from Revit Api).

 

Thanks,

Umar

 

 

Change ViewSheet Titleblock

$
0
0

Hello,

 

I have a code that finds the Titleblock used in every ViewSheet that is created with the following code:

 

                    getView = new SortableBindingList<SheetResource>();
                    FilteredElementCollector collector = new FilteredElementCollector(doc);
                    List<ViewSheet> views = collector.OfClass(typeof(ViewSheet))
                    .OfType<ViewSheet>().OrderBy(lev => lev.SheetNumber).ToList();
                    {
                        foreach (ViewSheet v in views)
                        {
                            IList<Element> ElementsOnSheet = new List<Element>();
                            foreach (Element e in new FilteredElementCollector(doc).OwnedByView(v.Id))
                            {
                                ElementsOnSheet.Add(e);
                            }

                            foreach (Element el in ElementsOnSheet)
                            {
                                foreach (FamilySymbol Fs in titleBlockSymbols)
                                {                                   
                                    if (el.GetTypeId().IntegerValue == Fs.Id.IntegerValue)
                                    {
                                        MyTitleBlock = Fs;
                                        dataInRow.UsedTitle = MyTitleBlock.Name;
                                    }
                                }
                            }

The results are shown in a datagridview. I also have a combobox in the datagrid with all the availible titleblocks. I would like to select a titleblock and change the titleblock used in a Viewsheet. But how can you change the Titleblock from a viewsheet with the code above?

 

Thanks!

Cannot Load Family Files

$
0
0

error message every time a family file is tried to be upoloaded

Re: Change ViewSheet Titleblock

$
0
0

A short impression from what i want in the video underneath. So Making New sheets is working, get the used TitleBlocks is working and from my question above, how to update a Titleblock Family in from an existing sheet? 

 

The Datagrid is still a WIP... So don't look to much at the other stuff ;-)

 

Thanks if someone can point me in the right direction.

 

ViewSheet.gif


Re: Get Material Types

Re: 如何判断一个构件属于哪个专业(建筑、结构、机械、电气、管道等)

$
0
0

Revit中Element没有很直接的属性或者方法可以得到哪个专业,我再和研发来确认下是否有其他方法。你所说的三维可见性设置功能也只是每个专业绑定了一些对应的 Category,而不是 Element。你可以通过查找 Element的 Category 对象,然后通过 Category来判断属于哪个专业。

 

 

Get title of ViewSchedule and edit it.

$
0
0

I would like to edit the title of a ViewSchedule that I have created trhough the API. If anyone has any information on how I can get it, and also if we could take it a step further, I would like to know how to add grid separations to the title of the schedule through the API (it is available through the UI, so I imagine it is possible through the api).

struct or class or dictionary

$
0
0

Hello everybody,

 

I programming design of anchor bolts and I am in the early stages.

I have prepared a family for an anchor bolt and the aim is when the code selects a bolt size, the bolt dimensions are all updated; bolt diameter, bolt head size, nut size, etc.

 

I thought I would write the code so when it runs, standard ASTM bolts with all their properties (diameter, head size, nut size, ...) are introduced so we can access them during the design. I want to do this by reading information from a CSV file.

 

My question is what is the best way to introduce this.

 

I am aware of look-up feature in the families but there is a problem. My information in CSV file has 0.1 mm precision and if in the model the precision is for example 1 mm then when I choose a 12.7 mm bolt it can not find it in the table because it searches for 13.  I know I can bypass this by coding but in a general scenario, I want to see what do you guys usually do when you want to introduce some sort of a fixed table (for example bolt information) so that you can use its information during the code.

 

First I thought maybe I have to read CSV file information into a dictionary but then I have to have a multi-dimensional dictionary and it would not be intuitive to call it during programming.

 

Now I am thinking about defining a class or struct for it. Please let me know what you think is the best method. Also consider that I am talking about a fixed number of standard anchor sizes which their properties are defined as table.

 

Thank you very much for the help.

Re: Why is the ElementType empty of all elements in model?

$
0
0

Based on the logic that a Type is used if it has instances then we should iterate the instances, link to the type and extract the type parameters. The main problem you have is deciding if a parameter is on the type or the instance. Named values could be on both so you either need some background information about where the parameters exist or you use the same list of names to search both the instance and the type.

 

Incidentally the Element.LookupParameter method should only be used if you know the name is unique within the element. Best practice is to use either the BuiltInParameter enum value or the SharedParameter GUID.

 

The below is a bit overly complicated as I was experimenting. Also remembered that probably the best way to get a list of elements with solid geometry is to create a 3D view and use the ViewID of that within the filtered element collector.  Most people will set up a view for IFC extraction and probably you could then use the same view for COBie extraction.

 

namespace MapaQuantidades
{
    delegate string AFunc(Parameter P);   
    public class GetNamedParameterValuesClass
    {
       public Result TObj33(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            UIApplication IntApp = commandData.Application;
            if (IntApp.ActiveUIDocument == null)
                return Result.Cancelled;
         Document IntDoc = IntApp.ActiveUIDocument.Document;

         TaskDialog TD = new TaskDialog("Search mode") { MainInstruction = "Type of search for parameters." };
         TD.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "Search based on specific search of likely Type/Instance (Faster)");
         TD.AddCommandLink(TaskDialogCommandLinkId.CommandLink2, "Single list of names used to search on both Type and Instance (Slower)");
         TaskDialogResult Res = TD.Show();

            FilteredElementCollector FEC = new FilteredElementCollector(IntDoc);
            List<ElementId> InstanceIDs = FEC.WhereElementIsNotElementType().WhereElementIsViewIndependent().ToElementIds() as List<ElementId>;

            //With transaction mode not set to readonly could instead of above:
            //1) create a temporary 3D view, hide categories of link, scope boxes, grids etc.
            //2) Set temporary view to fine, (crop and section box will be off for new views)
            //3) Use filtered element collector with overload containing the ViewID of the newly created view
            //4) Delete view

            IEnumerable<Element> Instances = InstanceIDs
                .Select((ElementId eid) => IntDoc.GetElement(eid))
                .Where(el => el == null == false)
                .Where(el => el.GetTypeId() != ElementId.InvalidElementId)
                .Where(J => J.Category == null == false)
                .Where(J => J.Category.CategoryType == CategoryType.Model && J.Category.CanAddSubcategory).Select(f => f);

            List<string> ParamNamesType = new string[8] {
			"Family Name",
			"Width",
			"Classification.Uniclass.Ss.Number",
			"Classification.Uniclass.EF.Number",
			"Classification.Uniclass.Ss.Description",
			"Classification.Uniclass.Pr.Number",
			"Classification.Uniclass.Pr.Description",
			"Cost"
		}.ToList();

            List<string> ParamNamesInst = new string[6] {
			"Length",
			"Area",
			"Quantity",
			"Price",
			"Unit",
			"Total"
		}.ToList();

            //Should know where the parameters exist (Type or Instance) and search based on this.

            if (Res == TaskDialogResult.CommandLink2)
            {
                ParamNamesType = ParamNamesType.Union(ParamNamesInst).ToList();
                ParamNamesInst = ParamNamesType;
            }

            //"Quantity", "Price", "Total", "Unit" : Not found
            //"Type" parameter same as Element.Name and ElementType.Name extracted from class properties below

            AFunc GetParamVal = (Parameter P) =>
            {
                string Out = null;
                if (P.StorageType == StorageType.Double)
                {
                    if (UnitUtils.IsValidDisplayUnit(P.DisplayUnitType))
                    {
                        Out = Convert.ToString(UnitUtils.ConvertFromInternalUnits(P.AsDouble(), P.DisplayUnitType));
                    }
                    else
                    {
                        Out = Convert.ToString(P.AsDouble());
                    }
                }
                else if (P.StorageType == StorageType.Integer)
                {
                    Out = Convert.ToString(P.AsInteger());
                }
                else if (P.StorageType == StorageType.ElementId)
                {
                    //Name for an element referred to by parameter is probably more useful than
                    //ElementID for your purpose
                    Element El = IntDoc.GetElement(P.AsElementId());
                    if (El == null)
                    {
                        Out = Convert.ToString(P.AsElementId().IntegerValue);
                    }
                    else
                    {
                        Out = El.Name;
                    }
                }
                else if (P.StorageType == StorageType.String)
                {
                    Out = P.AsString();
                }
                else
                {
                    return null;
                }

                return Out;
            };


            List<object> ElInfoSet = new List<object>();

            List<string> FoundTypeParamNames = new List<string>();
            List<string> FoundInstParamNames = new List<string>();

            //Should use BuiltInParameter integer values or Shared Parameter GUIDs rather than using Element.LookupParameter
            //Element may have mulptiple parameters of same name and only first found will be returned by Element.LookupParameter

            foreach (Element Inst in Instances)
            {
                ElementType Et = IntDoc.GetElement(Inst.GetTypeId()) as ElementType;
                IEnumerable<object> PValsType = ParamNamesType.Select(s => Et.LookupParameter(s)).Where(P => P == null == false).Where(P => P.StorageType != StorageType.None).Select(P => new
                {
                    PName = P.Definition.Name,
                    Value = GetParamVal(P)
                });

                IEnumerable<object> PValsInstance = ParamNamesInst.Select(s => Inst.LookupParameter(s)).Where(P => P == null == false).Where(P => P.StorageType != StorageType.None).Select(P => new
                {
                    PName = P.Definition.Name,
                    Value = GetParamVal(P)
                });

                dynamic ElInf = new
                {
                    Parameters = new List<Tuple<string, string, bool>>(),
                    ElementID = Inst.Id,
                    ElementName = Inst.Name,
                    TypeName = Et.Name
                };

                foreach (dynamic item in PValsType)
                {
                    ElInf.Parameters.Add(new Tuple<string, string, bool>(item.PName, item.Value, true));
                    if (!FoundTypeParamNames.Contains(item.PName))
                    {
                        FoundTypeParamNames.Add(item.PName);
                    }
                }
                foreach (dynamic item in PValsInstance)
                {
                    ElInf.Parameters.Add(new Tuple<string, string, bool>(item.PName, item.Value, false));
                    if (!FoundInstParamNames.Contains(item.PName))
                    {
                        FoundInstParamNames.Add(item.PName);
                    }
                }
                ElInfoSet.Add(ElInf);
            }

            Microsoft.Office.Interop.Excel.Application xlsApp = new Microsoft.Office.Interop.Excel.Application();
            xlsApp.Visible = true;
            xlsApp.Workbooks.Add();
            Microsoft.Office.Interop.Excel.Worksheet xlsWs = xlsApp.Worksheets.get_Item(1);

            xlsWs.Cells[1, 1] = "ElementID";
            xlsWs.Cells[1, 2] = "ElementName";
            //(Element.Name)
            xlsWs.Cells[1, 3] = "TypeName";
            //(ElementType.Name) Redundant in this usage as usually same as Element.Name for the instance 
           //i.e. the instance uses ElementType.Name for it's name.

            for (int i = 0; i <= FoundInstParamNames.Count - 1; i++)
            {
                xlsWs.Cells[1, i + 4] = FoundInstParamNames[i];
            }
            for (int i = 0; i <= FoundTypeParamNames.Count - 1; i++)
            {
                xlsWs.Cells[1, i + FoundInstParamNames.Count + 4] = FoundTypeParamNames[i];
            }

            for (int Row = 0; Row <= ElInfoSet.Count - 1; Row++)
            {
                dynamic El = ElInfoSet[Row];
                xlsWs.Cells[Row + 2, 1] = El.ElementID;
                xlsWs.Cells[Row + 2, 2] = El.ElementName;
                xlsWs.Cells[Row + 2, 3] = El.TypeName;
                List<Tuple<string, string, bool>> Params = El.Parameters;

                for (int i = 0; i <= FoundInstParamNames.Count - 1; i++)
                {
                    Tuple<string, string, bool> PV = Params.Find(x => x.Item1 == FoundInstParamNames[i]);
                    if (PV == null)
                        continue;
                    xlsWs.Cells[Row + 2, i + 4] = PV.Item2;
                }
                for (int i = 0; i <= FoundTypeParamNames.Count - 1; i++)
                {
                    Tuple<string, string, bool> PV = Params.Find(x => x.Item1 == FoundTypeParamNames[i]);
                    if (PV == null)
                        continue;
                    xlsWs.Cells[Row + 2, i + FoundInstParamNames.Count + 4] = PV.Item2;
                }
             }

           return Result.Succeeded;
        }


    }
     
}

 

Viewing all 66860 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>