Mon, Jan 6, 10:47 PM CST

Renderosity Forums / Poser Python Scripting



Welcome to the Poser Python Scripting Forum

Forum Moderators: Staff

Poser Python Scripting F.A.Q (Last Updated: 2024 Dec 02 3:16 pm)

We now have a ProPack Section in the Poser FreeStuff.
Check out the new Poser Python Wish List thread. If you have an idea for a script, jot it down and maybe someone can write it. If you're looking to write a script, check out this thread for useful suggestions.

Also, check out the official Python site for interpreters, sample code, applications, cool links and debuggers. This is THE central site for Python.

You can now attach text files to your posts to pass around scripts. Just attach the script as a txt file like you would a jpg or gif. Since the forum will use a random name for the file in the link, you should give instructions on what the file name should be and where to install it. Its a good idea to usually put that info right in the script file as well.

Checkout the Renderosity MarketPlace - Your source for digital art content!



Subject: Possible P6 python bug


face_off ( ) posted Mon, 28 March 2005 at 10:20 PM ยท edited Fri, 29 November 2024 at 2:10 AM

Hi All A couple of times now I've had a python script which works in P5 fall over on the following statement in P6 print "ActorName = " + str(poser.Scene().CurrentActor().Name()) If I restart P6, the script then runs ok! I've had someone else report the issue to me too. If I remove the "str()" part, it also works. Has anyone else noticed this?

Creator of PoserPhysics
Creator of OctaneRender for Poser
Blog
Facebook


jeffg3 ( ) posted Tue, 29 March 2005 at 12:36 AM

I believe I've seen it. Very occasionally I'll see it when running your Hyper-real in P6. I've had to do the same thing - quite and restart P6. Seems like the error message was a bit longer though.


face_off ( ) posted Tue, 29 March 2005 at 2:04 AM

Thanks Jeff. What a bummer. Once I catch the full error msg, I'll report it to CL.

Creator of PoserPhysics
Creator of OctaneRender for Poser
Blog
Facebook


an0malaus ( ) posted Tue, 29 March 2005 at 6:29 AM

Any chance that CurrentActor() is returning None, as in nothing selected? You might need to debug it by assigning the function calls to intermediate variables and printing them out. Assuming, of course, that doing so doesn't make the problem vanish ;-) Also, if you're doing a print, it should be able to handle the form: print "ActorName = ", poser.Scene().CurrentActor().Name() without the str() evaluation and string catenation. print can print tuples and dictionaries as well as functions evaluating to None. The inherent assumption (regardless of whether it's a P6 bug or not) of the combined statement is that none of the Scene(), CurrentActor() or Name() evaluations is going to return something that can't be evaluated by the next bit to be parsed - i.e. can't evaluate Name() method if CurrentActor() instance returns None.



My ShareCG Stuff

Verbosity: Profusely promulgating Graham's number epics of complete and utter verbiage by the metric monkey barrel.


stewer ( ) posted Tue, 29 March 2005 at 8:09 AM

In any case, it'd be much safer to check if you really get an object before trying to call methods:

scene = poser.Scene()<br></br>if (scene != None):<br></br>    actor = scene.CurrentActor()<br></br>    if (actor != None):<br></br>        print actor.Name()<br></br>

Python doesn't like it if you try to call functions of a None object.


an0malaus ( ) posted Tue, 29 March 2005 at 8:20 AM

Thanks stewer :-) A code sample is, as usual, the most concise way of illustrating the point I was trying to make: Check before assuming.



My ShareCG Stuff

Verbosity: Profusely promulgating Graham's number epics of complete and utter verbiage by the metric monkey barrel.


svdl ( ) posted Tue, 29 March 2005 at 1:14 PM

I often use Python exception handling for cases like this:

try:
print poser.Scene().CurrentActor().Name()
except:
print "No actor selected!"

The pen is mightier than the sword. But if you literally want to have some impact, use a typewriter

My galleryย ย ย My freestuff


face_off ( ) posted Tue, 29 March 2005 at 2:16 PM

Thanks for all the comments guys.... Stewer/svdl, my code already establishes that the scene and current actor are != None. The code is failing with a valid actor. In fact the code fails on... print str("hello") So it appears to be the str() function which is somehow becoming corrupted in the P6 session. The issue I've got is that there are a lot of people out there using scripts which have the str(...Name()) coding, and which ALWAYS work on P5. I agree that there is a work-around to remove the str() function - but that doesn't help if I want to convert a numeric to a string. The strange thing is that it works 99% of the time on P6 - it's just the 1% of times that it doesn't work, and you need to restart P6. So obviously there is something in there that is not right.

Creator of PoserPhysics
Creator of OctaneRender for Poser
Blog
Facebook


svdl ( ) posted Tue, 29 March 2005 at 2:21 PM

Oops. It usually works fine and sometimes crashes. No discernible pattern, right? Then it sounds like a memory management error in the C/C++ code. Very ugly bug, very hard to track down.

The pen is mightier than the sword. But if you literally want to have some impact, use a typewriter

My galleryย ย ย My freestuff


PoseWorks ( ) posted Thu, 31 March 2005 at 6:08 PM

I prefer using repr(x) for doing convert-to-string operations (just in case str is truly broken, it's a good alternative). Have you tried using str(x)? This will bypass anything that the rest of your code may have done to muck up str.


face_off ( ) posted Thu, 31 March 2005 at 6:26 PM

Thanks for the suggetions PoseWorks. I'd rather the bug was fixed than code around it! But if not, I'll look at your suggestions. Haven't tried str before - will check it out.

Creator of PoserPhysics
Creator of OctaneRender for Poser
Blog
Facebook


face_off ( ) posted Thu, 31 March 2005 at 7:27 PM

OK - i just got the problem again - and doing a File->Reinitialize Python fixed it. PoseWorks - I tried str but it couldn't find the method. I assume I need to input a particular library?

Creator of PoserPhysics
Creator of OctaneRender for Poser
Blog
Facebook


PoseWorks ( ) posted Fri, 01 April 2005 at 5:11 PM

Putting double underscores around some core Python functions will override any changes you may have accidently made, looks like it doesn't work with str though :-/


face_off ( ) posted Fri, 01 April 2005 at 9:48 PM

OK, I can now reproduce the error 100% of the time. Do the following: Start Poser With JamesCasual, run the SSS Wacro in the material room Then run a python script that simply contains the line print str(1) You should get the erro Traceback (most recent call last): File "", line 1, in ? TypeError: 'str' object is not callable Doing a File->Reinitialise Python will fix it (so the print str(1) actually prints 1. Is anyone else able to reproduce the error using the above sequence?

Creator of PoserPhysics
Creator of OctaneRender for Poser
Blog
Facebook


nruddock ( ) posted Fri, 01 April 2005 at 9:54 PM

Just taken a look at the Wacro.

It is using a global variable "str", so this will be overriding the function definition, which is why resetting cures the problem.

Try changing the variable in the Wacro and see if the problem goes away.


face_off ( ) posted Fri, 01 April 2005 at 9:58 PM

Yep nruddock - that fixed it - fantastic. Thanks so much.

Creator of PoserPhysics
Creator of OctaneRender for Poser
Blog
Facebook


nruddock ( ) posted Fri, 01 April 2005 at 10:03 PM

You can fix your scripts by adding the line

from __builtin__ import str

which will bring the function back into scope.


face_off ( ) posted Fri, 01 April 2005 at 10:28 PM

Good point. Although better to fix the source of the problem, than code work-arounds. I've reported the problem to CL.

Creator of PoserPhysics
Creator of OctaneRender for Poser
Blog
Facebook


nruddock ( ) posted Fri, 01 April 2005 at 10:34 PM

I bet you get your update out before they do.
You should ask to them to let you supply a fixed copy of the Wacro to your P6 customers.


face_off ( ) posted Fri, 01 April 2005 at 10:50 PM ยท edited Fri, 01 April 2005 at 10:50 PM

Attached Link: http://www.users.on.net/~pkinnane/P6%20Shader%20Compatibility.html

The fix is detailed at the above link.

And again, nruddock, thanks a heap for the help on this. I've been getting the problem (and reports of it) for over a week and just couldn't work it out!

Message edited on: 04/01/2005 22:50

Creator of PoserPhysics
Creator of OctaneRender for Poser
Blog
Facebook


nruddock ( ) posted Fri, 01 April 2005 at 11:06 PM

I'd been following the thread, but until you whittled it down to using that Wacro, it could have been (almost) anything.

"setLightStyle.py" has the same problem.

The simplest way of curing it would be to move the lines that do the actual work into a subroutine and call that like most of the other Wacros do.

One thought, getting people to edit their copy of the Wacro might cause problems when CL release an updater if it checks file timestamps or sizes.


face_off ( ) posted Fri, 01 April 2005 at 11:10 PM

Mmmmm, good point. I'll check it out.....

Creator of PoserPhysics
Creator of OctaneRender for Poser
Blog
Facebook


Privacy Notice

This site uses cookies to deliver the best experience. Our own cookies make user accounts and other features possible. Third-party cookies are used to display relevant ads and to analyze how Renderosity is used. By using our site, you acknowledge that you have read and understood our Terms of Service, including our Cookie Policy and our Privacy Policy.