Forum: Poser Python Scripting


Subject: Renaming materials in Poser

flyerx opened this issue on Jan 25, 2003 ยท 5 posts


flyerx posted Sat, 25 January 2003 at 6:16 PM

Hello, Because of Poser's broken OBJ export functionality. I have been trying to make a script to rename the material names in a scene. As a trial I tried to first list all the material names in the scene but it keeps giving me syntax error. Here is the text of the scritp: import poser scene = poser.Scene() for actor in scene.Actors(): materials = actor.Materials() for material in materials: print material.Name() Here is the error: File "", line 6 print material.Name() ^ SyntaxError: invalid syntax I tried to store the material.Name() value into a string variable and print it but it showed the same error. Oddly if I add a carriage return at the end of the file a different error shows: Preview Traceback (innermost last): File "", line 5, in ? TypeError: loop over non-sequence This is not really encouraging. So much for easy to use phyton. If anynone knows what the source of the error is I would appreciate any hints. I am using Poser Pro Pack with SR3 FlyerX


flyerx posted Sat, 25 January 2003 at 6:17 PM

the above post had tabs in the loops.


ockham posted Sat, 25 January 2003 at 10:37 PM

I tried it, with some extra printing to see where the problem was happening, and I think the problem is some Actors (specifically the Lights, but probably others as well) have no materials. So when you try to loop over Materials(), you get errors when you run into such actors. Quick fix: import poser scene = poser.Scene() for actor in scene.Actors(): ~try: ~~for onemat in actor.Materials(): ~~~print onemat.Name() ~except: ~~pass (The tildes substitute for tabs.)

My python page
My ShareCG freebies


flyerx posted Sat, 25 January 2003 at 11:28 PM

thanks for the info. That works. Unfortunately It seems that I cannot rename materials without creating new ones. I am using poly.SetMaterialName(newmatname) but this method creates a new material instead of renaming the material. I tried material.Name(newmatname) and that did not have any effect. Maybe if I use SetMaterialName() and copy the material properties to the new material but that is rather cumbersome way of doing it. FlyerX


ockham posted Sun, 26 January 2003 at 9:11 AM

That sounds about right. The Python connection to Materials is skimpy at best; many of the actions that "ought" to be there are not there! So don't expect things to work the easy way in this department.

My python page
My ShareCG freebies