How to use vba to create a mateconstraint for two cylindrical faces?

How to use vba to create a mateconstraint for two cylindrical faces?

lzs013
Advocate Advocate
713 Views
1 Reply
Message 1 of 2

How to use vba to create a mateconstraint for two cylindrical faces?

lzs013
Advocate
Advocate

I need a macro. When I run this macro, I need to pick two cylindrical faces, after which the macro automatically creates a coaxial mate for the two part. Who can help me?

0 Likes
Accepted solutions (1)
714 Views
1 Reply
Reply (1)
Message 2 of 2

YuhanZhang
Autodesk
Autodesk
Accepted solution

Here is the VBA sample:

 

Sub CylinderFacesMateSample()
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oFace1 As Face
    Set oFace1 = ThisApplication.CommandManager.Pick(kPartFaceCylindricalFilter, "Select a cylindrical face")
    
    Dim oFace2 As Face
    Set oFace2 = ThisApplication.CommandManager.Pick(kPartFaceCylindricalFilter, "Select another cylindrical face")
     
    Dim omate As MateConstraint
    Set omate = oDoc.ComponentDefinition.Constraints.AddMateConstraint(oFace1, oFace2, 0, kInferredLine, kInferredLine)
End Sub

 

 

Hope it helps.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes