Need Help about AddMateConstrain

Need Help about AddMateConstrain

Octave.Lab
Advocate Advocate
502 Views
7 Replies
Message 1 of 8

Need Help about AddMateConstrain

Octave.Lab
Advocate
Advocate

Hi,

 

I need your help about how to add mate constrain by using API.

 

OctaveLab_0-1671584241365.png

I'd like to connect a conduit (left) and UNV (right)

My Code is below,

Sub AddMateTest01()
    ' Add Mate constrain sammple
    ' Cylindrical Face of Conduit and  Work Axis od Clamp
  
    Dim oDoc As Inventor.AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument

    
    'select couduit
    Dim oConduitFace As Inventor.FaceProxy
    Set oConduitFace = ThisApplication.CommandManager.Pick(kPartFaceCylindricalFilter, "select couduit")

    Dim oUNV_Comp As Inventor.ComponentOccurrence
    Set oUNV_Comp = ThisApplication.CommandManager.Pick(kAssemblyOccurrenceFilter, "select UNIV")
    
    'select UNV
    Dim oWx As Inventor.WorkAxis
    Set oWx = oUNV_Comp.Definition.WorkAxes.Item("Wx_Unv")
    
    'Create Proxy
    Dim oWxProxy As Inventor.WorkAxisProxy
    Call oUNV_Comp.CreateGeometryProxy(oWx, oWxProxy)


    'Add Mate
    Dim oMate As Inventor.MateConstraint
    Set oMate = oDoc.ComponentDefinition.Constraints.AddMateConstraint(oConduitFace, oWxProxy, 0)



End Sub


Sub AddMateTest02()

    ' Add Mate constrain sammple
    ' Cylindrical Face of Conduit and  Work Axis od Clamp
    
    Dim oDoc As Inventor.AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument

    
    'select couduit
    Dim oConduitFace As Inventor.FaceProxy
    Set oConduitFace = ThisApplication.CommandManager.Pick(kPartFaceCylindricalFilter, "select couduit")

    Dim oUNV_Comp As Inventor.ComponentOccurrence
    Set oUNV_Comp = ThisApplication.CommandManager.Pick(kAssemblyOccurrenceFilter, "select UNIV")
    
    'Get Wx of Conduit
    Dim oWxConduit As Inventor.WorkAxis
    Set oWxConduit = oConduitFace.ContainingOccurrence.Definition.WorkAxes.Item(3)
    
    Dim oWxConduitProxy As Inventor.WorkAxisProxy
    oConduitFace.ContainingOccurrence.CreateGeometryProxy oWxConduit, oWxConduitProxy
    
    
    'select UNV
    Dim oWx As Inventor.WorkAxis
    Set oWx = oUNV_Comp.Definition.WorkAxes.Item("Wx_Unv")
    
    'Create Proxy
    Dim oWxProxy As Inventor.WorkAxisProxy
    oUNV_Comp.CreateGeometryProxy oWx, oWxProxy


    'Add Mate
    Dim oMate As Inventor.MateConstraint
    Set oMate = oDoc.ComponentDefinition.Constraints.AddMateConstraint(oWxConduitProxy, oWxProxy, 0)



End Sub

 

1st program AddMateTest01 will stop by Error at line 27.

2nd progra will OK.

 

The difference is whether using   Face proxy  or work axis proxy for constraint.

But I want use Face proxy for mate constrain.

Can you tell me how I can add constrain  correctly?

 

I attached the Sample project and movie.

 

Regards,

 

 

-YO
Octave.Lab
https://note.com/yo420186 
0 Likes
Accepted solutions (1)
503 Views
7 Replies
Replies (7)
Message 2 of 8

A.Acheson
Mentor
Mentor

This seems to work for me. 

Sub AddMateTest01()

    Dim oDoc As Inventor.AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument

    'select couduit
    Dim oConduitFace As Inventor.FaceProxy
    Set oConduitFace = ThisApplication.CommandManager.Pick(kPartFaceCylindricalFilter, "select couduit")
    
    'select oUNV
    Dim oUNV_Face As Inventor.FaceProxy
    Set oUNV_Face = ThisApplication.CommandManager.Pick(kPartFaceCylindricalFilter, "select UNIV")
    
    'Add Mate
    Dim oMate As Inventor.MateConstraint
    Set oMate = oDoc.ComponentDefinition.Constraints.AddMateConstraint2(oUNV_Face, oConduitFace, 0, InferredTypeEnum.kInferredLine, InferredTypeEnum.kInferredLine, MateConstraintSolutionTypeEnum.kOpposedSolutionType)

End Sub

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 8

Octave.Lab
Advocate
Advocate

@A.Acheson -san

Thank you for your help.

But, I want to add mate with the work axis within the selected occurrence.

Is Face proxy and Work Axis proxy bad match?

Regards,

-YO
Octave.Lab
https://note.com/yo420186 
0 Likes
Message 4 of 8

A.Acheson
Mentor
Mentor

Ok i see. Once you have the occurrence go to definition then axes. To clarify you want to mate axis to axis? 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 8

Octave.Lab
Advocate
Advocate

@A.Acheson 

> To clarify you want to mate axis to axis? 

I want to mate Face to Axis.

 

Regards,

 

 

 

-YO
Octave.Lab
https://note.com/yo420186 
0 Likes
Message 6 of 8

A.Acheson
Mentor
Mentor
Accepted solution

This works

 

Sub AddMateTest02()

    ' Add Mate constrain sammple
    ' Cylindrical Face of Conduit and  Work Axis od Clamp
    
    Dim oDoc As Inventor.AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument

    
    'select couduit
    Dim oConduitFaceProxy As Inventor.FaceProxy
    Set oConduitFaceProxy = ThisApplication.CommandManager.Pick(kPartFaceCylindricalFilter, "select couduit")

    Dim oUNV_Comp As Inventor.ComponentOccurrence
    Set oUNV_Comp = ThisApplication.CommandManager.Pick(kAssemblyOccurrenceFilter, "select UNIV")
    
 
   'select UNV Axis
    Dim oWx As Inventor.WorkAxis
    Set oWx = oUNV_Comp.Definition.WorkAxes.Item("Wx_Unv")
    
    'Create Proxy as axis is in an assembly
    Dim oWxProxy As Inventor.WorkAxisProxy
    oUNV_Comp.CreateGeometryProxy oWx, oWxProxy


    'Add Mate
    Dim oMate As Inventor.MateConstraint
    Set oMate = oDoc.ComponentDefinition.Constraints.AddMateConstraint2(oWxProxy, oConduitFaceProxy, 0, InferredTypeEnum.kInferredLine, InferredTypeEnum.kInferredLine, MateConstraintSolutionTypeEnum.kOpposedSolutionType)


End Sub

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 7 of 8

Octave.Lab
Advocate
Advocate
It Works!
I understand that i should use AddMateConstraint2 method instead.
Thank you so much for your help.
-YO
Octave.Lab
https://note.com/yo420186 
0 Likes
Message 8 of 8

A.Acheson
Mentor
Mentor

I think this will work with either Mateconstraint or Mateconstraint2. I must have left that in there accidently while testing. Try it without. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes