loop over selected objects (python)

Discussions concerning programming of SOFTIMAGE©
clankill3r
Posts: 131
Joined: 21 Oct 2012, 13:36

loop over selected objects (python)

Post by clankill3r » 04 Oct 2013, 12:58

Is there any way to loop over the selected objects?

If i run this

Code: Select all

geom = Application.SelectAllUsingFilter("geometry", "siCheckComponentVisibility", "", "")
LogMessage(geom);
Then it seems like a string in the console.
However i can't split it. And neither i can access an element, so i'm guessing it's not an array.

User avatar
Hirazi Blue
Administrator
Posts: 5113
Joined: 04 Jun 2009, 10:15

Re: loop over selected objects (python)

Post by Hirazi Blue » 04 Oct 2013, 13:22

Probably something like this. The Selection object ("a kind of a specialized collection") contains the current selection.

Code: Select all

geom = Application.SelectAllUsingFilter("geometry", "siCheckComponentVisibility", "", "")
for obj in Application.Selection :
	Application.LogMessage( obj.Name )
sdkdocs - Selection
Stay safe, sane & healthy!

clankill3r
Posts: 131
Joined: 21 Oct 2012, 13:36

Re: loop over selected objects (python)

Post by clankill3r » 04 Oct 2013, 14:16

thanks, i will try in half an hour.

User avatar
myara
Posts: 406
Joined: 28 Sep 2011, 08:33

Re: loop over selected objects (python)

Post by myara » 04 Oct 2013, 14:23

That would work because it is selecting and then loop through the new selection.
But since you are creating a variable (Object Collection, not an array) with geom, you could just loop that collection so you could deselect or select something else and you would keep your collection alive. Or even use the SelectAllUsingFilter to not select the objects (SelectAllUsingFilter("geometry", "siCheckComponentVisibility", False) and get the return collection.

Code: Select all

for obj in geom :
   Application.LogMessage( obj.Name )
M.Yara
Character Modeler | Softimage Generalist (sort of)

clankill3r
Posts: 131
Joined: 21 Oct 2012, 13:36

Re: loop over selected objects (python)

Post by clankill3r » 04 Oct 2013, 18:54

thanks!