Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

How to position multiple copied groups?

How to position multiple copied groups?

Anonymous
Not applicable
947 Views
4 Replies
Message 1 of 5

How to position multiple copied groups?

Anonymous
Not applicable

Hi all,

firstly thanks for looking this one over.

I have had a little experience with scripting and programming in the past but generally just learn what I need for the task at hand, then forget it all a week later 😞

What I am attempting to achieve is to get the width, height and length of a group, then duplicate that group multiple times in all axis and position each group next to, along, and on top of the previous duplication.

I'm pretty sure that I am close with this (It works for a none grouped object) but I keep getting an error (-- Runtime error: Not a keyword argument: #pos) at the "pos: [poz_x, pos_y, pos_z]" section of my script (Right at the bottom).

Can anyone help me with this please?

global FindGroupHead
	
	fn FindGroupHead obj = 
	 (
		 if ((isGroupHead obj)AND(not (isGroupMember obj))) then
		(
			return obj
		) 
		 else 
		(
		if (isGroupMember obj) then
		(
			FindGroupHead (obj.parent)
		)
		else
		(
				return undefined)
		)
	 )

on PickFillMesh picked sel do
(		
local SelectedGroupHead = (FindGroupHead sel)
		---------- Get Selected Mesh Dimensions
		FillMeshWidth = (SelectedGroupHead.max - SelectedGroupHead.min).x
		FillMeshLength = (SelectedGroupHead.max - SelectedGroupHead.min).y
		FillMeshHeight = (SelectedGroupHead.max - SelectedGroupHead.min).z
		
		---------- Clone Selected Mesh and Position
		
		for HeightAmount = 1 to StackHeight.value do
		(
			for LenghtAmount = 1 to StackLength.value do
			(
				for WidthAmount = 1 to StackWidth.value do
				(
					pos_z = ((HeightAmount-1) * FillMeshHeight)
					
					pos_y = ((LenghtAmount-1) * FillMeshLength)
				
					pos_x = ((WidthAmount-1) * FillMeshWidth)
					
					maxOps.cloneNodes SelectedGroupHead cloneType:#instance --error here>>>-- pos:[pos_x, pos_y, pos_z]
				)
			)
		)
	)

 

0 Likes
Accepted solutions (1)
948 Views
4 Replies
Replies (4)
Message 2 of 5

miauuuu
Collaborator
Collaborator
Accepted solution

Calculate pos_x, pos_y, pos_z as offset, not as position, and use

 

maxOps.CloneNodes selectedGroupHead cloneType:#instance offset:[pos_x, pos_y, pos_z]

 

https://miauu-maxscript.com/
Message 3 of 5

Anonymous
Not applicable

Thanks miauuuu, that's done the trick, the only issue now is that it is sort of making the first duplicate in the same position of the selected group, let me try and elaborate.

I have a group in the scene, in my UI I have 3 spinners (Length, Width and Height) and a pick button. If I leave my spinners at a value of 1. when I pick the group to duplicate it duplicates on the spot, this is correct behaviour but not what I want.

I need it to either delete the original group or ignore the first duplication. Any ideas?

0 Likes
Message 4 of 5

miauuuu
Collaborator
Collaborator

Try this:

(
	global FindGroupHead
	
	fn FindGroupHead obj = 
	 (
		 if ((isGroupHead obj)AND(not (isGroupMember obj))) then
		(
			return obj
		) 
		 else 
		(
		if (isGroupMember obj) then
		(
			FindGroupHead (obj.parent)
		)
		else
		(
				return undefined)
		)
	 )
	 
	--	"credits to denisT"
	fn GetGeometryGroupMembers node = if isgrouphead node do
	(
		for node in (join #() node) where iskindof node geometryclass and canconvertto node editable_mesh collect node 
	)
	--	"credits to denisT"
	fn isGroupHeadMember head node act:off = 
	(
		while isvalidnode node and isgroupmember node and not (act = (node.parent == head)) do node = node.parent
		act
	)
	--	"credits to denisT"
	fn getAllGroupMembers head = if isgrouphead head do
	(
		for node in (join #() head) where isGroupHeadMember head node collect node
	)
	

on PickFillMesh picked sel do
(		
local SelectedGroupHead = (FindGroupHead sel)
		---------- Get Selected Mesh Dimensions
		FillMeshWidth = (SelectedGroupHead.max - SelectedGroupHead.min).x
		FillMeshLength = (SelectedGroupHead.max - SelectedGroupHead.min).y
		FillMeshHeight = (SelectedGroupHead.max - SelectedGroupHead.min).z
		
		---------- Clone Selected Mesh and Position
		
		for HeightAmount = 1 to StackHeight.value do
		(
			for LenghtAmount = 1 to StackLength.value do
			(
				for WidthAmount = 1 to StackWidth.value do
				(
					pos_z = ((HeightAmount-1) * FillMeshHeight)
					
					pos_y = ((LenghtAmount-1) * FillMeshLength)
				
					pos_x = ((WidthAmount-1) * FillMeshWidth)
					
					maxOps.CloneNodes selectedGroupHead cloneType:#instance offset:[pos_x, pos_y, pos_z]
				)
			)
		)
		
		delete (getAllGroupMembers SelectedGroupHead)
		--	"if group head is not deleted"
		--	delete SelectedGroupHead
	)
)

 

https://miauu-maxscript.com/
0 Likes
Message 5 of 5

Anonymous
Not applicable

Works like a charm, thank you for all the help.

0 Likes