iMate limits and ilogic

iMate limits and ilogic

jzcrouse
Enthusiast Enthusiast
523 Views
0 Replies
Message 1 of 1

iMate limits and ilogic

jzcrouse
Enthusiast
Enthusiast

I have a part with iMates. I insert 2 of the parts into an assembly using ilogic and create various mates with the iMates within the macro. My issue lies with limits placed in some of the iMates. They work if you connect them manually, however with the program the mate gets created but the limit does not work properly. After the program runs I have to open the two mates with the limits for the limits to register. After i open them once everything works fine. How can i avoid the error in the limit imates? 

SyntaxEditor Code Snippet

Public Sub Main()
    ' Get the component definition of the currently open assembly.
    ' This will fail if an assembly document is not open.
    Dim oAsmCompDef As AssemblyComponentDefinition
     oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
   
    ' Create a new matrix object.  It will be initialized to an identity matrix.
    Dim oMatrix As Matrix
     oMatrix = ThisApplication.TransientGeometry.CreateMatrix   

    ' Place the first occurrence.
    Dim oOcc1 As ComponentOccurrence
     oOcc1 = oAsmCompDef.Occurrences.Add("C:\Vault Workspace\Designs\_Part Library\MSC - Miscellaneous\MSC.000001022.ipt", oMatrix)   

    ' Place the second occurrence, but adjust the matrix slightly so they're
    ' not right on top of each other.
    oMatrix.Cell(1, 4) = 10
    Dim oOcc2 As ComponentOccurrence
     oOcc2 = oAsmCompDef.Occurrences.Add("C:\Vault Workspace\Designs\_Part Library\MSC - Miscellaneous\MSC.000001022.ipt", oMatrix)
    
    ' Look through the iMateDefinitions defined for the first occurrence
    ' and find the one named "iMate:1".  This loop demonstrates using the
    ' Count and Item properties of the iMateDefinitions object.
	
'Axis constraint
    Dim i As Long
    Dim oiMateDef1 As iMateDefinition
    For i = 1 To oOcc1.iMateDefinitions.Count
        If oOcc1.iMateDefinitions.Item(i).Name = "iMate:1" Then
             oiMateDef1 = oOcc1.iMateDefinitions.Item(i)
            Exit For
        End If
    Next  

    If oiMateDef1 Is Nothing Then
        MsgBox ("An iMate definition named ""iMate:1"" does not exist in " & oOcc1.Name)
        Exit Sub
    End If
    
    ' Look through the iMateDefinitions defined for the second occurrence
    ' and find the one named "iMate:2".  This loop demonstrates using the
    ' For Each method of iterating through a collection.
    Dim oiMateDef2 As iMateDefinition
    Dim bFoundDefinition As Boolean
    For Each oiMateDef2 In oOcc2.iMateDefinitions
        If oiMateDef2.Name = "iMate:2" Then
            bFoundDefinition = True
            Exit For
        End If
    Next

    If Not bFoundDefinition Then
        MsgBox ("An iMate definition named ""iMate:2"" does not exist in " & oOcc2.Name)
        Exit Sub
    End If
	 Dim oiMateResult As iMateResult
     oiMateResult = oAsmCompDef.iMateResults.AddByTwoiMates(oiMateDef1, oiMateDef2)
'Movement constraint
    Dim oiMateDef3 As iMateDefinition

    For Each oiMateDef3 In oOcc2.iMateDefinitions
        If oiMateDef3.Name = "iMate:3" Then
            bFoundDefinition = True
            Exit For
        End If
    Next

    If Not bFoundDefinition Then
        MsgBox ("An iMate definition named ""iMate:3"" does not exist in " & oOcc2.Name)
        Exit Sub
    End If
    
    ' Look through the iMateDefinitions defined for the second occurrence
    ' and find the one named "iMate:1".  This loop demonstrates using the
    ' For Each method of iterating through a collection.
    Dim oiMateDef4 As iMateDefinition

    For Each oiMateDef4 In oOcc1.iMateDefinitions
        If oiMateDef4.Name = "iMate:4" Then
            bFoundDefinition = True
            Exit For
        End If
    Next

    If Not bFoundDefinition Then
        MsgBox ("An iMate definition named ""iMate:4"" does not exist in " & oOcc1.Name)
        Exit Sub
    End If
    ' Create an iMate result using the two definitions.
    Dim oiMateResult2 As iMateResult
     oiMateResult2 = oAsmCompDef.iMateResults.AddByTwoiMates(oiMateDef3, oiMateDef4)
	 
'Direction of movement constraint	 
Dim oiMateDef5 As iMateDefinition

    For Each oiMateDef5 In oOcc1.iMateDefinitions
        If oiMateDef5.Name = "iMate:5" Then
            bFoundDefinition = True
            Exit For
        End If
    Next

    If Not bFoundDefinition Then
        MsgBox ("An iMate definition named ""iMate:5"" does not exist in " & oOcc1.Name)
        Exit Sub
    End If
    
    ' Look through the iMateDefinitions defined for the second occurrence
    ' and find the one named "iMate:1".  This loop demonstrates using the
    ' For Each method of iterating through a collection.
    Dim oiMateDef6 As iMateDefinition

    For Each oiMateDef6 In oOcc2.iMateDefinitions
        If oiMateDef6.Name = "iMate:6" Then
            bFoundDefinition = True
            Exit For
        End If
    Next

    If Not bFoundDefinition Then
        MsgBox ("An iMate definition named ""iMate:7"" does not exist in " & oOcc2.Name)
        Exit Sub
    End If
    ' Create an iMate result using the two definitions.
    Dim oiMateResult3 As iMateResult
     oiMateResult3 = oAsmCompDef.iMateResults.AddByTwoiMates(oiMateDef5, oiMateDef6)	
	 
'Center plane constraint
Dim oiMateDef7 As iMateDefinition

    For Each oiMateDef7 In oOcc1.iMateDefinitions
        If oiMateDef7.Name = "iFlush:1" Then
            bFoundDefinition = True
            Exit For
        End If
    Next

    If Not bFoundDefinition Then
        MsgBox ("An iMate definition named ""iFlush:1"" does not exist in " & oOcc1.Name)
        Exit Sub
    End If
    
    ' Look through the iMateDefinitions defined for the second occurrence
    ' and find the one named "iMate:1".  This loop demonstrates using the
    ' For Each method of iterating through a collection.
    Dim oiMateDef8 As iMateDefinition

    For Each oiMateDef8 In oOcc2.iMateDefinitions
        If oiMateDef8.Name = "iFlush:1" Then
            bFoundDefinition = True
            Exit For
        End If
    Next

    If Not bFoundDefinition Then
        MsgBox ("An iMate definition named ""iFlush:1"" does not exist in " & oOcc2.Name)
        Exit Sub
    End If
    ' Create an iMate result using the two definitions.
    Dim oiMateResult4 As iMateResult
     oiMateResult4 = oAsmCompDef.iMateResults.AddByTwoiMates(oiMateDef7, oiMateDef8)

End Sub 

 

 

0 Likes
524 Views
0 Replies
Replies (0)