ScriptSpot

Forum topic · General Scripting

If.....then.......

By Mrjacks2o · 2015-10-26

Description

how can i make it search the name in the selected objects instead of the entire scene?
the script searches the entire scene i want to search only the selected objects for G1.

thanks in advance.

on insert pressed do
(
objVar = $G1
(
if isvalidnode objVar then
(
Print "1"
)
else
(
Print "2"
)
)
)

Comments (4)

barigazy · 2015-10-26


objToFind = "ObjName"
objVar = $G1
(
if isvalidnode objVar and objVar.children.count != 0 do
(
node = for o in objVar.children where o.name == objToFind collect o
if node.count != 0 then
(
Print "1"
)
else
(
Print "2"
)
)
)

Thanks but

Mrjacks2o · 2015-10-26

Hi Thanks for the replay but its not working for me.
it keeps printing 2 if the object is selected or not. how can i have it print "1" if selected and if the name = G1 else print "2"

rollout test "Test"
(
listBox testList items:#("Item 1","Item 2")
button addToList "Add Item To End Of List" width:180
button insertToList "Insert Before Current Item" width:180
button removeFromList "Remove Current Item" width:180

on addToList pressed do
testList.items = append testList.items "test"
on insertToList pressed do
(
objToFind = "ObjName"
objVar = $G1
(
if isvalidnode objVar and objVar.children.count != 0 do
(
node = for o in objVar.children where o.name == objToFind collect o
if node.count != 0 then
(
Print "1"
)
else
(
Print "2"
)
)
)
)

on removeFromList pressed do
(
testList.items = deleteItem testList.items testList.selection
)
)
createDialog test 200 220

`

pixamoon · 2015-10-27

try those:


for i = 1 to selection.count do (
	if selection[i].name == "G1" do (
		print "1"
		exit
	)
	if i == selection.count do print "2"
)

or this one:
(it also collect objects with specified name)


someArray = for o in selection where o.name == "G1" collect o
if someArray.count > 0 then print "1" else print "2"

Great!!! thank you both!!!!

Mrjacks2o · 2015-10-27

worked great.