Thu, Nov 14, 3:40 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 Sep 18 2:50 am)

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: Poser Readscript - weird behavior.


Xameva ( ) posted Wed, 11 July 2012 at 7:36 AM · edited Wed, 06 November 2024 at 4:41 AM

 Hi! I'm hoping someone can help me.

 I'm having trouble with what I thought would be a simple task. I'm a co-creator of the 'Perfect Fixes', and I'm trying to create an "Inject All" pose that injects all of the fixes at once.

 We've created a script with a graphic interface that lets you select what fixes you want to load, and it works great! But unfortunately it doesn't work in older poser versions, and we also just want a basic one-click pose solution to load every fix - for newer Poser users too... for those afraid of scripts. This is where the problem comes in:

 I created a simple readscript script (set-up copied from Morphs++ INJ) that calls upon all the fixes. It loads them all fine, and in DAZ Studio and Poser 7 Pro everything works perfectly. But in newer Poser versions, (tested in 2010, 2012) - the fixes load in fine, but some of the fixes are bugged, while others are not. It's very strange.

 I asked a script friend (the one who created the GUI script that works perfectly) to edit the working script to a stripped down version that has no GUI and loads all of the fixes at once. He did so, and the result is the same as the readscript - bugged. Here is the code for his script:

========

FILES_TO_LOAD_PREFIX = "!inj perfectp ";

import poser
import os.path
import time

myPath = os.path.dirname(os.path.realpath(sys.argv[0]))

XamDict = dict()
for dirname, dirnames, filenames in os.walk(myPath):
    for filename in filenames:
        lfn = filename.lower()
        if (lfn.endswith(".pz2") and lfn.startswith(FILES_TO_LOAD_PREFIX)):
            ufn = filename[ len(FILES_TO_LOAD_PREFIX) : len(filename)-4 ]
            XamDict[ufn] = os.path.join(dirname, filename)

for n in XamDict.values():
    print "Loading " + n
    poser.Scene().LoadLibraryPose( n )
    poser.Scene().ProcessSomeEvents(5)
    poser.Scene().DrawAll()
    #poser.Scene().Draw()

poser.DialogSimple.MessageBox( "Fixes loaded.  Click X at top-right to close window." ) 

=============

 From what I can see when loading the fixes with the above script which bugs the fixes, vs the working GUI script, the difference is:

  • Working script: while loading the fixes, it shows a "loading" symbol instead of a mouse clicker, then changes to the mouse click symbol every half second. It does this 10 times (for 10 fixes)

  • Bugged script: while loading the fixes, it shows a "loading" symbol the entire time, and loads much quicker.

 Here's the working GUI script code by the way:

==========

import poser
import wx
import wx.aui
import os.path
import pickle

this is used with a lower-cased string, so must be all lowercase

FILES_TO_LOAD_PREFIX = "!inj perfectp ";

class XamScriptsWindow(wx.Panel):

    def init( self, parent, title, pane ):
        wx.Panel.init ( self, parent, id = wx.ID_ANY,
                            pos = wx.DefaultPosition,
                            size = wx.Size( 439,399 ),
                            style = wx.TAB_TRAVERSAL )
        
        XamSizer = wx.BoxSizer( wx.VERTICAL )

        self.XamManager = poser.WxAuiManager()
        self.XamParent = parent
        self.XamPane = pane
        
        myPath = os.path.dirname(os.path.realpath(sys.argv[0]))
        self.XamBanner = wx.StaticBitmap( self, wx.ID_ANY,
                                          wx.Bitmap( os.path.join(myPath, u"InjectFixesPoser-banner.jpg"), wx.BITMAP_TYPE_ANY ),
                                          wx.DefaultPosition, wx.DefaultSize, 0 )
        XamSizer.Add( self.XamBanner, 0, wx.ALL|wx.EXPAND|wx.FIXED_MINSIZE, 5 )

        self.XamDict = dict()
        for dirname, dirnames, filenames in os.walk(myPath):
            for filename in filenames:
                lfn = filename.lower()
                if (lfn.endswith(".pz2") and lfn.startswith(FILES_TO_LOAD_PREFIX)):
                    ufn = filename[ len(FILES_TO_LOAD_PREFIX) : len(filename)-4 ]
                    self.XamDict[ufn] = os.path.join(dirname, filename)
        
        XamListChoices = self.XamDict.keys()
        self.XamList = wx.ListBox( self, wx.ID_ANY,
                                   wx.DefaultPosition, wx.DefaultSize,
                                   XamListChoices, wx.LB_EXTENDED|wx.LB_MULTIPLE )
        for i in range(self.XamList.Count):
            self.XamList.Select(i)

        XamSizer.Add( self.XamList, 1, wx.ALL|wx.EXPAND, 5 )
        
        XamButtons = wx.BoxSizer( wx.HORIZONTAL )
        XamButtons.AddSpacer( ( 0, 0), 1, wx.EXPAND, 5 )
 
        self.butLoad = wx.Button( self, wx.ID_ANY, u"Load", wx.DefaultPosition, wx.DefaultSize, 0 )
        XamButtons.Add( self.butLoad, 0, wx.ALL, 5 )
 
        XamSizer.Add( XamButtons, 0, wx.EXPAND, 5 )
 
        self.SetSizer( XamSizer )
        self.Layout()

        # Connect Events
        self.butLoad.Bind( wx.EVT_BUTTON, self.DoLoad )

    def del( self ):
        pass

    def DoLoad( self, event ):
        total = self.XamList.Count
        for i in range(total):
            if (self.XamList.IsSelected(i)):
                pfx = str(i+1) + "/" + str(total)
                #print pfx + " :Loading " + self.XamDict[ self.XamList.GetString(i) ]
                poser.Scene().LoadLibraryPose( self.XamDict[ self.XamList.GetString(i) ] )
        poser.DialogSimple.MessageBox( "Fixes loaded successfully!" )

name = "PerfectV4 Fix Loader"
man  = poser.WxAuiManager()
root = man.GetManagedWindow()

pane = wx.aui.AuiPaneInfo()
pane.Caption(name).CaptionVisible().CloseButton().Resizable().DestroyOnClose()
pane.Right().PinButton().Float()

win  = XamScriptsWindow(root, name, pane)

man.AddPane( win, pane )
#A: pane.show()
man.Update()

#----eof----

===============

 Any idea why the GUI script works properly, while readscript and the simple script do not?

 Any help would be much appreciated. :) Thanks!

 - Xameva


millighost ( ) posted Wed, 11 July 2012 at 4:24 PM

Quote - .... From what I can see when loading the fixes with the above script which bugs the fixes, vs the working GUI script, the difference is:

  • Working script: while loading the fixes, it shows a "loading" symbol instead of a mouse clicker, then changes to the mouse click symbol every half second. It does this 10 times (for 10 fixes)

  • Bugged script: while loading the fixes, it shows a "loading" symbol the entire time, and loads much quicker.

That is plausible; the first script does a complete redraw and process some events after loading any pose file:

    poser.Scene().LoadLibraryPose( n )
    poser.Scene().ProcessSomeEvents(5)
    poser.Scene().DrawAll()     # redraw (costly)

The ProcessSomeEvents(5) looks a bit strange, btw. It might lead to changing the current figure in the midst of the process. I hope you know what you are doing :-)

Not sure why the one script works, but the other does not. But what looks at least a bit dangerous:

The script relies to be in the same path as the pz2 files (probably in the Pose directory of the Library). Are these script installed in the Pose directory? Most scripts are in the Python directory, in which case Poser will start to guess on what file it tries to load; very nasty if you have multiple files with the same name in your runtimes (it can load something from any runtime if you have multiple runtimes and are unlucky). In my experience, you cannot rely on Poser giving you an error message if a file is not there. Sometimes it has an equally named file in its cache or so and instead uses that.


Xameva ( ) posted Thu, 12 July 2012 at 7:49 AM

Got it working. :)

 Thanks!


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.