how to make script for clone and align ?

how to make script for making aclone (instanse) of selected object or group and align them to object you select it after starting the script .
Like this script from -Jim Jagger-

JJTools_CreateAlign

(
toolmode.coordsys #local
Box lengthsegs:1 widthsegs:1 heightsegs:1 length:12 width:7 height:4 mapCoords:off pos:[0,0,0] isSelected:on
selectedbox = selection as array
targetbox = pickobject()
selectedbox.rotation = targetbox.rotation
selectedbox.pos = targetbox.transform.position
)

Comments

Comment viewing options

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

nothing fancy

to clone you can use instance() or maxOps.CloneNodes() function.

-- #1 using instance() function:
if selection.count > 0 do
(
	trgObj = pickObject()
	if IsValidNode trgObj do
	(
		allObjs = objects.count
		instance selection
		newObjs = for i = (allObjs+1) to objects.count collect objects[i]
		newObjs.transform = trgObj.transform -- align
	)
)
 
-- #2 using maxOps.CloneNodes() function:
if selection.count > 0 do
(
	trgObj = pickObject()
	if IsValidNode trgObj do
	(
		maxOps.CloneNodes selection \
			expandHierarchy:true \
			cloneType:#instance \
			actualNodeList:&anl newNodes:&nnl
		nnl.transform = trgObj.transform -- align
	)
)

my recent MAXScripts RSS (archive here)

Comment viewing options

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