I have an assembly that contains a part and a hole feature (the hole feature is at the assembly level). Using the api, I'm trying to get the hole location relative to the part's coordinate system in a without using the holeplacementdefinition.distance property, this way I can get the hole location regardless of the way it was defined. Any help would be greatly appreciated.
Below is some code that I believe will do what you want. I've tried to comment it to explain what's going on.
Public Sub AssemblyHoleFeatureInPartSpace() Dim asmDoc As AssemblyDocument Set asmDoc = ThisApplication.ActiveDocument
Dim hole As HoleFeature Set hole = ThisApplication.CommandManager.Pick( _ kAssemblyFeatureFilter, _ "Select a hole feature.")
' A single hole feature can define multiple actual holes ' in a part and the position of the holes can be defined ' in different ways, i.e. at sketch points, distance from ' an edges, concentric to a circle, etc. The ' HoleCenterPoints property returns the coordinate point ' for each physical hole created by the hole feature. The ' code below uses that to determine the hole position and ' then gets a cylinder from the hole to determine the ' direction. Dim holeCenter As Object For Each holeCenter In hole.HoleCenterPoints ' Center points can be returned as a sketch point when
' the hole was created using a sketch point, or a ' coordinate for other placement types. Dim holePosition As Point If TypeOf holeCenter Is SketchPoint Then Dim holeSketchPoint As SketchPoint Set holeSketchPoint = holeCenter Set holePosition = holeSketchPoint.Geometry3d Else Set holePosition = holeCenter End If
' Iterate through the occurrences the hole affects. Dim occ As ComponentOccurrence For Each occ In hole.Participants ' Get the transform from the occurrence. Dim occMatrix As Matrix Set occMatrix = occ.Transformation
' Invert the matrix to get an assembly to ' occurrence transform. occMatrix.Invert
' Transform the hole point into occurrence space. Dim newPoint As Point Set newPoint = holePosition.Copy Call newPoint.TransformBy(occMatrix)
' Display the coordinates. Debug.Print "Position in assembly space" Debug.Print (" " & hole.name & " position in " _ & occ.name & " is " & _ Format(holePosition.X, "0.000000") _ & "," & _ Format(holePosition.Y, "0.000000") _ & "," & _ Format(holePosition.Z, "0.000000"))
Debug.Print "Position in part space" Debug.Print (" " & hole.name & " position in " & _ occ.name & " is " & _ Format(newPoint.X, "0.000000") _ & "," & _ Format(newPoint.Y, "0.000000") _ & "," & _ Format(newPoint.Z, "0.000000")) Next Next End Sub
Brian Ekins Developer Technical Services Autodesk Developer Network Autodesk, Inc.