Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating Composite iMates

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Q_Visser
128 Views, 2 Replies

Creating Composite iMates

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!

2 REPLIES 2
Message 2 of 3
A.Acheson
in reply to: Q_Visser

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")

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 3
Q_Visser
in reply to: 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.

Post to forums  

Technology Administrators


Autodesk Design & Make Report