get texture script
-
- Posts: 253
- Joined: 17 Feb 2010, 15:13
get texture script
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
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
-
- Moderator
- Posts: 754
- Joined: 25 Nov 2009, 01:41
- Contact:
Re: get texture script
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... - HB
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... - HB
-
- Posts: 253
- Joined: 17 Feb 2010, 15:13
Re: get texture script
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:
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:
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
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)
connect a texture to a texture map:
Code: Select all
Application.SetValue("sphere.Texture_Map.ImageClipName", "Clips.Engines_jpg", "")
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
-
- Moderator
- Posts: 754
- Joined: 25 Nov 2009, 01:41
- Contact:
Re: get texture script
You're going to have to iterate over the selection:
You'll have to get the material from eachObj while looping over it:
From that material you'll need to get the image clips used in it:
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:
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.
Code: Select all
for eachObj in Application.Selection:
log(eachObj.FullName) # logs the full name of the object
Code: Select all
oMat = eachObj.Material
Code: Select all
collImgClips = oMat.ImageClips #returns an xsi collection, you should loop over it maybe?
Code: Select all
oImgClip = collImgClips(0)
-
- Posts: 253
- Joined: 17 Feb 2010, 15:13
Re: get texture script
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:
p.s.:my script doesn't work so i will continue with your suggestion and python(!)
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
Code: Select all
' ERROR : Variable uses an Automation type not supported in VBScript: 'SetValue' - [line 11]
SI 2015 @ WIN7-64
-
- Posts: 253
- Joined: 17 Feb 2010, 15:13
Re: get texture script
if i try:
i get
so another try with VB: the script runs with no error. but nothing happens?!
Code: Select all
for eachObj in Application.Selection:
log(eachObj.FullName)
Code: Select all
# NameError: name 'log' is not defined
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
Re: get texture script
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.
-
- Posts: 253
- Joined: 17 Feb 2010, 15:13
Re: get texture script
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:
but it should be:
if i do
it logs
which is what i want, but in the context of the script it doesn't work.
somehow...
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"
Code: Select all
SetValue "sphere.Texture_Map.ImageClipName", "Clips.Engines_jpg"
Code: Select all
LogMessage oMaterial.CurrentImageClip
Code: Select all
Clips.Engines_jpg
somehow...
SI 2015 @ WIN7-64
- xsisupport
- Posts: 713
- Joined: 09 Jun 2009, 11:02
- Location: Montreal Canada
- Contact:
Re: get texture script
Here's a hint.
I often start by writing a snippet like this, and then I generalize it (and add error checking).
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
-
- Posts: 253
- Joined: 17 Feb 2010, 15:13
Re: get texture script
hi and thanks steve
how can i do the following in python?
VB example:
(it's the [ & ] i'm interested in...)
i try to adapt your parameters into
that's my suggestion, but i doesn't seem to work:
how can i do the following in python?
VB example:
Code: Select all
SetValue oItem.Name & ".Texture_Map.ImageClipName", "oMaterial.CurrentImageClip"
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
- xsisupport
- Posts: 713
- Joined: 09 Jun 2009, 11:02
- Location: Montreal Canada
- Contact:
Re: get texture script
Code: Select all
"%s.Texture_Map.ImageClipName" % oItem.Name
-
- Posts: 253
- Joined: 17 Feb 2010, 15:13
Re: get texture script
i have it working for the first selected object only:
now i should iterate over the selection, which confuses me...
PS.: as you can see i used "+". i assume this is the same as "%"
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, "")
PS.: as you can see i used "+". i assume this is the same as "%"
SI 2015 @ WIN7-64
- xsisupport
- Posts: 713
- Joined: 09 Jun 2009, 11:02
- Location: Montreal Canada
- Contact:
Re: get texture script
My snippet works on the first object in the selection ("si.Selection(0)", note the "(0)").caledonian_tartan wrote:i have it working for the first selected object only:
now i should iterate over the selection, which confuses me...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, "")
PS.: as you can see i used "+". i assume this is the same as "%"
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
My last line is setting the parameter value, but through the OM instead of with SetValue.
ciao
-
- Posts: 253
- Joined: 17 Feb 2010, 15:13
Re: get texture script
whatever i do the loop doesn't work:
in eric's version it logs 3 objects, but only one material/texture/clip.
steve's version is understandable but even with the suggested "for o in si.Selection:" it sets all texture maps to noIcon_pic
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
-
- Posts: 253
- Joined: 17 Feb 2010, 15:13
Re: get texture script
OK. It's done!
wouldn't have been possible without you guys, thanks a lot:
i just had to change
i.Name
to
"Clips." + i.Name
again, thx
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.Name
to
"Clips." + i.Name
again, thx
SI 2015 @ WIN7-64
-
- Moderator
- Posts: 754
- Joined: 25 Nov 2009, 01:41
- Contact:
Re: get texture script
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.
Who is online
Users browsing this forum: No registered users and 43 guests