object cloning with offset to selection

This is a bit Maxscript 101, but I cant seem to get it to work. Let's say you have 5 boxes (copies or instances) in a selection, I am looking to create a new clone object (sphere) offset in the -z direction. I have been looking online and at the maxscript help but cant get it to work as I want.

This is what I have so far. Any help would be much appreciated!

for i in selection do
(
nl = sphere radius:3
newObj = maxOps.cloneNodes nl cloneType:#instance newNodes:i #nodialog
nl.pos = i.pos
nl.pos.z = nl.pos.z - 10
)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
miauu's picture

.

(
	nl = sphere radius:3
	for i in selection do
	(		
		newObj = maxOps.cloneNodes nl cloneType:#instance newNodes:i #nodialog
		nl.pos = i.pos
		nl.pos.z = nl.pos.z - 10
	)
)
ce89's picture

Hi Miauu, Thank you for that.

Hi Miauu,

Thank you for that. I thought I was very close :)

Just one quick question. Do you know why it creates an instance at 0,0,0 also. There is nothing in my selection at that location, but it still seems to create an instance object at that point?

miauu's picture

.

Because this line:

nl = sphere radius:3

creates a sphere at 0,0,0 no matter if you use my code or yours. Then, in the for loop the script cretes an instance below each box object.

This will creates new sphere below the boxes, without creating a sphere at 0,0,0

(
	for i in selection do
	(		
		nl = sphere radius:3
		nl.pos = i.pos
		nl.pos.z = nl.pos.z - 10
	)
)

This will create instances:

(
	nl = sphere radius:3
	for i in selection do
	(
		newObj = instance nl
		newObj.pos = i.pos
		newObj.pos.z = nl.pos.z - 10
	)
	delete nl
)
ce89's picture

Miauu, Thank you so much.

Miauu,

Thank you so much. Very much appreciated!!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.