How to retrieve detail Item Geometry?

How to retrieve detail Item Geometry?

jmyr
Enthusiast Enthusiast
2,348 Views
4 Replies
Message 1 of 5

How to retrieve detail Item Geometry?

jmyr
Enthusiast
Enthusiast
Options options = new Options();
                            GeometryElement geoEle = guidline.get_Geometry(options);

                            foreach (var subEle in geoEle)
                            {
                                Line line = subEle as Line;
                                if (line!= null)
                                {
                                    point1 = line.GetEndPoint(0);
                                    point2 = line.GetEndPoint(1);
                                }
                            }

Hi Guys,

 

I have detail item (Line based family), just a simple line inside but I'm having trouble getting its geometry. Any ideas?

below code is not working.

 

Thanks

Accepted solutions (1)
2,349 Views
4 Replies
Replies (4)
Message 2 of 5

RPTHOMAS108
Mentor
Mentor

Detail items are view specific so Options.View would require a view to be set for it.

 

Since it is a family instance the top level item will be a GeometryInstance from which you can then get the instance or symbol geometry.

 

You can review this in RevitLookup using 'View = ActiveView' branch vs 'View = null'.

Message 3 of 5

jmyr
Enthusiast
Enthusiast

Thanks @RPTHOMAS108 not sure exactly what do you mean, i tried below but still getting null

                            Options options = new Options();
                            options.View = _doc.ActiveView;
                            
                            XYZ point1 = null;
                            XYZ point2 = null;
                           
                            List<GeometryInstance> ginsList = guidline.get_Geometry(options).Where(o => o is GeometryInstance).Cast<GeometryInstance>().ToList();

                            foreach (GeometryInstance gins in ginsList)
                            {
                                foreach (GeometryObject ge in gins.GetSymbolGeometry())
                                {
                                    Line line = ge as Line;
                                    if (line != null)
                                    {
                                        point1 = line.GetEndPoint(0);
                                        point2 = line.GetEndPoint(1);
                                    }
                                }
                            }
Message 4 of 5

RPTHOMAS108
Mentor
Mentor
Accepted solution

From looking at your code I don't see anything obviously wrong. Make sure 'Line' is coming from the Revit API namespace perhaps.

 

Is the active view the one that contains the element? Always best to use UIDocument.ActiveGraphicalView, since the project browser and other interface windows occasionally become the active view. 

 

Using RevitLookup, below is what you should see for a line based detail item family symbol geometry (more common for me to use the instance geometry):

210912c.PNG

 

Message 5 of 5

FrankHolidaytoiling
Advocate
Advocate

This is a bit late, however are you checking the geometry is a Line before accessing it?

if(x is Line) {then do stuff;}

0 Likes