Hole Axis

Hole Axis

Anonymous
Not applicable
423 Views
3 Replies
Message 1 of 4

Hole Axis

Anonymous
Not applicable

I am writing some VBA and I am having a little trouble.  I have an Assembly and I am trying to align a pin into a hole. I am having trouble figuring out the axis of the hole to mate with Z axis of the pin.  Can anyone help me here and point me in the right direction?

Dim p1CompOcc As ComponentOccurrence
Dim p2CompOcc As ComponentOccurrence
Dim oHole As face
Set oHole = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceCylindricalFilter, "Pick Hole")
set p2CompOcc = oHole.ContainingOccurrence
Call ThisApplication.ActiveDocument.ComponentDefinition.Constraints.AddMateConstraint(p1CompOcc.Definition.WorkAxes.Item(3), oHole.Geometry.AxisVector, 0)

 

0 Likes
424 Views
3 Replies
Replies (3)
Message 2 of 4

dutt.thakar
Collaborator
Collaborator

@Anonymous 

 

Can you try the below code? First you need to select the Hole face, and second Pin face. It will automatically pick the vectors and create a mate.

 

Dim oDef As AssemblyComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition
Dim oSS As SelectSet = ThisApplication.ActiveDocument.SelectSet
Dim p1CompOcc As ComponentOccurrence
Dim p2CompOcc As ComponentOccurrence

Dim oHole1 As Face
oHole1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceCylindricalFilter, "Pick Hole Face")
p1CompOcc = oHole1.ContainingOccurrence

Dim oFP1 As FaceProxy
p1CompOcc.CreateGeometryProxy(oHole1,oFP1)

Dim oHole2 As Face
oHole2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceCylindricalFilter, "Pick Cylindrical Pin Face")
p2CompOcc = oHole2.ContainingOccurrence

Dim oFP2 As FaceProxy
p2CompOcc.CreateGeometryProxy(oHole2,oFP2)

oDef.Constraints.AddMateConstraint(oFP1,oFP2,"0",InferredTypeEnum.kInferredLine,InferredTypeEnum.kInferredLine)

  

Let me know if this is helpful or not.

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 3 of 4

_dscholtes_
Advocate
Advocate

@dutt.thakar You forgot to mention the most important thing in your code: create proxies when you work with assemblies!

@Anonymous You can read about proxies in How Deep is the Rabbit Hole? Examining the Matrix and Other Inventor Math and Geometry Objects (page 12 to 14, including code example) which can be found here: https://modthemachine.typepad.com/my_weblog/2008/12/after-autodesk-university.html . I used to have an easier to read help example, but can't seem to find it.

0 Likes
Message 4 of 4

dutt.thakar
Collaborator
Collaborator

@_dscholtes_ 

Yes, you are correct, I have created them in the code but forgot to mention them in the description. Thanks for the reply.

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes