Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

matrix woes

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Inventor.Fanatic
490 Views, 2 Replies

matrix woes

Hi guys,

 

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.

 

Dominik

 

MatrixWoes_Screenshot.jpg

2 REPLIES 2
Message 2 of 3
ekinsb
in reply to: Inventor.Fanatic

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
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 3
Inventor.Fanatic
in reply to: ekinsb

That's exactly what I wanted.  Thanks a bunch Brian !

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report