Constrain, mate or flush? How to choose?

Constrain, mate or flush? How to choose?

Hubert_Los
Advocate Advocate
593 Views
1 Reply
Message 1 of 2

Constrain, mate or flush? How to choose?

Hubert_Los
Advocate
Advocate

Hello,

I would like to constrain the part to the origin plane at this actual position. I check the angle between the planes and if it is 0, I create a constraint. And at this point I have a problem, because I don't know what type of constraint I should choose. Sometimes the part rotates 180 degrees. Do you know how I can choose the constraints correctly?

Sub Constrain()

    Dim oADoc As AssemblyDocument
    Set oADoc = ThisApplication.ActiveDocument
    Dim oADef As AssemblyComponentDefinition
    Set oADef = oADoc.ComponentDefinition
    
    Dim oAsmYZPlane As WorkPlane
    Set oAsmYZPlane = oADef.WorkPlanes.Item(1)
    
    Dim oCompYZPlane1 As Object
    Dim oCompYZPlane2 As Object
    
    If oADoc.SelectSet.Count = 1 Then
        Set oOcc1 = ThisApplication.ActiveDocument.SelectSet.Item(1)
    Else
        Set oOcc1 = ThisApplication.CommandManager.Pick(kAssemblyLeafOccurrenceFilter, "1")
    End If
    
    Dim oCompPtDef1 As PartComponentDefinition
    Set oCompPtDef1 = oOcc1.Definition
    Call oOcc1.CreateGeometryProxy(oCompPtDef1.WorkPlanes.Item(1), oCompYZPlane1)
    
    Angle = ThisApplication.MeasureTools.GetAngle(oCompYZPlane1, oAsmYZPlane)
    If Angle = 0 Then
        Call oADef.Constraints.AddFlushConstraint(oCompYZPlane1, oAsmYZPlane, 0)
    End If

End Sub
0 Likes
Accepted solutions (1)
594 Views
1 Reply
Reply (1)
Message 2 of 2

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @Hubert_Los . You can check the direction of the plane normal if they are in the same direction to create the desired constraint. I added the following check on line 26:

Sub Constrain()

    Dim oADoc As AssemblyDocument
    Set oADoc = ThisApplication.ActiveDocument
    Dim oADef As AssemblyComponentDefinition
    Set oADef = oADoc.ComponentDefinition
    
    Dim oAsmYZPlane As WorkPlane
    Set oAsmYZPlane = oADef.WorkPlanes.Item(1)
    
    Dim oCompYZPlane1 As Object
    Dim oCompYZPlane2 As Object
    
    If oADoc.SelectSet.Count = 1 Then
        Set oOcc1 = ThisApplication.ActiveDocument.SelectSet.Item(1)
    Else
        Set oOcc1 = ThisApplication.CommandManager.Pick(kAssemblyLeafOccurrenceFilter, "1")
    End If
    
    Dim oCompPtDef1 As PartComponentDefinition
    Set oCompPtDef1 = oOcc1.Definition
    Call oOcc1.CreateGeometryProxy(oCompPtDef1.WorkPlanes.Item(1), oCompYZPlane1)
    
    Angle = ThisApplication.MeasureTools.GetAngle(oCompYZPlane1, oAsmYZPlane)
    If Angle = 0 Then
		If oAsmYZPlane.Plane.Normal.IsEqualTo(oCompYZPlane1.Plane.Normal, 0.001) Then
        	Call oADef.Constraints.AddFlushConstraint(oCompYZPlane1, oAsmYZPlane, 0)
		End If
    End If

End Sub

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes