Forum: Poser Python Scripting


Subject: I can't get this script to apply to all materials (Please help!)

destro75 opened this issue on Jun 01, 2006 · 3 posts


destro75 posted Thu, 01 June 2006 at 5:57 AM

Hey all,

I have no idea why I can't get this script to apply to all materials in the scene. Am I missing something here? I tried running it through the User Defined button in the Wacros in the Mat Room (holding Shift while clicking, and not holding Shift.) I also tried running it through the Run Python Script option in the File menu. Any help is appreciated.

import poser

print "Starting Script"

scene  = poser.Scene()
mats  = scene.WacroMaterials()
OutlineVal = 0.00001

for mat in mats:
 tree  = mat.ShaderTree()
 
 iNodes  = tree.NumNodes()
 iCurrent = 0
 
 while (iCurrent < iNodes):
  WorkNode = tree.Node(iCurrent)
  
  print "%s" % (WorkNode.Name(),)
  
  if (WorkNode.Type() == poser.kNodeTypeCodeTOON):
   WorkNode.Input(4).SetFloat(OutlineVal)
   print "   Node Set: %f" % (OutlineVal,)
   
  iCurrent += 1
  
 tree.UpdatePreview()
 
scene.SetCurrentRenderEngine(poser.kRenderEngineCodeFIREFLY)
renderoptions = scene.CurrentFireFlyOptions()
renderoptions.SetDrawToonOutline(1)
renderoptions.SetToonOutlineStyle(poser.kOutlineCodeTHINPEN)

print "Done"

Thanks in advance!

Lou


nruddock posted Thu, 01 June 2006 at 2:34 PM

Shift-click to apply to all materials, only works from the Wacro buttons in the material room, not the drop down list that "User Defined" gives.

When you run it from the File menu, scene.WacroMaterials() contains the set of materials that your last action in the Material room worked on (i.e. it's a "sticky" list).

If you look at the scripts I wrote to apply things to all materials, you'll see the required construction.
Because the list scene.WacroMaterials() returns is sticky, there is no logic that will distinguish whether a script is being run from the Wacro buttons or the file menu, so if you need it to run on on one or all materials, you must assign it to a Wacro button.


destro75 posted Thu, 01 June 2006 at 6:32 PM

Okay cool. I fixed it.

import poser

print "Starting Script"

scene  = poser.Scene()
OutlineVal = 0.00001

figs  = scene.Figures()

for fig in figs:
 mats  = fig.Materials()

 for mat in mats:
  tree  = mat.ShaderTree()
  
  iNodes  = tree.NumNodes()
  iCurrent = 0
  
  while (iCurrent < iNodes):
   WorkNode = tree.Node(iCurrent)
   
   print "%s" % (WorkNode.Name(),)
   
   if (WorkNode.Type() == poser.kNodeTypeCodeTOON):
    WorkNode.Input(4).SetFloat(OutlineVal)
    print "   Node Set: %f" % (OutlineVal,)
    
   iCurrent += 1
   
  tree.UpdatePreview()
 
scene.SetCurrentRenderEngine(poser.kRenderEngineCodeFIREFLY)
renderoptions = scene.CurrentFireFlyOptions()
renderoptions.SetDrawToonOutline(1)
renderoptions.SetToonOutlineStyle(poser.kOutlineCodeTHINPEN)

print "Done"

Now it scrolls through all materials on all figures. I had a nagging feeling this morning that this might be the case. I should have listened to my instincts. Anyway, thanks for the help!

Lou