PDA

View Full Version : Problem: how to Skip Objects with no TXT Projection


Loki
03-28-2008, 04:25 PM
Hi All,

How can I set an "if" condition to skip objects with no Texture Projection?

I made this script that turns on the UVW Wrapping in the Texture Projections of selected objects...


Selection = Application.GetValue("SelectionList")
for obj in Application.Selection :
oObjName = obj.name
Application.SelectObj(oObjName)
oSel = Application.Selection(0).Material.CurrentUV.FullNa me
Application.SetValue(oSel + ".Texture_Projection_Def.wrap_u", 1, "")
Application.SetValue(oSel + ".Texture_Projection_Def.wrap_v", 1, "")
Application.SetValue(oSel + ".Texture_Projection_Def.wrap_w", 1, "")
Application.SelectObj(Selection)




But if an object has no Texture Projection, the script crashes with errors.
How can I set an "if" condition to skip objects with no Texture Projection?

Julian Johnson
03-29-2008, 05:11 AM
This way will do what you want but only works if the Material has an image shader attached (i.e. Material.CurrentUV won't work if you have a projection but no image node in the tree):

oSel = Application.Selection
for oObj in oSel:
try:
for x in oObj.Material.CurrentUV.NestedObjects:
if x.Type == "uvprojdef":
x.wrap_u = 1
x.wrap_v = 1
x.wrap_w = 1
except AttributeError:
passThis should work in all circumstances:

oSel = Application.Selection
oDefs = Application.FindObjects("","{C27897E0-1B97-11D4-AE61-00A0C96E63E1}")
for x in oDefs:
if oSel(x.Parent3DObject.Name):
x.wrap_u = 1
x.wrap_v = 1
x.wrap_w = 1The latter just collects all Texture_Projection_Defs in the scene and then iterates through each one to check if it belongs to one of your selected objects. If it does, it sets the wrap parameters..

Loki
04-02-2008, 03:51 PM
Thanks Julian for your help. It works perfectly!