Hi Folks,
I'm attempting to create a bunch of composite iMates in an assembly, but I keep running into errors as I try to create them. I can create standard iMates no problem, but then using the created iMates to create a composite iMate is proving problematic.
To try trouble shoot, I manually created 3 iMates (test1, test2, test3) and then tried to use these to create the composite to no avail.
My test code is below:
Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim o_iMateDefinitions As iMateDefinitions = oCompDef.iMateDefinitions
Dim o_iMateDefinition1 As iMateDefinition
Dim o_iMateDefinition2 As iMateDefinition
Dim o_iMateDefinition3 As iMateDefinition
Dim iMateCollection As ObjectCollection
For index = 1 To o_iMateDefinitions.Count
If o_iMateDefinitions.Item(index).Name = "test1" Then
o_iMateDefinition1 = o_iMateDefinitions.Item(index)
ElseIf o_iMateDefinitions.Item(index).Name = "test2" Then
o_iMateDefinition1 = o_iMateDefinitions.Item(index)
ElseIf o_iMateDefinitions.Item(index).Name = "test3" Then
o_iMateDefinition1 = o_iMateDefinitions.Item(index)
End If
Next
iMateCollection.Add(o_iMateDefinition1)
iMateCollection.Add(o_iMateDefinition2)
iMateCollection.Add(o_iMateDefinition3)
Dim oCompImate As CompositeiMateDefinition = o_iMateDefinitions.AddCompositeiMateDefinition(iMateCollection, "CompositeTest")
Any help would be greatly appreciated!
Solved! Go to Solution.
Hi Folks,
I'm attempting to create a bunch of composite iMates in an assembly, but I keep running into errors as I try to create them. I can create standard iMates no problem, but then using the created iMates to create a composite iMate is proving problematic.
To try trouble shoot, I manually created 3 iMates (test1, test2, test3) and then tried to use these to create the composite to no avail.
My test code is below:
Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim o_iMateDefinitions As iMateDefinitions = oCompDef.iMateDefinitions
Dim o_iMateDefinition1 As iMateDefinition
Dim o_iMateDefinition2 As iMateDefinition
Dim o_iMateDefinition3 As iMateDefinition
Dim iMateCollection As ObjectCollection
For index = 1 To o_iMateDefinitions.Count
If o_iMateDefinitions.Item(index).Name = "test1" Then
o_iMateDefinition1 = o_iMateDefinitions.Item(index)
ElseIf o_iMateDefinitions.Item(index).Name = "test2" Then
o_iMateDefinition1 = o_iMateDefinitions.Item(index)
ElseIf o_iMateDefinitions.Item(index).Name = "test3" Then
o_iMateDefinition1 = o_iMateDefinitions.Item(index)
End If
Next
iMateCollection.Add(o_iMateDefinition1)
iMateCollection.Add(o_iMateDefinition2)
iMateCollection.Add(o_iMateDefinition3)
Dim oCompImate As CompositeiMateDefinition = o_iMateDefinitions.AddCompositeiMateDefinition(iMateCollection, "CompositeTest")
Any help would be greatly appreciated!
Solved! Go to Solution.
Solved by A.Acheson. Go to Solution.
Hi @Q_Visser
You were missing two things. To create and set the Object collection
Dim iMateCollection As ObjectCollection iMateCollection = ThisApplication.TransientObjects.CreateObjectCollection
and also this variable was used in each if statement instead of as they are declared.as individual.
o_iMateDefinition1
Here is another way to write this a little shorter
Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim o_iMatesDefs As iMateDefinitions = oCompDef.iMateDefinitions
Dim iMateCollection As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim imateList As String() = {"test1","test2","test3"}
For Each o_imateDef As iMateDefinition In o_iMatesDefs
If imateList.Contains(o_imateDef.Name)
iMateCollection.Add(o_imateDef)
End If
Next
Dim oCompImate As CompositeiMateDefinition = o_iMatesDefs.AddCompositeiMateDefinition(iMateCollection, "CompositeTest")
and another way if you like or statements.
Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim o_iMatesDefs As iMateDefinitions = oCompDef.iMateDefinitions
Dim iMateCollection As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each o_imateDef As iMateDefinition In o_iMatesDefs
If o_imateDef.Name = "test1" _
Or o_imateDef.Name = "test2" _
Or o_imateDef.Name = "test3" Then
iMateCollection.Add(o_imateDef)
End If
Next
Dim oCompImate As CompositeiMateDefinition = o_iMatesDefs.AddCompositeiMateDefinition(iMateCollection, "CompositeTest")
Hi @Q_Visser
You were missing two things. To create and set the Object collection
Dim iMateCollection As ObjectCollection iMateCollection = ThisApplication.TransientObjects.CreateObjectCollection
and also this variable was used in each if statement instead of as they are declared.as individual.
o_iMateDefinition1
Here is another way to write this a little shorter
Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim o_iMatesDefs As iMateDefinitions = oCompDef.iMateDefinitions
Dim iMateCollection As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim imateList As String() = {"test1","test2","test3"}
For Each o_imateDef As iMateDefinition In o_iMatesDefs
If imateList.Contains(o_imateDef.Name)
iMateCollection.Add(o_imateDef)
End If
Next
Dim oCompImate As CompositeiMateDefinition = o_iMatesDefs.AddCompositeiMateDefinition(iMateCollection, "CompositeTest")
and another way if you like or statements.
Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim o_iMatesDefs As iMateDefinitions = oCompDef.iMateDefinitions
Dim iMateCollection As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each o_imateDef As iMateDefinition In o_iMatesDefs
If o_imateDef.Name = "test1" _
Or o_imateDef.Name = "test2" _
Or o_imateDef.Name = "test3" Then
iMateCollection.Add(o_imateDef)
End If
Next
Dim oCompImate As CompositeiMateDefinition = o_iMatesDefs.AddCompositeiMateDefinition(iMateCollection, "CompositeTest")
Ahh, the setting of the object collection was absolutely my issue.
The duplicate "o_iMateDefinition1" was absolutely a typo in my test code, I didn't have that in my original code but that definitely didn't help with the test.
The short code with the array is a great way to add the required iMates to the collection - big fan of efficient code here.
Thank you so much @A.Acheson
Ahh, the setting of the object collection was absolutely my issue.
The duplicate "o_iMateDefinition1" was absolutely a typo in my test code, I didn't have that in my original code but that definitely didn't help with the test.
The short code with the array is a great way to add the required iMates to the collection - big fan of efficient code here.
Thank you so much @A.Acheson
Can't find what you're looking for? Ask the community or share your knowledge.