Get HoleFeature xyz Coordinates in Derived Part with VBA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.