LocationCurve is getting null for Familyinstance.

LocationCurve is getting null for Familyinstance.

praveen.cMXB2H
Enthusiast Enthusiast
343 Views
2 Replies
Message 1 of 3

LocationCurve is getting null for Familyinstance.

praveen.cMXB2H
Enthusiast
Enthusiast

I am able to get LocationCurve reference  for walls but getting null reference for Beams and Columnns.

 

IntersectionResultArray intersectionResultArray = null;
XYZ point = null;

 

LocationCurve hostLocation = e1.Location as LocationCurve;

Curve hostCurve = hostLocation.Curve;

 

//Getting FamilyInstance CurveLocation

FamilyInstance familyInstance = e2  as FamilyInstance;
Location location = familyInstance.Location;
Curve famCurve = (location as LocationCurve).Curve;

 

 

//Here i need to get LocationCurve reference for to find intersection point of the elements.

hostCurve.Intersect(famCurve, out intersectionResultArray);

 

foreach (IntersectionResult intersectionResult in intersectionResultArray)
{
point = intersectionResult.XYZPoint;
}

 

Is there any other way to get intersecting point of two elements, if it is not possible to get LocationCurve of the FamilyInstance.

0 Likes
Accepted solutions (1)
344 Views
2 Replies
Replies (2)
Message 2 of 3

Mohamed_Arshad
Advisor
Advisor
Accepted solution

HI @praveen.cMXB2H 

 

    For Beam you can able to get the Location Curve using LocationCurve Class. But for the column you won't get because column is point based element, So we need to calculate the center line using  BoundingBoxXYZ Class, Kindly check the below code for additional reference.

 

Reference Code

            #region Get Center Curve From the Beam

            LocationCurve locCurve = beamInst.Location as LocationCurve;

            Line beamCurve = locCurve.Curve as Line;

            #endregion


            #region Get Center Curve From the Column

            //Get Bounding Box
            BoundingBoxXYZ bbox = colInst.get_BoundingBox(doc.ActiveView);

            //Get Center Point
            XYZ cp = bbox.Min.Add(bbox.Max).Divide(2.0);

            //Create Top and Bottom Points
            XYZ p1 = new XYZ(cp.X, cp.Y, bbox.Min.Z);
            XYZ p2 = new XYZ(cp.X, cp.Y, bbox.Max.Z);

            //Center Line Creation
            Line columnCurve = Line.CreateBound(p1, p2);


            #endregion


            #region Get Intersection Point

            IntersectionResultArray intersectionResult = null;

            beamCurve.Intersect(columnCurve, out intersectionResult);

            using (Transaction createPoint = new Transaction(doc, "Create Intersect Point"))
            {
                createPoint.Start();

                XYZ intersetionPoint  = intersectionResult.get_Item(0).XYZPoint;

                List<GeometryObject> pointList = new List<GeometryObject>();
                pointList.Add(Point.Create(intersetionPoint));

                //Create Points
                DirectShape shape = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel));
                shape.SetShape(pointList);

                createPoint.Commit();
            }

            #endregio

 

Note:

The Intersection Point will create when the Two Curves Intersect.

 

Hope this will helps 🙂


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 3 of 3

praveen.cMXB2H
Enthusiast
Enthusiast

Hi Arshad,

 

Thank you so much for your reply,  now I am able to get intersection point.

0 Likes