Python Create Objects as Child or Not

Discussions concerning programming of SOFTIMAGE©
Post Reply
CYTE
Posts: 33
Joined: 05 Sep 2015, 07:55

Python Create Objects as Child or Not

Post by CYTE » 19 Aug 2016, 06:11

Hi everybody,
this is fairly simple. i just want to create an object as a child of the current selection. this works fine. but i just cant figure out how to create the object normally if nothing is selected.... have a look and thanks for any help CYTE:



from win32com.client import constants as c

selObjects = []
for oObject in Application.Selection:
selObjects.append(oObject)

if (Application.Selection > None):
for oObject in selObjects:
Application.CreatePrim("Cube", "MeshSurface", "Cube_1", "")
Application.SetValue(".cube.length", 6, "")
Application.Translate("", 0, 3, 0, "siAbsolute", "siPivotCOG", "siObj", "siY", "", "", "", "", "", "", "", "", "", 0, "")
Application.AddToSelection(oObject, "", True)
Application.ParentObjects("")
else:
Application.CreatePrim("Cube", "MeshSurface", "Cube_1", "")
Application.SetValue(".cube.length", 6, "")
Application.Translate("", 0, 3, 0, "siAbsolute", "siPivotCOG", "siObj", "siY", "", "", "", "", "", "", "", "", "", 0, "")

CYTE
Posts: 33
Joined: 05 Sep 2015, 07:55

Re: Python Create Objects as Child or Not

Post by CYTE » 19 Aug 2016, 06:49

found it:

from win32com.client import constants as c

selObjects = []
for oObject in Application.Selection:
selObjects.append(oObject)

if (Application.Selection(0) != None):
for oObject in selObjects:
Application.CreatePrim("Cube", "MeshSurface", "Cube_1", "")
Application.SetValue(".cube.length", 6, "")
Application.Translate("", 0, 3, 0, "siAbsolute", "siPivotCOG", "siObj", "siY", "", "", "", "", "", "", "", "", "", 0, "")
Application.AddToSelection(oObject, "", True)
Application.ParentObjects("")
Application.TransZero()
else:
Application.CreatePrim("Cube", "MeshSurface", "Cube_1", "")
Application.SetValue(".cube.length", 6, "")
Application.Translate("", 0, 3, 0, "siAbsolute", "siPivotCOG", "siObj", "siY", "", "", "", "", "", "", "", "", "", 0, "")

User avatar
myara
Posts: 403
Joined: 28 Sep 2011, 10:33

Re: Python Create Objects as Child or Not

Post by myara » 22 Aug 2016, 10:15

If you're going to script in Softimage, you'll want to write in Object Mode for those things.

Being said that it may take a while to get used to it so I'm not sure if that would worth the effort for a dead Software.

Code: Select all

#python
xsi = Application
sel = xsi.GetValue('selectionlist')
for obj in sel:
    cube = obj.AddGeometry('cube', 'MeshSurface')
    cube.length = 6
    cube.posy = 3
    cube.name = 'Cube_1'
And next time use the code tag or the code spacing will get messed up.
M.Yara
Character Modeler | Softimage Generalist (sort of)

CYTE
Posts: 33
Joined: 05 Sep 2015, 07:55

Re: Python Create Objects as Child or Not

Post by CYTE » 22 Aug 2016, 10:25

hey myara,
thanks for the tips! yes i will use the code style next time!
I´m fairly new to scripting...
for me softimage isnt dead, i use it everyday. for me its like a pencil and i dont need new fancy features on my pencil every year.
and now i can customize the hell out of softi, as it will stay like it is! \m/
even today lots of stuff gets produced that doesnt look as good as jurassic park (1993) (just sayin)

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests