ScriptSpot

Forum topic · General Scripting

why doesn't the script see the variable ???

By Any · 2020-09-06

Downloads
Description

Good afternoon.

I'm trying to create a script that moves objects in a certain direction (X,Y,Z) ....
in the initial position, these objects are located inside another object
_______________________________________________________________________________________
try (DestroyDialog parent_dialog) catch()
rollout parent_dialog "Parent" width:140 height:140
(
local varDir = undefined
local arrayObj =#() -- массив выбранных объектов

checkbox XPOS "X pos."
checkbox YPOS "Y pos."
checkbox ZPOS "Z pos."
button btPrepear "Prepear"

on btPrepear pressed do
(
arrayObj = selection as array
case of
(
(XPOS.checked == true):
(
varDir = "arrayObj[t].pos.x = arrayObj[t].pos.x + 1.0"
)
(YPOS.checked == true):
(
varDir = "arrayObj[t].pos.y = arrayObj[t].pos.y + 1.0"
)
(ZPOS.checked == true):
(
varDir = "arrayObj[t].pos.z = arrayObj[t].pos.z + 1.0"
)
)
for t = 1 to arrayObj.count do
(
while (intersects arrayObj[t] $Box001 == true) do
(
execute varDir
)
)
)
)

createDialog parent_dialog pos:[1580,30] style:#(#style_titlebar, #style_border, #style_sysmenu, #style_minimizebox)
__________________________________________________________________

when I do such conversions without creating a CreateDialog everything is happening normally. But if I use CreateDialog function,an error occurs.
It seems that the script does not see the internal variable.

I attach a scene

Comments (2)

Swordslayer · 2020-09-13

Your arrayObj is local inside the parent_dialog scope, while execute always works in global scope. While you could address it as parent_dialog.arrayObj, you're also using variable t, that's local to the for loop scope. It's better to rethink it and do it without execute altogether:

try destroyDialog parent_dialog catch()
rollout parent_dialog "Parent" width:140 height:140
(
    local cullObj = $Box001

    checkBox XPOS "X pos."
    checkBox YPOS "Y pos."
    checkBox ZPOS "Z pos."
    button btPrepear "Prepear"

    on btPrepear pressed do with undo "Move Objects" on
        for obj in selection do if intersects obj $Box001 do move obj \
            [if XPOS.checked then amax 0 (ceil (cullObj.max.x - obj.min.x)) else 0,
             if YPOS.checked then amax 0 (ceil (cullObj.max.y - obj.min.y)) else 0,
             if ZPOS.checked then amax 0 (ceil (cullObj.max.z - obj.min.z)) else 0]
)
createDialog parent_dialog pos:[1580,30] style:#(#style_titlebar, #style_border, #style_sysmenu, #style_minimizebox)

.

jahman · 2020-09-06

you can define offset for all three axis at the same time

offset = [5.0,5.0,5.0] * [ if XPOS.checked then 1 else 0, if YPOS.checked then 1 else 0, if ZPOS.checked then 1 else 0]