running this script from "run script" don't work...

Hi,
I made a little script to project an object on a surface keeping its volume
when I drag and drop the script to max it works fine, when I run from menu "run script" it don't work as it should.
anybody can help ? thanks

How to use :
- select an edit poly object, select all its vertices to be projected
- drag and drop the script to max
- pick a vertex of the selected object which will be in contact with the surface
- clic the button and choose a target surface

---------------------------------------------------------
(
savesnap=snapMode.active
snapMode.active=true

ptax = pickpoint snap:#3d
vvv = $
rollout pick_box_test "Target surface"
(
pickbutton chooseit "Project on me" width:140
on chooseit picked obj do
(
undo on(
for v in polyOp.getVertSelection vvv do
(
pta = (polyOp.getVert vvv v)
RRay = ray pta [0,0,-1]
aaa = (intersectRay obj RRay)

if aaa != undefined then
(
PPos = (intersectRay obj RRay).pos
PPosPRO = [ PPos.x , PPos.y , (PPos.z + pta.z - ( ptax.z)) ]
polyOp.setVert vvv v PPosPRO
)
else
(
RRay = ray pta [0,0,1]
aaa = (intersectRay obj RRay)
if aaa !=undefined then
(
PPos = (intersectRay obj RRay).pos
PPosPRO = [ PPos.x , PPos.y , (PPos.z + pta.z - ( ptax.z)) ]
polyOp.setVert vvv v PPosPRO
)
)---end else

)--- end for
)--- end undo on
snapMode.active=savesnap
)--- end on choseit

)--- end rollout
createDialog pick_box_test

)
-------------------------------------------------------

Comments

Comment viewing options

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

...

What if you not have selected object or more then one selected objects.
Your concept is not good. Better create two pickbuttons : one for source and second for target object. Anyway ... this is fixed your first code

try(destroyDialog ::pick_box_test)catch()
rollout pick_box_test "Target surface"
(
	local savesnap, node = undefined, ptax = [0,0,0]
	local getVertSelection = polyOp.getVertSelection, getVert = polyOp.getVert, setVert = polyOp.setVert
	pickbutton chooseit "Project on me" width:140
	on pick_box_test open do
	(
		if selection.count == 1 and isKindOf selection[1] editable_poly do node = selection[1]
		savesnap = snapMode.active
		snapMode.active = true
		ptax = pickpoint snap:#3d
	)
	on chooseit picked obj do if isValidNode obj and isKindOf obj editable_poly and isValidNode node do with undo on
	(
		if not (verts = getVertSelection node).isEmpty do
		(
			for v in verts do
			(
				pta = (getVert node v)
				RRay = ray pta [0,0,-1]
				aaa = (intersectRay obj RRay)
 
				if aaa != undefined then
				(
					PPos = (intersectRay obj RRay).pos
					PPosPRO = [ PPos.x , PPos.y , (PPos.z + pta.z - ( ptax.z)) ]
					setVert node v PPosPRO
				)
				else
				(
					RRay = ray pta [0,0,1]
					aaa = (intersectRay obj RRay)
					if aaa != undefined then
					(
						PPos = (intersectRay obj RRay).pos
						PPosPRO = [ PPos.x , PPos.y , (PPos.z + pta.z - ( ptax.z)) ]
						setVert node v PPosPRO
					)
				)---end else
			)--- end for
		)
		snapMode.active=savesnap
	)--- end on choseit
)--- end rollout
createDialog pick_box_test

barigazy

Comment viewing options

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