ScriptSpot

Forum topic · General Scripting

Check State

By JokerMartini · 2011-03-26

Description

I have a script where I need to have a check state running through every object in the selection and if any of the objects are being used as a variable then DO NOT run the script.

This is what I have so far and it is not right.
Because if 2 objects are ok and 1 is a bad object, the script still runs, it does not stop after finding the bad one.


StartObj = $Sphere005
EndObj = $Sphere001
CheckSt = false

for i = 1 to selection.count do
(
obj = selection[i]
if (obj.name == StartObj.name or obj.name == EndObj.name)then
(
CheckSt = false
)
else
(
CheckSt = true
)
)

if CheckSt == false then
(
messagebox "Make sure the reference objects are NOT selected"
)
else
(
--Run Scripted Function Here
)

Comments (4)

JokerMartini · 2011-03-28

Alright I'll implement this version of it instead.
Thanks again Anubis.

Anubis · 2011-03-27

if i see, this fn s'd be called per obj,
if so, the loop s'd be out of the fn, like...

fn getState obj = (
	not (obj.name == StartObj.name or obj.name == EndObj.name)
)

for obj in selection do
	if getState obj then ...

JokerMartini · 2011-03-26

Thanks Garp,
I'll be sure to implement this.
I appreciate the help.

JokerMartini

Run your code 'manually'.

Garp · 2011-03-26

At the end of the loop, your ChechSt variable will have its value set according to the last object tested.

Try this instead


fn state_ok = 
(
  for obj in selection do
    if (obj.name == StartObj.name or
        obj.name == EndObj.name) do return false
    
    return true
)
 
if state_ok() then 
(
	--Run Scripted Function Here
)
else messagebox "Make sure the reference objects are NOT selected"