By Adam Nagy
You may have a part with some work points that show important places in the model. When you derive another part from that model you can also import those work points.
If the edges that the work point is based on are important to you for some reason then how can you get to them in the derived part (e.g. an iPart instance)? Unfortunately, there is no direct way to do that.
The work point's definition only knows what edges in the factory/original part were used to define its position. The corresponding work point in the derived part is not driven by the edges inside the dervied part. The geometry is created based on the orginal part and the position of the work points is also set based on the geometry (e.g. edges) in the base part. They have no connection with the geometry in the derived part.
The API is a bit misleading because it suggests that you could get to the edges that drive the work point in the derived part since it provides WorkPoint.Definition.Line1, but that Edge is in no man's land. It's not the edge residing in the factory and not the edge that is inside the derived part, because you cannot select it in the derived part using Document.SelectSet.Select().
If you want to get back the edge inside the base part then you can first get to the work point in the base part using WorkPoint.ReferencedEntity then check the definition of that: WorkPoint.ReferencedEntity.Definition.Line1
In case of a Face entity residing in the derived part we can get to the original Face that is in the base part using its ReferencedEntity property. So at least we have a one way connection between the original face and the one inside the derived part. That's not the case with the Edge entity.
However, the Edge is the border between two Faces and we can find the original face that corresponds to the face in the derived part. Based on that we can also figure out which original edge corresponds to the edge in the derived part. Thanks for the idea Brian :)
So if you have a derived part that imports a work point that is based on edges in the original model, then using this code you can find the corresponding edge in the derived part:
Function GetEdgeInSurfaceBody(e As Edge, sb As SurfaceBody) ' Go through the edges inside the iPart instance ' to see which one connects the same faces Dim e2 As Edge For Each e2 In sb.Edges If (e2.Faces(1).ReferencedEntity Is e.Faces(1) And _ e2.Faces(2).ReferencedEntity Is e.Faces(2)) Or _ (e2.Faces(1).ReferencedEntity Is e.Faces(2) And _ e2.Faces(2).ReferencedEntity Is e.Faces(1)) Then Set GetEdgeInSurfaceBody = e2 Exit Function End If Next End Function Sub SelectWorkPointEdge() Dim doc As PartDocument Set doc = ThisApplication.ActiveDocument Dim pcd As PartComponentDefinition Set pcd = doc.ComponentDefinition Dim wp As WorkPoint Set wp = pcd.WorkPoints("Edges") Dim dpc As DerivedPartComponent Set dpc = wp.ReferenceComponent ' Ths surface body where we are looking for ' the equivalent of the edge residing in the ' iPart factory Dim sb As SurfaceBody Set sb = dpc.SolidBodies(1).SurfaceBodies(1) ' Get the edge in the base part Dim e As Edge Set e = wp.ReferencedEntity.Definition.Line1 ' Get the edge residing in the iPart instance Dim e2 As Edge Set e2 = GetEdgeInSurfaceBody(e, sb) Call doc.SelectSet.Select(e2) End Sub
Another way to find a given edge in the derived part could be by marking their mid point with a work point and then inside the derived part use FindUsingPoint to find it based on the work point's position:
Sub GetEdgeFromMidpoint() Dim doc As PartDocument Set doc = ThisApplication.ActiveDocument Dim pcd As PartComponentDefinition Set pcd = doc.ComponentDefinition Dim wp As WorkPoint Set wp = pcd.WorkPoints("EdgeMidpoint") Dim objectTypes(0) As SelectionFilterEnum objectTypes(0) = kPartEdgeFilter Dim foundObjects As ObjectsEnumerator Set foundObjects = pcd.FindUsingPoint( _ wp.Point, objectTypes, 0.001) doc.SelectSet.Select foundObjects(1) End Sub