get texture script

Discussions concerning programming of SOFTIMAGE©
caledonian_tartan
Posts: 253
Joined: 17 Feb 2010, 15:13

get texture script

Post by caledonian_tartan » 25 Oct 2012, 13:23

dear community

i have the follwing problem i dont know how to solve...
i have 1000 objects, each with its own material with a texture. now i would like to have the same texture as texturemap,
so i can work with just one shader and pipe the texture information via "color map lookup" into the shader.
now, how the heck can i create a texturemap for every object and get automatic the right texture i use in the existing shader as the texture in the texturemap-property?
searched the hole web, nothing... so a script might be the path, but... im not able to do it, my scripting abilities are to poor...
any help is very welcome!

thank you very much
SI 2015 @ WIN7-64

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

Re: get texture script

Post by EricTRocks » 25 Oct 2012, 13:47

This question is sitting on the fence so I'll ask you to clarify your question with a reminder to read this before posting in this forum:
viewtopic.php?f=16&t=2532

You need to be asking specific programming questions and posting code that you are attempting to put together to complete the task you have in front of you. This is not a forum to ask someone to write tools for you.

Where are you stuck programming-wise? Do you know how to create a texture map via scripting on all 1000 objects? Do you need to know how to look up the image clip used in the shader to then use the same clip in the texture map?

Other moderator edit: A bit harsh maybe?
As a moderator you might also want to read this post again... :D - HB
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 » 25 Oct 2012, 14:05

you're right eric, i'm sorry
i was a bit in a rush...

so here's what i have so far (in Python)

here's the code logged when connecting a texture to the image node:

Code: Select all

Application.SIConnectShaderToCnxPoint("Clips.Engines_jpg", "Sources.Materials.DefaultLib.Material.Image.tex", False)
i' trying to derive the code for "get the materials texture." this should be possible to evaluate from the SDK help. i hope.


connect a texture to a texture map:

Code: Select all

Application.SetValue("sphere.Texture_Map.ImageClipName", "Clips.Engines_jpg", "")
here's what i'm stuck on:

can i use the selection model to tell the script: "get the texture of the selected objects material and apply that to the same objects texture map"?
or do i need to iterate over the selection in some matter?

thank you
SI 2015 @ WIN7-64

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

Re: get texture script

Post by EricTRocks » 25 Oct 2012, 14:22

You're going to have to iterate over the selection:

Code: Select all

for eachObj in Application.Selection:
    log(eachObj.FullName) # logs the full name of the object

You'll have to get the material from eachObj while looping over it:

Code: Select all

oMat = eachObj.Material
From that material you'll need to get the image clips used in it:

Code: Select all

collImgClips = oMat.ImageClips #returns an xsi collection, you should loop over it maybe?
from that collImgClips you'll be able to loop over that and log each value. If you're 100% sure there is only 1 image clip used then you can just pick the first one on the collection:

Code: Select all

oImgClip = collImgClips(0)
Hopefully that info will point you in the right direction. My other advice is to use Application.LogMessage() a lot and see what it prints out.
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 » 25 Oct 2012, 14:28

you're too kind. give me a second to understand your script.

as the SDK examples aren't very python friendly (unfortunately i had to) switch to VB script.
here's what i have so far:

Code: Select all

set oSelection = Application.Selection

for each oItem in oSelection
	
set oMaterial = oItem.Material

SetValue oItem.Name & ".Texture_Map.ImageClipName", oMaterial.CurrentImageClip

next
p.s.:my script doesn't work so i will continue with your suggestion and python(!)

Code: Select all

' ERROR : Variable uses an Automation type not supported in VBScript: 'SetValue' - [line 11]
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, 14:50

if i try:

Code: Select all

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

Code: Select all

# NameError: name 'log' is not defined
so another try with VB: the script runs with no error. but nothing happens?!

Code: Select all

set oSelection = Application.Selection

for each oItem in oSelection
	
set oMaterial = oItem.Material

SetValue oItem.Name & ".Texture_Map.ImageClipName", "oMaterial.CurrentImageClip"

next
SI 2015 @ WIN7-64

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

Re: get texture script

Post by Letterbox » 25 Oct 2012, 14:54

Carry on with what your doing, but there might be a much nicer way.... i'm working on it now, when/if done, I'll post it up.

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

Re: get texture script

Post by caledonian_tartan » 25 Oct 2012, 15:09

hi letterbox
thank you. really looking forward to your solution.

i noticed that my script does indeed change the texture map image. but i changes it to the noIcon_pic...

also it logs:

Code: Select all

SetValue "sphere.Texture_Map.ImageClipName", "oMaterial.CurrentImageClip"
but it should be:

Code: Select all

SetValue "sphere.Texture_Map.ImageClipName", "Clips.Engines_jpg"
if i do

Code: Select all

LogMessage oMaterial.CurrentImageClip
it logs

Code: Select all

Clips.Engines_jpg
which is what i want, but in the context of the script it doesn't work.
somehow...
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, 15:15

Here's a hint.

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

Application.SelectObj("SomeMeshWithAnImageAndATextureMap", "", "")

o = si.Selection(0)
mat = o.Materials(0)
i = mat.ImageClips(0)
txmap = o.LocalProperties.Filter("TextureProp")(0)
txmap.Parameters("ImageClipName").Value = i.Name
I often start by writing a snippet like this, and then I generalize it (and add error checking).
// 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, 15:31

hi and thanks steve

how can i do the following in python?

VB example:

Code: Select all

SetValue oItem.Name & ".Texture_Map.ImageClipName", "oMaterial.CurrentImageClip"
(it's the [ & ] i'm interested in...)


i try to adapt your parameters into

Code: Select all

Application.SetValue("sphere.Texture_Map.ImageClipName", "Clips.Engines_jpg", "")


that's my suggestion, but i doesn't seem to work:

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

for eachObj in o:
Application.SetValue "i", "Clips" + i.Name, "")
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: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

Post Reply

Who is online

Users browsing this forum: No registered users and 29 guests