Getting Edge Reference from Face

Getting Edge Reference from Face

AGGilliam
Collaborator Collaborator
3,862 Views
4 Replies
Message 1 of 5

Getting Edge Reference from Face

AGGilliam
Collaborator
Collaborator

I'm trying to grab Edge references from a Face reference (I thought about selecting the edge to begin with, but I didn't want the user to accidentally select the wrong edge), and I figured out how to get Curves but not the reference. Trying to grab the reference from those Curves returns null. I found this post which was really helpful, but getting that edge reference to pass in is where I'm getting stuck. Any ideas would be greatly appreciated.

 

Here's the chunk of code I'm working with:

Reference sel1 = uidoc.Selection.PickObject(ObjectType.Face);
Reference sel2 = uidoc.Selection.PickObject(ObjectType.Face);
PlanarFace face1 = (doc.GetElement(sel1) as FamilyInstance).GetGeometryObjectFromReference(sel1) as PlanarFace;
PlanarFace face2 = (doc.GetElement(sel2) as FamilyInstance).GetGeometryObjectFromReference(sel2) as PlanarFace;
List<CurveLoop> list1 = face1.GetEdgesAsCurveLoops().ToList();
List<CurveLoop> list2 = face2.GetEdgesAsCurveLoops().ToList();
List<Curve> curves1 = new List<Curve>();
List<Curve> curves2 = new List<Curve>();
foreach (Curve c in list1[0])
{
    curves1.Add(c);
}
foreach (Curve c in list2[0])
{
    curves2.Add(c);
}
curves1.Sort(SortLines);
curves2.Sort(SortLines);
XYZ point = FindIntersection(curves1[0], curves2[0]); //Where would these edges intersect?
Edge edge1 = GetEdge(curves1[0].Reference, doc); //Use the symbol edge reference to return the instance edge reference
Edge edge2 = GetEdge(curves2[0].Reference, doc);

 *I know the point and edge variables are a bit mixed up, I'm still just trying to figure out the references.

0 Likes
Accepted solutions (2)
3,863 Views
4 Replies
Replies (4)
Message 2 of 5

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Austin,

 

Interesting question, not trivial, and thank you for pointing out the blog post.

 

Have you checked in the debugger that the two faces you pick have valid references?

 

I assume so.

 

I can imagine that the GetEdgesAsCurveLoops method looses the face edges' reference information, if they ever had any at all.

 

You can use those curves to find the intersection, if you must.

 

However, to obtain valid edge references, I suspect that you will have to return to the original elements, retrieve their entire geometry via their Geometry property, specifying ComputeReferences = true in the Options you pass in, and then search for the edges or vertices that match the intersection you determined from the curves. 

 

The matching object from the element geometry is equipped with the valid reference you seek.

 

Good luck, and please let us know how you fare.

 

Thank you!

 

Cheers,

 

Jeremy

 



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

Message 3 of 5

AGGilliam
Collaborator
Collaborator

Thanks for the explanation! I checked, and the faces are indeed valid references, however, it appears they loose their reference after grabbing the PlanarFace. How would I go about finding the intersection with those curves? That's what I tried doing originally but it's referring to the edges of the family rather than the instance.

0 Likes
Message 4 of 5

AGGilliam
Collaborator
Collaborator
Accepted solution

I ended up looping through the geometry in order to grab the edges, using GetInstanceGeometry, and all of the solids were empty. After debugging for a while I swapped GetInstanceGeometry for GetSymbolGeometry and then the solids had faces and edges. (Looking back, perhaps this was because the referenced Element was in a nested family and not activated yet?) After that worked, I added a transform to the edge curves to use the Instance coordinates instead of the Symbol. This post helped a lot with the last part.

In other words, it works! Thank you for the help!

Here's the main section of my code (I can post the whole thing if anyone actually wants to see it):

using (Transaction t = new Transaction(doc, "header"))
{
  t.Start();
  Reference sel1 = uidoc.Selection.PickObject(ObjectType.Face);
  Reference sel2 = uidoc.Selection.PickObject(ObjectType.Face);
  GeometryObject face1 = (doc.GetElement(sel1) as FamilyInstance).GetGeometryObjectFromReference(sel1);
  GeometryObject face2 = (doc.GetElement(sel2) as FamilyInstance).GetGeometryObjectFromReference(sel2);
  List<Edge> edgeList1 = GetEdgesFromFace(sel1, doc, out Transform tran1);
  List<Edge> edgeList2 = GetEdgesFromFace(sel2, doc, out Transform tran2);
  edgeList1.Sort(SortLines);
  edgeList2.Sort(SortLines);
  Curve curve1 = TransformCurve(edgeList1[0].AsCurve(), tran1);
  Curve curve2 = TransformCurve(edgeList2[0].AsCurve(), tran2);
  XYZ intersect = FindIntersection(curve1, curve2);
  t.Commit();
}

 

0 Likes
Message 5 of 5

matias_m1912
Explorer
Explorer
Hi Aggilliam, I'm working in some similar. I will aprecciate if you can share your code.
And congrats for make it works.
Regards.