[QUOTE][/QUOTE]Hey there. I’ve got a noob question.
I just got started working on Softimage, and I’m having a seeminly silly problem with an extremely simple piece of code. For some reason, creating objects inside of a For loop breaks the loop. This is what my code snippet looks like (this is actually a simplified version of what I’m trying to do, but it shows what’s going on…)
objSel = Application.Selection
for obj in objSel:
print obj.name
new_ctrl = Application.GetPrim("Null", "", "", "")
Application.SelectObj(objSel, "NODE", True)
The last line of the script is not necessary, but I added it to see what was happening with my selection, and that’s when things got interesting.
The idea is to select some objects in the scene, and run this script. The script will create one Null per selected object. So, three selected objects get you three Nulls in the scene. If I comment out the GetPrim line, the names are printed fine. But including it prevents the loop from passing the 1st iteration. The interesting thing about the last line is that, instead of selecting the original objects that I had when the code was executed, it selects the new Null! So, what’s going on in there? Why has the stored selection changed? And why does that change (if that’s what’s happening) break the loop? This is happening in Softimage 2012, BTW…
I appreciate any help with this. Thanks a lot! (Getting a hang of scripting for Softimage…)
[SUB]caveat: I know nothing of Softimage, and my python is rusty, this is just a guess.[/SUB]
Maybe objSelalways references Application.Selection which always references the current selction,
and new_ctrl = Application.GetPrim(“Null”, “”, “”, “”) causes Application.Selection to change to the newly created node, thus ending the loop
so instead of objSel referenceing the selection, pass the selected objects to an objSel array.
objSel=[]
for obj in Application.Selection:
objSel.append [obj]
[QUOTE=Mambo4;22487][SUB]caveat: I know nothing of Softimage, and my python is rusty, this is just a guess.[/SUB]
Maybe objSelalways references Application.Selection which always references the current selction,
and new_ctrl = Application.GetPrim(“Null”, “”, “”, “”) causes Application.Selection to change to the newly created node, thus ending the loop
so instead of objSel referenceing the selection, pass the selected objects to an objSel array.
objSel=[]
for obj in Application.Selection:
objSel.append [obj]
(no gaurantees on my syntax…)[/QUOTE]
That did it. I felt something like that was happening, but I hadn’t dealt with a situation where a selection stored in a variable was actually a live selection. The syntax was close enough… I just corrected a small detail, and now the code snippet works. Thanks a lot for your help Mambo!