PLACE, POSITION, MOVE, TURN, COPY IN PATTERN, components in an assembly

PLACE, POSITION, MOVE, TURN, COPY IN PATTERN, components in an assembly

ThomasB44
Mentor Mentor
1,294 Views
6 Replies
Message 1 of 7

PLACE, POSITION, MOVE, TURN, COPY IN PATTERN, components in an assembly

ThomasB44
Mentor
Mentor

Hi folks, I create this post to share the code I've found here.

Thanks to the authors !

And special thanks to @MechMachineMan ! Most of this codes come from him.

 

I use this codes to quickly create an assembly of some special configurations of a scaffolding.

With these codes, I use an iLogic form, so you will need to create some user parameters, or modify some code.

I've put some code in bold to reflect this.

 

To place a component :

 

 

'''PLACE components
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oMatrix As Matrix = oTG.CreateMatrix
Dim oOccurrence As ComponentOccurrence

'Create matrix
oMatrix.SetTranslation(oTG.CreateVector( _
Parameter("X_Pos")/10, _
Parameter("Y_Pos")/10, _
Parameter("Z_Pos")/10))
'PLACE component
oOccurrence = oAsmCompDef.Occurrences.Add(Parameter("Path and file name"), oMatrix)
oOccurrence.Grounded = True

'Reset parameters
Parameter("X_Pos") = 0
Parameter("Y_Pos") = 0
Parameter("Z_Pos") = 0
'''End of rule

 

 

To position some components :

Relocate selected components to coordinates from the assembly origin.

 

 

'''RELOCATE components
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
'check for selection
Dim oSelSet As SelectSet
oSelSet = oDoc.SelectSet
If oSelSet.Count = 0 Then
  Return
End If

'Save current selection
Dim oItems As ObjectsEnumerator
oItems = ThisApplication.TransientObjects.CreateObjectCollection
Dim Item As Object
For Each Item In oSelSet
	oItems.Add(Item)
Next

'RELOCATE each occurrence
Dim CompOcc As ComponentOccurrence
Dim oConstraint As AssemblyConstraint
Dim oMatrix As Matrix
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
For Each CompOcc In oSelSet
	'Create matrix
	oMatrix = CompOcc.Transformation
	oMatrix.SetTranslation(oTG.CreateVector( _
	Parameter("X_Pos")/10, _
	Parameter("Y_Pos")/10, _
	Parameter("Z_Pos")/10))
	'RELOCATE ignoring any constraints
	CompOcc.SetTransformWithoutConstraints(oMatrix)
	'RELOCATE according to constraints
	'CompOcc.Transformation = oMatrix
	CompOcc.Grounded = True
Next

'Reset parameters
Parameter("X_Pos") = 0
Parameter("Y_Pos") = 0
Parameter("Z_Pos") = 0
'Update components constraints
oDoc.Rebuild
'Call saved Selection
oDoc.SelectSet.SelectMultiple(oItems)
'''End of rule

 

 

To move some components :

Move selected components from their current places to input distances.

 

 

'''MOVE components
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
'check for selection
Dim oSelSet As SelectSet
oSelSet = oDoc.SelectSet
If oSelSet.Count = 0 Then
  Return
End If

'Save current selection
Dim oItems As ObjectsEnumerator
oItems = ThisApplication.TransientObjects.CreateObjectCollection
Dim Item As Object
For Each Item In oSelSet
	oItems.Add(Item)
Next

'MOVE each occurrence
Dim CompOcc As ComponentOccurrence
Dim oMatrix As Matrix
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
Dim Coords(2) As Double
For Each CompOcc In oSelSet
	'Create matrix
	oMatrix = CompOcc.Transformation
	oMatrix.Translation.GetVectorData(Coords)'in cm
	oMatrix.SetTranslation(oTG.CreateVector( _
	Coords(0)+Parameter("X_Pos")/10, _
	Coords(1)+Parameter("Y_Pos")/10, _
	Coords(2)+Parameter("Z_Pos")/10))'in cm
	'MOVE ignoring any constraints
	CompOcc.SetTransformWithoutConstraints(oMatrix)
	'MOVE according to constraints
	'CompOcc.Transformation = oMatrix
	CompOcc.Grounded = True
Next

'Reset parameters
Parameter("X_Pos") = 0
Parameter("Y_Pos") = 0
Parameter("Z_Pos") = 0
'Update components constraints
oDoc.Rebuild
'Call saved Selection
oDoc.SelectSet.SelectMultiple(oItems)
'''End of rule

 

 

To turn some components :

 

 

'''ROTATE components
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
'check for selection
Dim oSelSet As SelectSet 
oSelSet = oDoc.SelectSet 
If oSelSet.Count = 0 Then
	Return
End If

'Save current selection
Dim oItems As ObjectsEnumerator
oItems = ThisApplication.TransientObjects.CreateObjectCollection
For Each Item As Object In oSelSet
	oItems.Add(Item)
Next

'Create matrix
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oRx As Matrix
oRx = oTG.CreateMatrix()
oRx.Cell(2,2) = Math.Cos(Parameter("X_Rot")*Math.PI/180)
oRx.Cell(2,3) = -Math.Sin(Parameter("X_Rot")*Math.PI/180)
oRx.Cell(3,2) = Math.Sin(Parameter("X_Rot")*Math.PI/180)
oRx.Cell(3,3) = Math.Cos(Parameter("X_Rot")*Math.PI/180)
Dim oRy As Matrix
oRy = oTG.CreateMatrix()
oRy.Cell(1,1) = Math.Cos(Parameter("Y_Rot")*Math.PI/180)
oRy.Cell(1,3) = Math.Sin(Parameter("Y_Rot")*Math.PI/180)
oRy.Cell(3,1) = -Math.Sin(Parameter("Y_Rot")*Math.PI/180)
oRy.Cell(3,3) = Math.Cos(Parameter("Y_Rot")*Math.PI/180)
Dim oRz As Matrix
oRz = oTG.CreateMatrix()
oRz.Cell(1,1) = Math.Cos(Parameter("Z_Rot")*Math.PI/180)
oRz.Cell(1,2) = -Math.Sin(Parameter("Z_Rot")*Math.PI/180)
oRz.Cell(2,1) = Math.Sin(Parameter("Z_Rot")*Math.PI/180)
oRz.Cell(2,2) = Math.Cos(Parameter("Z_Rot")*Math.PI/180)

'ROTATE each component
Dim oOcc As ComponentOccurrence
For Each oOcc In oSelSet
	Dim oOccTransform As Matrix = oOcc.Transformation
	Dim oTransVec As Vector = oOccTransform.Translation
	If Parameter("X_Rot") > 0 Then 
		oOccTransform.PreMultiplyBy(oRx)
		oOccTransform.SetTranslation(oTransVec, False)
		oOcc.SetTransformWithoutConstraints(oOccTransform)
	End If
	If Parameter("Y_Rot") > 0 Then 
		oOccTransform.PreMultiplyBy(oRy)
		oOccTransform.SetTranslation(oTransVec, False)
		oOcc.SetTransformWithoutConstraints(oOccTransform)
	End If
	If Parameter("Z_Rot") > 0 Then 
		oOccTransform.PreMultiplyBy(oRz)
		oOccTransform.SetTranslation(oTransVec, False)
		oOcc.SetTransformWithoutConstraints(oOccTransform)
	End If
	oOcc.Grounded = True
Next

'Update components constraints
oDoc.Rebuild
'Call saved Selection
oSelSet.SelectMultiple(oItems)
'''End of rule

 

To copy in pattern some components :

Like a rectangular pattern...but in 3 direction.

 

'''COPY components in pattern
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
'check for selection
Dim oSelSet As SelectSet
oSelSet = oDoc.SelectSet
If oSelSet.Count = 0 Then
  Return
End If

Dim CompOcc As ComponentOccurrence
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oDoc.ComponentDefinition
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
Dim oMatrix As Matrix
oMatrix = oTG.CreateMatrix
Dim oOccurrence As ComponentOccurrence
Dim Coords(2) As Double
For Each CompOcc In oSelSet
	'Get the full file name of selected occurence
	FullFileName = CompOcc.Definition.Document.FullFileName
	'Get occurence coordinates
	oMatrix = CompOcc.Transformation
	oMatrix.Translation.GetVectorData(Coords)'in cm
	'Copy occurence according to user parameters
	If Parameter("Nb_X") - 1 > 0 Then
		For i = 1 To Parameter("Nb_X") - 1
			'Set new matrix
			oMatrix.SetTranslation(oTG.CreateVector( _
			Coords(0) + i * Parameter("Esp_X")/10, _
			Coords(1), _
			Coords(2)))
			oOccurrence = oAsmCompDef.Occurrences.Add(FullFileName, oMatrix)
			oOccurrence.Grounded = True
		Next
	End If
	If Parameter("Nb_Y") - 1 > 0 Then
		For i = 1 To Parameter("Nb_Y") - 1
			'Set new matrix
			oMatrix.SetTranslation(oTG.CreateVector( _
			Coords(0), _
			Coords(1) + i * Parameter("Esp_Y")/10, _
			Coords(2)))
			oOccurrence = oAsmCompDef.Occurrences.Add(FullFileName, oMatrix)
			oOccurrence.Grounded = True
		Next
	End If
	If Parameter("Nb_Z") - 1 > 0 Then
		For i = 1 To Parameter("Nb_Z") - 1
			'Set new matrix
			oMatrix.SetTranslation(oTG.CreateVector( _
			Coords(0), _
			Coords(1), _
			Coords(2) + i * Parameter("Esp_Z")/10))
			oOccurrence = oAsmCompDef.Occurrences.Add(FullFileName, oMatrix)
			oOccurrence.Grounded = True
		Next
	End If
Next
'Reset parameters
Parameter("Nb_X") = 1
Parameter("Esp_X") = 0
Parameter("Nb_Y") = 1
Parameter("Esp_Y") = 0	
Parameter("Nb_Z") = 1
Parameter("Esp_Z") = 0
'''End of rule

Hope you will enjoy !

Give Kudos if you like it Smiley Happy

 


Thomas
Mechanical Designer / Inventor Professional 2025
Inventor Professional EESignature

1,295 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

 Could you give an example of where you would apply the parameter to a part or subassembly?

0 Likes
Message 3 of 7

ThomasB44
Mentor
Mentor

Hi @Anonymous

I use these samples of codes in external rules with a global form in a main assembly to place/move parts or subassemblies.

Capture.PNG

So, in my case, parameters are needed in the main assembly.


Thomas
Mechanical Designer / Inventor Professional 2025
Inventor Professional EESignature

0 Likes
Message 4 of 7

Anonymous
Not applicable

Thank You for the reply. I recently started a new job at scaffolding company and was research the best way to quickly assemble scaffold and came across of the codes in your posted. I'm currently building a library of parts that the scaffold is made of. I would eventually like to automate the process as much as possible. I have created the parameters and the global form, but I was wondering if you had time could you post a demonstration if possible using the codes. 

Thank You 

0 Likes
Message 5 of 7

ThomasB44
Mentor
Mentor

Hi @Anonymous

In fact, all my "standard" scaffolding are made with iAssemblies. And I create special scaffolding configurations with these rules, as iAssemblies can't create this.

I've choose to have an Excel file to list my scaffolding components, by product, type (guardrail, deck, toe board...), and size, as listed in my form. This Excel file store the full path of my parts, to call them with iLogic.

These product, type, size and full path name, are also parameters in the assembly.

 

Here below how it works, you will need to have iLogic skills :

1- I start a new main assembly, so parameters don't exist yet :

Capture.PNG

2- I click the red button, firing an external rule to create the needed parameters

This initial rule also create some rules in the main assembly, with product, type and size as blue parameters, so, when I change these parameters in the form, it fire these rules and update them following the Excel file. For example, if I choose a product, it update the type and size, If I choose a type, it update the size only. It also update the full path name as a parameter at each time.

3- I select a component I want to place, as I know their dimensions, it's easy to place them quickly.

Capture.PNG

"Place" button in the form, fire a external rule to add a component, following coordinates entries

"Remplace" button in the form, fire a external to replace the selected component(s) by the one selected in the form

"Replace" button in the form, fire a external to place the selected component(s) following coordinates entries and main assembly origin

"Déplace" button in the form, fire a external to move the selected component(s) following coordinates entries and current component(s) position

"Copie" button in the form, fire a external to duplicate component(s) in pattern following coordinates entries

"Tourne" button in the form, fire a external to turn component(s) following coordinates entries

"Bloc" check box in the form, fire a external to switch all components to their simplified version. I generally start with these simplified parts to have a schematic drawing, if details needed, I switch to full original assembies.

Capture.PNG

Most of the codes I've used come from this forum, I've just adapted them to my need Smiley Wink

 

As I stated, all "standard" scaffolding can be create with iAssemblies, it's easier to automate some process like drawings or visual representations. It's also easy to re-use these iAssemblies members and switch between them. I've personnaly done it for several products with several hundred scaffolding sizes. Smiley Happy


Thomas
Mechanical Designer / Inventor Professional 2025
Inventor Professional EESignature

Message 6 of 7

Anonymous
Not applicable

I'm going to look into using you code. We make scaffolding stages. Use mostly Layher, in combination with custom decking and supports for other components. I find making a complete stage a nightmare in Inventor.

Currently I'm using 3D blocks (exported from Inventor) to build the stage in AutoCAD Mechanical and exporting it to Step.

When the stage is finished, I import the stage in my Inventor assembly, ground all parts and replace the imported (step based) parts by their Inventor version.

Where I'm really struggeling, I determining when a rosette is full. Automating things, or skipping steps in this process would really help...

 

0 Likes
Message 7 of 7

ThomasB44
Mentor
Mentor

Hi @Anonymous 

Glad to see that you want to adapt some of these codes Smiley Wink

It helps me daily and it's very usefull to quickly add some components like we do with Autocad.

 

You want to determine if a rosette is full, but if I reword this, I suppose that you want to know if several components are pinned in the same rosette hole, to check your assembly ?

If yes, this Curtis code will be a really good help. Smiley Wink

 


Thomas
Mechanical Designer / Inventor Professional 2025
Inventor Professional EESignature