Page 1 of 2

Re: get texture script

Posted: 25 Oct 2012, 16:00
by xsisupport

Code: Select all

"%s.Texture_Map.ImageClipName" % oItem.Name

Re: get texture script

Posted: 25 Oct 2012, 16:07
by caledonian_tartan
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 "%"

Re: get texture script

Posted: 25 Oct 2012, 16:19
by xsisupport
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

Re: get texture script

Posted: 25 Oct 2012, 17:03
by caledonian_tartan
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

Re: get texture script

Posted: 25 Oct 2012, 17:17
by caledonian_tartan
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

Re: get texture script

Posted: 26 Oct 2012, 00:21
by EricTRocks
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

Re: get texture script

Posted: 26 Oct 2012, 08:41
by caledonian_tartan
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...

Re: get texture script

Posted: 26 Oct 2012, 08:47
by EricTRocks
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. :)

Re: get texture script

Posted: 26 Oct 2012, 09:09
by Letterbox
and for completeness sake here's an ICE way...

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

have fun.