It is currently 18 Apr 2014, 17:39

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: get texture script
PostPosted: 25 Oct 2012, 13:23 
Offline

Joined: 17 Feb 2010, 16:13
Posts: 209
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 2014 SP1 @ WIN7-64


Top
 Profile  
 
 Post subject: Re: get texture script
PostPosted: 25 Oct 2012, 13:47 
Offline
Moderator
User avatar

Joined: 25 Nov 2009, 02:41
Posts: 666
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:
http://www.si-community.com/community/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
ethivierge@gmail.com
http://www.ethivierge.com
http://www.exocortex.com/products/species/


Top
 Profile  
 
 Post subject: Re: get texture script
PostPosted: 25 Oct 2012, 14:05 
Offline

Joined: 17 Feb 2010, 16:13
Posts: 209
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:
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:
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 2014 SP1 @ WIN7-64


Top
 Profile  
 
 Post subject: Re: get texture script
PostPosted: 25 Oct 2012, 14:22 
Offline
Moderator
User avatar

Joined: 25 Nov 2009, 02:41
Posts: 666
You're going to have to iterate over the selection:

Code:
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:
oMat = eachObj.Material


From that material you'll need to get the image clips used in it:
Code:
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:
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
ethivierge@gmail.com
http://www.ethivierge.com
http://www.exocortex.com/products/species/


Top
 Profile  
 
 Post subject: Re: get texture script
PostPosted: 25 Oct 2012, 14:28 
Offline

Joined: 17 Feb 2010, 16:13
Posts: 209
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:
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:
' ERROR : Variable uses an Automation type not supported in VBScript: 'SetValue' - [line 11]

_________________
SI 2014 SP1 @ WIN7-64


Top
 Profile  
 
 Post subject: Re: get texture script
PostPosted: 25 Oct 2012, 14:50 
Offline

Joined: 17 Feb 2010, 16:13
Posts: 209
if i try:
Code:
for eachObj in Application.Selection:
    log(eachObj.FullName)

i get
Code:
# NameError: name 'log' is not defined


so another try with VB: the script runs with no error. but nothing happens?!
Code:
set oSelection = Application.Selection

for each oItem in oSelection
   
set oMaterial = oItem.Material

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

next

_________________
SI 2014 SP1 @ WIN7-64


Top
 Profile  
 
 Post subject: Re: get texture script
PostPosted: 25 Oct 2012, 14:54 
Offline

Joined: 17 Jun 2009, 14:49
Posts: 391
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.


Top
 Profile  
 
 Post subject: Re: get texture script
PostPosted: 25 Oct 2012, 15:09 
Offline

Joined: 17 Feb 2010, 16:13
Posts: 209
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:
SetValue "sphere.Texture_Map.ImageClipName", "oMaterial.CurrentImageClip"

but it should be:
Code:
SetValue "sphere.Texture_Map.ImageClipName", "Clips.Engines_jpg"


if i do
Code:
LogMessage oMaterial.CurrentImageClip

it logs
Code:
Clips.Engines_jpg

which is what i want, but in the context of the script it doesn't work.
somehow...

_________________
SI 2014 SP1 @ WIN7-64


Top
 Profile  
 
 Post subject: Re: get texture script
PostPosted: 25 Oct 2012, 15:15 
Offline
User avatar

Joined: 09 Jun 2009, 11:02
Posts: 677
Location: Montreal Canada
Here's a hint.
Code:
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


Top
 Profile  
 
 Post subject: Re: get texture script
PostPosted: 25 Oct 2012, 15:31 
Offline

Joined: 17 Feb 2010, 16:13
Posts: 209
hi and thanks steve

how can i do the following in python?

VB example:

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


(it's the [ & ] i'm interested in...)


i try to adapt your parameters into

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




that's my suggestion, but i doesn't seem to work:
Code:
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 2014 SP1 @ WIN7-64


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group