Reference point from FamilyInstance

Reference point from FamilyInstance

Anonymous
Not applicable
5,141 Views
10 Replies
Message 1 of 11

Reference point from FamilyInstance

Anonymous
Not applicable

Hi, I tried to get Reference Point from FamilyInstance by this code from TheBuildingCoder blog:

Reference reference = sectionInstance.get_Geometry(options).OfType<Point>().Select<Point, Reference>(x => x.Reference).FirstOrDefault();

 

Unfortunately I recive null. In family creator I can get ReferencePoint using Dynamo using ReferencePoint.ByPoint so Im sure that those points exist. I tried to recive those point in both by family creator and project. I have two family instances in which I want to use this Conceptual Mass and Adaptive.

 

Here is full code:

  public static Reference GetReferencePoint(string targetSectionName)
        {
            Options options = new Options();
            options.ComputeReferences = true;
            options.DetailLevel = ViewDetailLevel.Undefined;
            options.IncludeNonVisibleObjects = true;
            //Set document as current document
            Document document = RevitServices.Persistence.DocumentManager.Instance.CurrentDBDocument;
            //Collect FamilyInstances
            var symbolCollector = new FilteredElementCollector(document)
                .OfClass(typeof(FamilyInstance));
            //Get FamilyInstance by name
            FamilyInstance sectionInstance = symbolCollector
                .Where(x => ((FamilyInstance)x).Symbol.Name.Equals(targetSectionName))
                .Cast<FamilyInstance>()
                .FirstOrDefault();
            using (Transaction transaction = new Transaction(document, "GetReferencePoint"))
            {
                transaction.Start();
                Reference reference = sectionInstance.get_Geometry(options).OfType<Point>().Select<Point, Reference>(x => x.Reference).FirstOrDefault();
                transaction.Commit();
                return reference;
            }
        }
0 Likes
Accepted solutions (2)
5,142 Views
10 Replies
Replies (10)
Message 2 of 11

jeremytammik
Autodesk
Autodesk

Check whether FamilyInstance.GetReferences provides what you need:

 

https://www.revitapidocs.com/2020/a8a7dc74-db8e-a7b6-a9c8-869397cca6b4.htm

 

Above all, read the documentation before asking a question 🙂

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 11

Anonymous
Not applicable

I'm confused now, from method you mentioned I can get only line and surface references, are those points part of surface reference? 

0 Likes
Message 4 of 11

jeremytammik
Autodesk
Autodesk

I do not know what references you are after.

 

Take a look at all of the solids contained in your element geometry.

 

You can navigate through them all using RevitLookup and other interactive database exploration tools:

 

 

I can well imagine that many element's geometry will not contain any `Point` objects at all.

 

However, if your element has a solid, the solid will have faces, and those faces (or possibly their edges) will be equipped with references.

 

Maybe you can use those instead of the points?

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 11

Anonymous
Not applicable

First of all, RevitLookup... It's such a help!

Secondly, I can find point which I want to get in this tool, but I still dont know how to get it via RevitAPI, I attach screenshots.

point.png

nullreference.png

pointnull.png

 

0 Likes
Message 6 of 11

jeremytammik
Autodesk
Autodesk
Accepted solution

You can run RevitLookup in the debugger and look at the call stack to see the exact sequence of calls and their argument that lead you to the desired information.

 

For instance, when requesting the element geometry, you can specify a specific view. The element geometry returned may be view specific. What view are you requesting it for?

 

By the way, screen snapshots of source code are pretty useless. I cannot read them, and the search engines cannot find them for future reference. It is more useful to paste source code in text format.

 

Thank you!

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 7 of 11

Anonymous
Not applicable
Accepted solution

Succees, I repeated path from Revit Lookup. But one answer brings more questions, first: Why couldnt I get those points by previous method? And why when I set point visibility as not visible I couldn't receive it geometry even with Options IncludeNonVisible Objects property set as true, Revit Lookup also didn't see that. Is the fact that this family was nested in another one a case?

 

But as to main question I think it's solved, here is the code:

GeometryObject geometryObject sectionInstance.get_Geometry(options);
GeometryElement geometryElement = sectionInstance.get_Geometry(options);
GeometryInstance geometryInstance = geometryElement.First() as GeometryInstance;
Point point = geometryInstance.GetInstanceGeometry().OfType<Point>().First();
Message 8 of 11

jeremytammik
Autodesk
Autodesk

View specific geometry. ActiveView.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 9 of 11

Anonymous
Not applicable

I search to cast object of type FamilyInstance to ReferencePoint but I don't met any way to cast. Does anyone have a way to do it?

UIDocument uiDoc = commandData.Application.ActiveUIDocument;

                Selection selection = uiDoc.Selection;
                ICollection<ElementId> elemSelected = selection.GetElementIds();
                if (elemSelected.Count == 2)
                {
                    List<ElementId> elemList = new List<ElementId>();
                    foreach (var element in elemSelected)
                    {
                        elemList.Add(element); 
                    }
                    
                    Element elemFirst = uiDoc.Document.GetElement(elemList[0]);
                    Element elemSecond = uiDoc.Document.GetElement(elemList[1]);
                    
                    ReferencePoint rpFirst = elemFirst as ReferencePoint;
                    
                }
0 Likes
Message 10 of 11

gdavis479JP
Contributor
Contributor

This is another horrible answer Jeremy. Autodesk needs to evaluate the tone of the messaging here. I find this distasteful. First of all, the current link is broken, so "reading" the documentation is not possible. Second, documentation is inconsistent, the program changes, and people have other responsibilities, hence the need for a forum to ask a specific question to get a specific answer. If you are just going to chastise people, how can anyone actually learn to satisfy you.  I too (have been coding in the API for years), and trying to sort out getting the points from a selected element (Pipe Accessories category, no location curve), and am getting nulls. Answer the questions thoughtfully please. If anyone has anything else to offer please do.

0 Likes
Message 11 of 11

Sleepingfish_Kuo
Advocate
Advocate

That answer replied in 2019.

You're complaining to the wrong person.
No one could have predicted that website would be deleted.

 

Try these (edit the "2020" to another year)

https://www.revitapidocs.com/2023/a8a7dc74-db8e-a7b6-a9c8-869397cca6b4.htm

https://www.revitapidocs.com/2025/a8a7dc74-db8e-a7b6-a9c8-869397cca6b4.htm

 

0 Likes