Get HoleFeature xyz Coordinates in Derived Part with VBA

Get HoleFeature xyz Coordinates in Derived Part with VBA

kccameron
Explorer Explorer
708 Views
1 Reply
Message 1 of 2

Get HoleFeature xyz Coordinates in Derived Part with VBA

kccameron
Explorer
Explorer

In VBA, what is the best way to get the center points of the circular edges for all the holes of a Derived Part in an assembly?

 

My ultimate goal is to produce a bolt schedule for a very large assembly (a bridge with about 100,000 holes). There are many reasons why this was not done during modeling, not the least of which is that it was originally out of our scope. I have a working SUB that iterates through each Face of each HoleFeatureProxy of each Leaf Occurrence in the assembly and populates a collection with the circular edges, from which I can extract the center points, etc. in assembly space coordinates. I then match up the holes and calculate bolt lengths.

 

My problem is with the Derived Parts in the assembly. I don't know the best way to retrieve the center points (in the context of the assembly model space) of the HoleFeatures of the derived parts, since they don't actually have HoleFeatures. I could use the edges from the faces in the Surface Body, but I would prefer something that would distinguish between an actual hole and other circular edges. The DerivedPartComponentProxy object sounded promising, but I couldn't figure out how to return HoleFeature, Face, or Edge proxies from the derived part.

 

Below is my working SUB, and I could attach the sample .asm that I'm using for testing if it would help.

 

Sub GetDerivedPartCircles()
   Dim oDoc As AssemblyDocument
   Set oDoc = ThisApplication.ActiveDocument

   ' Get the assembly component definition.
   Dim oAsmDef As AssemblyComponentDefinition
   Set oAsmDef = oDoc.ComponentDefinition
   
   ' Create a collection for the hole face edges.
   Dim oTO As TransientObjects
   Set oTO = ThisApplication.TransientObjects
   Dim cEdges As EdgeCollection
   Set cEdges = oTO.CreateEdgeCollection
   
   ' Get all of the leaf occurrences of the assembly.
   Dim oLeafOccs As ComponentOccurrencesEnumerator
   Set oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences
   Dim oOcc As ComponentOccurrence
   Dim oHoleFeature As HoleFeature
   Dim oHoleFeatureProxy As HoleFeatureProxy
   Dim oFace As FaceProxy
   Dim oEdge As EdgeProxy
   
   ' Get all the holes from each occurrence
   For Each oOcc In oLeafOccs
      ' If this is a standard part...
      If oOcc.Definition.ReferenceComponents.DerivedPartComponents.Count = 0 Then
         ' Get the hole edges.
         For Each oHoleFeature In oOcc.Definition.Features.HoleFeatures
            oOcc.CreateGeometryProxy oHoleFeature, oHoleFeatureProxy
            For Each oFace In oHoleFeatureProxy.Faces
               For Each oEdge In oFace.Edges
                  cEdges.Add oEdge ' Add circular edges to a collection to process later.
               Next oEdge
            Next oFace
         Next oHoleFeature
      Else ' if DerivedPartComponents.count > 0, then this is a Derived Part.
         ' There are no HoleFeatures in the derived part.
         '   (At least in oOcc.Definition.Features.HoleFeatures.)
         ' Need a way to retrieve model-space coordinates for the derived hole features.
      End If
   Next oOcc
End Sub

 

Thanks in advance for any help. 

0 Likes
709 Views
1 Reply
Reply (1)
Message 2 of 2

kccameron
Explorer
Explorer

I'm thinking maybe I should approach this by obtaining the transform matrix that would move the base part to the derived part location, then applying the transform to each of the hole features in the base part to obtain the location of the corresponding geometry in the derived part. Does that sound like a reasonable approach?

 

I haven't worked with transform matrices before. I know they account for translation and rotation, but would they be able to account for a mirrored part? I need to obtain the location and normal vector for each circular edge in the derived part that corresponds to a hole feature face edge in the base part.

 

I want to derive these locations directly from hole features because I'm not sure if I can assume that the circular edges of ALL cylindrical faces in the derived part are necessarily from holes. There is also information in the hole feature I may end up using (threads, for example).

0 Likes