Inventor Customization

New Member
Posts: 2
Registered: ‎03-26-2012
Message 1 of 3 (193 Views)
Accepted Solution

matrix woes

193 Views, 2 Replies
04-27-2012 01:46 PM

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.





ADN Support Specialist
Posts: 288
Registered: ‎07-21-2006
Message 2 of 3 (143 Views)

Re: matrix woes

05-10-2012 03:45 PM 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
         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.


         ' 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 ("   " & & " position in " _
                      & &
" is " & _
                      Format(holePosition.X, "0.000000") _
                      & "," & _
Format(holePosition.Y, "0.000000") _
                      & "," & _
Format(holePosition.Z, "0.000000"))

         Debug.Print "Position in part space"
         Debug.Print ("   " & & " position in " & _
" is " & _
                      Format(newPoint.X, "0.000000") _
                      & "," & _

                      Format(newPoint.Y, "0.000000") _
                      & "," & _

                      Format(newPoint.Z, "0.000000"))
End Sub

Brian Ekins
Developer Technical Services
Autodesk Developer Network
Autodesk, Inc.
New Member
Posts: 2
Registered: ‎03-26-2012
Message 3 of 3 (134 Views)

Re: matrix woes

05-11-2012 02:13 PM in reply to: ekinsb

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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community

Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor