Home Coding, Scripting, Shaders

[Maxscript] Create bone between selections

polycounter lvl 7
Offline / Send Message
dg3duy polycounter lvl 7
This script to build bones based on selected objects works perfect if you are going to use it only once in the scene.
It gives error when using it again for the second time in the scene, apparently it is the way your array is built, as I do not have enough knowledge to solve it public here the question.
Is it possible to correct it to be able to use it as many times as one wants in a same scene?






[code]

fn creaHuesoEntreSelecciones ancho alto tapersito=
	
(
	bns=#()
	pts = selection as array

	for i = 1 to pts.count-1 do
	(
		crearHuesos= bonesys.createbone (pts[i].pos) (pts[i+1].pos) [0,0,1]	
		crearHuesos.name = ("huesito_"+i as string)
	)


	creaHuesoFinal=bonesys.createbone (pts[pts.count].pos) (pts[pts.count].pos) [0,0,1]
		creaHuesoFinal.name= ("huesito_"+pts.count as string)

	bns = $huesito_* as array
	pts= selection as array

	bns.width= ancho
	bns.Height= alto
	bns.taper= tapersito

	for i = 1 to bns.count do
	(
		if bns[i] != bns[1] then bns[i].parent = bns[i-1]
		bns[i].position.controller =position_constraint()
		bns[i].position.controller.appendtarget pts[i] 100
		if bns[i]!= bns[bns.count] then bns[i].rotation.controller =lookAt_constraint target_axis:0 upnode_axis:2 StoUP_axis:2 lookat_vector_length:0 else bns[i].rotation.controller= Euler_XYZ()
		
		if bns[i] != bns[bns.count] then bns[i].rotation.controller.appendtarget pts[i+1] 100 else 0
		if bns[i]!= bns[bns.count] then bns[i].rotation.controller.pickupnode=pts[i] else 0
		if bns[i]!= bns[bns.count] then bns[i].rotation.controller.upnode_world=false else 0
	)
	--ROTACION DEL HUESO FINAL
	in coordsys bns[bns.count-1] bns[bns.count].rotation = eulerangles 0 0 0
	--TAMAÑO DEL HUESO FINAL	
	bns[bns.count].length=bns[bns.count-1].length/20
	bns[bns.count].width= bns[bns.count-1].width/20
	bns[bns.count].height= bns[bns.count-1].height/20
	select bns
)
rollout CreaCadenaEntreSelecciones "CreateBones"
(
	spinner UI_width "width" range:[1,100,2]
	spinner UI_height "height"range:[1,100,2]
	spinner UI_taper "taper" range:[1,100,2]
	
	button CreateBones "CreateBones"
	
	on CreateBones pressed do
	(
		if selection.count > 0  then 
			(
				creaHuesoEntreSelecciones (UI_width.value)  (UI_height.value)  (UI_taper.value)
			)
			else messagebox "Seleccione mas de un objeto"
	)
)

createDialog CreaCadenaEntreSelecciones

[/code]

Replies

  • Swordslayer
    Offline / Send Message
    Swordslayer interpolator
    try destroyDialog CreaCadenaEntreSelecciones catch()
    rollout CreaCadenaEntreSelecciones "Create Bones"
    (
    	spinner UI_width "Width: " range:[1,100,2]
    	spinner UI_height "Height: "range:[1,100,2]
    	spinner UI_taper "Taper: " range:[1,100,2]
    	button createBones "Create Bones"
    
    	fn creaHuesoEntreSelecciones pts width height taper =
    	(
    		local numPts = pts.count
    		local prevBone = unsupplied
    
    		local bones = for i = 1 to numPts collect
    		(
    			local bone = ::Bone prefix:"huesito_" pos:pts[i].pos baseObject:(createInstance BoneGeometry width:width height:height taper:taper forceCreate:on) parent:prevBone boneEnable:on
    			bone.position.controller = Position_Constraint()
    			bone.position.controller.appendTarget pts[i] 100
    			if isValidNode prevBone do prevBone.resetBoneStretch()
    
    			if i < numPts then
    			(
    				bone.rotation.controller = LookAt_Constraint target_axis:0 upnode_axis:2 upnode_world:off pickUpNode:pts[i] StoUP_axis:2 lookAt_vector_length:0
    				bone.rotation.controller.appendTarget pts[i + 1] 100
    			)
    			else
    			(
    				in coordsys prevBone bone.rotation = quat 1
    				bone.length = prevBone.length / 20
    				bone.height /= 20
    				bone.width /= 20
    			)
    
    			prevBone = bone
    		)
    
    		select bones
    	)
    
    	on createBones pressed do
    		if selection.count > 0 then with undo "Create Bones" on
    			creaHuesoEntreSelecciones (selection as array) UI_width.value UI_height.value UI_taper.value
    		else messagebox "Seleccione mas de un objeto"
    )
    createDialog CreaCadenaEntreSelecciones

  • dg3duy
    Offline / Send Message
    dg3duy polycounter lvl 7
    try destroyDialog CreaCadenaEntreSelecciones catch()
    rollout CreaCadenaEntreSelecciones "Create Bones"
    (
    	spinner UI_width "Width: " range:[1,100,2]
    	spinner UI_height "Height: "range:[1,100,2]
    	spinner UI_taper "Taper: " range:[1,100,2]
    	button createBones "Create Bones"
    
    	fn creaHuesoEntreSelecciones pts width height taper =
    	(
    		local numPts = pts.count
    		local prevBone = unsupplied
    
    		local bones = for i = 1 to numPts collect
    		(
    			local bone = ::Bone prefix:"huesito_" pos:pts[i].pos baseObject:(createInstance BoneGeometry width:width height:height taper:taper forceCreate:on) parent:prevBone boneEnable:on
    			bone.position.controller = Position_Constraint()
    			bone.position.controller.appendTarget pts[i] 100
    			if isValidNode prevBone do prevBone.resetBoneStretch()
    
    			if i < numPts then
    			(
    				bone.rotation.controller = LookAt_Constraint target_axis:0 upnode_axis:2 upnode_world:off pickUpNode:pts[i] StoUP_axis:2 lookAt_vector_length:0
    				bone.rotation.controller.appendTarget pts[i + 1] 100
    			)
    			else
    			(
    				in coordsys prevBone bone.rotation = quat 1
    				bone.length = prevBone.length / 20
    				bone.height /= 20
    				bone.width /= 20
    			)
    
    			prevBone = bone
    		)
    
    		select bones
    	)
    
    	on createBones pressed do
    		if selection.count > 0 then with undo "Create Bones" on
    			creaHuesoEntreSelecciones (selection as array) UI_width.value UI_height.value UI_taper.value
    		else messagebox "Seleccione mas de un objeto"
    )
    createDialog CreaCadenaEntreSelecciones

    Thank you very much! Now it works perfect
Sign In or Register to comment.