ScriptSpot

Forum topic · General Scripting

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

By titane357 · 2016-07-20

Description

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 (1)

barigazy · 2016-07-20

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