Forum: Poser Python Scripting


Subject: Poser Readscript - weird behavior.

Xameva opened this issue on Jul 11, 2012 · 3 posts


Xameva posted Wed, 11 July 2012 at 7:36 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:

 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