iLogic add components at offset

iLogic add components at offset

Anonymous
Not applicable
639 Views
2 Replies
Message 1 of 3

iLogic add components at offset

Anonymous
Not applicable

Hello everyone,

 

First time poster and iLogic beginner so please be gentle 🙂 

 

I am looking at adding the same part in an empty assembly via a form. The idea being that you input the number of parts you want and then click add they will be put nicely one on top of the other with an offset on the z axis. The offset will be hard coded and not part of the form.

 

I have managed to reach a point on which I can insert the number of parts I want but they are all on top of each other so I need help making them offset one to each other.

 

It seems that my z variable gets updated but it seems iLogic does not like it in the CreateVector function. 

 

Code below:

 

Dim Counter As Integer = 0

While Counter < NumbersOfItemsToAdd
	
	Counter = Counter + 1 
	
	oPath = ThisDoc.Path & "\"
	oFile = "Generic Part.ipt"
	
	Dim oAsmCompDef As AssemblyComponentDefinition
	oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
	
	Dim oTG As TransientGeometry
	oTG = ThisApplication.TransientGeometry
	
	Dim oMatrix As Matrix
	oMatrix = oTG.CreateMatrix

	Dim oOccurrence As ComponentOccurrence
	oOccurence = oAsmCompDef.Occurrences.Add(oPath & oFile, oMatrix)
	
	Dim Offset As Double
	Offset = 10

	Dim z As Double
	z = Offset*Counter
	
	oMatrix.SetTranslation(oTG.CreateVector(0,0,z))
	oOccurence.Grounded = False

	MessageBox.Show("Counter is " & Counter & vbCr & "Z is " & z, "Parameters")
		
End While

 

Accepted solutions (1)
640 Views
2 Replies
Replies (2)
Message 2 of 3

ckeveryga
Advocate
Advocate
Accepted solution

Your code is perfect! You just need to move the line where you place the component, to below where you set the vector. 

Dim Counter As Integer = 0

While Counter < NumbersOfItemsToAdd
	
	Counter = Counter + 1 
	
	oPath = ThisDoc.Path & "\"
	oFile = "Generic Part.ipt"
	
	Dim oAsmCompDef As AssemblyComponentDefinition
	oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
	
	Dim oTG As TransientGeometry
	oTG = ThisApplication.TransientGeometry
	
	Dim oMatrix As Matrix
	oMatrix = oTG.CreateMatrix

	Dim oOccurrence As ComponentOccurrence
	
	Dim Offset As Double
	Offset = 10

	Dim z As Double
	z = Offset*Counter
	
	oMatrix.SetTranslation(oTG.CreateVector(0, 0, z))
	oOccurence = oAsmCompDef.Occurrences.Add(oPath & oFile, oMatrix)
	oOccurence.Grounded = False	
	
	MessageBox.Show("Counter is " & Counter & vbCr & "Z is " & z, "Parameters")
		
End While
Message 3 of 3

Anonymous
Not applicable

Thank you very much ! Well that was easy 🙂 

0 Likes