get texture script

Discussions concerning programming of SOFTIMAGE©
User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 11:02
Location: Montreal Canada
Contact:

Re: get texture script

Post by xsisupport » 25 Oct 2012, 16:00

Code: Select all

"%s.Texture_Map.ImageClipName" % oItem.Name
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage

caledonian_tartan
Posts: 253
Joined: 17 Feb 2010, 15:13

Re: get texture script

Post by caledonian_tartan » 25 Oct 2012, 16:07

i have it working for the first selected object only:

Code: Select all

from siutils import si
si = si()               # win32com.client.Dispatch('XSI.Application')
from siutils import log      # LogMessage
from siutils import disp   # win32com.client.Dispatch
from siutils import C      # win32com.client.constants

o = si.Selection(0)
mat = o.Materials(0)
i = mat.ImageClips(0)
txmap = o.LocalProperties.Filter("TextureProp")(0)
txmap.Parameters("ImageClipName").Value = i.Name

Application.SetValue(txmap.Parameters("ImageClipName"), "Clips." + i.Name, "")
now i should iterate over the selection, which confuses me...


PS.: as you can see i used "+". i assume this is the same as "%"
SI 2015 @ WIN7-64

User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 11:02
Location: Montreal Canada
Contact:

Re: get texture script

Post by xsisupport » 25 Oct 2012, 16:19

caledonian_tartan wrote:i have it working for the first selected object only:

Code: Select all

from siutils import si
si = si()               # win32com.client.Dispatch('XSI.Application')
from siutils import log      # LogMessage
from siutils import disp   # win32com.client.Dispatch
from siutils import C      # win32com.client.constants

o = si.Selection(0)
mat = o.Materials(0)
i = mat.ImageClips(0)
txmap = o.LocalProperties.Filter("TextureProp")(0)
txmap.Parameters("ImageClipName").Value = i.Name

Application.SetValue(txmap.Parameters("ImageClipName"), "Clips." + i.Name, "")
now i should iterate over the selection, which confuses me...


PS.: as you can see i used "+". i assume this is the same as "%"
My snippet works on the first object in the selection ("si.Selection(0)", note the "(0)").

If I wanted to turn it into a loop, I would do something like this:

Code: Select all

for o in si.Selection:
    mat = o.Materials(0)
    i = mat.ImageClips(0)
    txmap = o.LocalProperties.Filter("TextureProp")(0)
    txmap.Parameters("ImageClipName").Value = i.Name
This crude snippet works on the first material, the first image clip, and first texturemap property found.
My last line is setting the parameter value, but through the OM instead of with SetValue.

ciao
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage

caledonian_tartan
Posts: 253
Joined: 17 Feb 2010, 15:13

Re: get texture script

Post by caledonian_tartan » 25 Oct 2012, 17:03

whatever i do the loop doesn't work:


in eric's version it logs 3 objects, but only one material/texture/clip.

Code: Select all

from siutils import si
si = si()                  # win32com.client.Dispatch('XSI.Application')
from siutils import log    # LogMessage
from siutils import disp   # win32com.client.Dispatch
from siutils import C      # win32com.client.constants

for eachObj in Application.Selection:
    log(eachObj.FullName) 

oMat = eachObj.Material

collImgClips = oMat.ImageClips 

oImgClip = collImgClips(0)



print oMat

print collImgClips

print oImgClip

steve's version is understandable but even with the suggested "for o in si.Selection:" it sets all texture maps to noIcon_pic

Code: Select all

from siutils import si
si = si()                  # win32com.client.Dispatch('XSI.Application')
from siutils import log    # LogMessage
from siutils import disp   # win32com.client.Dispatch
from siutils import C      # win32com.client.constants




for o in si.Selection:
    mat = o.Materials(0)
    i = mat.ImageClips(0)
    txmap = o.LocalProperties.Filter("TextureProp")(0)
    txmap.Parameters("ImageClipName").Value = i.Name


#Application.SetValue(txmap.Parameters("ImageClipName"), "Clips." + i.Name, "")

print txmap.Parameters("ImageClipName").Value
SI 2015 @ WIN7-64

caledonian_tartan
Posts: 253
Joined: 17 Feb 2010, 15:13

Re: get texture script

Post by caledonian_tartan » 25 Oct 2012, 17:17

OK. It's done!

wouldn't have been possible without you guys, thanks a lot:

Code: Select all

from siutils import si
si = si()                  # win32com.client.Dispatch('XSI.Application')
from siutils import log    # LogMessage
from siutils import disp   # win32com.client.Dispatch
from siutils import C      # win32com.client.constants




for o in si.Selection:
    mat = o.Materials(0)
    i = mat.ImageClips(0)
    txmap = o.LocalProperties.Filter("TextureProp")(0)
    txmap.Parameters("ImageClipName").Value = "Clips." + i.Name

# log all object names

for obj in Application.Selection :
    Application.LogMessage( obj.name )

# log object count

oObjectCount = len(Application.Selection)

Application.LogMessage("%s Objects edited" %(oObjectCount))
i just had to change
i.Name
to
"Clips." + i.Name

again, thx
SI 2015 @ WIN7-64

EricTRocks
Moderator
Posts: 754
Joined: 25 Nov 2009, 01:41
Contact:

Re: get texture script

Post by EricTRocks » 26 Oct 2012, 00:21

Glad you finally got it working. Also a word of advice, don't use VBScript. No one I know uses it any more. Python is the way to go so stick to that in the future. :D
Eric Thivierge
Lead Kraken Developer, Fabric Engine
http://fabric-engine.github.io/Kraken

caledonian_tartan
Posts: 253
Joined: 17 Feb 2010, 15:13

Re: get texture script

Post by caledonian_tartan » 26 Oct 2012, 08:41

Glad you finally got it working...
:ymblushing:

i shurely want to stick the python way. unfortunately the majority of SDK examples is JS or VB...
SI 2015 @ WIN7-64

EricTRocks
Moderator
Posts: 754
Joined: 25 Nov 2009, 01:41
Contact:

Re: get texture script

Post by EricTRocks » 26 Oct 2012, 08:47

Easily transferable once you know Python better and the Softimage Object Model. The SDK Guide and the SDK Explorer in the Views are key to understanding. :)
Eric Thivierge
Lead Kraken Developer, Fabric Engine
http://fabric-engine.github.io/Kraken

Letterbox
Posts: 391
Joined: 17 Jun 2009, 14:49

Re: get texture script

Post by Letterbox » 26 Oct 2012, 09:09

and for completeness sake here's an ICE way...

viewtopic.php?f=41&t=2935&start=0

have fun.

Post Reply

Who is online

Users browsing this forum: No registered users and 32 guests