Thu, Dec 12, 12:25 PM CST

Renderosity Forums / Poser - OFFICIAL



Welcome to the Poser - OFFICIAL Forum

Forum Coordinators: RedPhantom

Poser - OFFICIAL F.A.Q (Last Updated: 2024 Dec 12 3:30 am)



Subject: Poser file name via Python


3doutlaw ( ) posted Wed, 26 June 2013 at 3:25 PM · edited Thu, 12 December 2024 at 10:01 AM

I asked this somewhere before, but I cant find it.

In P9/2012 I had looked for a Python way to get the active Poser file name, but could not find any way to do it?

I was wondering if someone found (or knew) a way to do this, or if there is anything new in the 10/2014 realm that this has been added?


markschum ( ) posted Wed, 26 June 2013 at 5:09 PM

the name of the loaded pz3 was not available.

A workaround was to use a load script that would add the filename to a parameter in some scene object.


ockham ( ) posted Wed, 26 June 2013 at 5:53 PM

Horrible but practical workaround: 

You could save the scene [poser.SaveDocument()] and then look at the files on disk to see which PZ3 had the most recent modification date!

If you only need to KNOW what the name is, not to find it among other existing PZ3s, you can do SaveDocument() with a specified name then reload the specified name.

poser.SaveDocument("ThisIsKnownFileName.PZ3")

poser.OpenDocument("ThisIsKnownFileName.PZ3")

My python page
My ShareCG freebies


ockham ( ) posted Wed, 26 June 2013 at 7:52 PM

Here's the horrible workaround, which I couldn't resist writing.  I'd wanted the same function at some point for reasons long forgotten. 

It fetches the hour, minute and second of time just before saving the PZ3; then saves the PZ3; then checks the files in a specified folder to see which one is equal or newer than the first time.

Note that basedir is a hard-wired runtime location on my disk, and won't work on yours.  Fill in your own base directory.  You could use os.walk to search a wider range, but that tends to take a long time; better to restrict the search.

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

import os
import poser
import time
import glob

TimeTuple = time.localtime(time.time())
OldH=TimeTuple[3]
OldM=TimeTuple[4]
OldS=TimeTuple[5]

poser.SaveDocument()

basedir="c:PoserProductsGrapher" # Fill in your own base runtime

FileList=glob.glob(os.path.join(basedir,'runtime','libraries','scene','*.PZ3'))

for file in FileList:
    stats = os.stat(file)
    TimeTuple = time.localtime(stats[8])
    NewH=TimeTuple[3]
    NewM=TimeTuple[4]
    NewS=TimeTuple[5]
    if (NewH >= OldH) and (NewM >= OldM) and (NewS >= OldS):
        print file
        break

end file loop

My python page
My ShareCG freebies


3doutlaw ( ) posted Wed, 26 June 2013 at 8:46 PM

Thanks ockham, but I fear the whole time-based thing, though you are a master for figuring that out.  I've been googling and testing a while now, and I think I came up with a good option.

It basically runs through the open windows, looking for one with "Smith Micro Poser" in the window title, then removes that part of the string.  This would work as long as there is only one Poser window open, that has "Smith Micro Poser" in the window title.

Here is the link that got me there...

        EnumWindows = ctypes.windll.user32.EnumWindows
        EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int))
        GetWindowText = ctypes.windll.user32.GetWindowTextW
        GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW
        IsWindowVisible = ctypes.windll.user32.IsWindowVisible
 
        global windowtitle
        def foreach_window(hwnd, lParam):
            if IsWindowVisible(hwnd):
                length = GetWindowTextLength(hwnd)
                buff = ctypes.create_unicode_buffer(length + 1)
                GetWindowText(hwnd, buff, length + 1)
                if "Smith Micro Poser" in buff.value:
                                    windowtitle = buff.value
                                    print windowtitle[:-20]
            return True
        EnumWindows(EnumWindowsProc(foreach_window), 0)


ockham ( ) posted Wed, 26 June 2013 at 9:16 PM

Very clever!  The Ctypes stuff wasn't part of the standard Poser Python setup in P7, so I never got accustomed to using it.  I see it's part of the setup now in 9.

My python page
My ShareCG freebies


3doutlaw ( ) posted Wed, 26 June 2013 at 9:19 PM

Thanks, I think this is beneficial to all, and both methods could be used depending on the application.  I gotta believe there is something simpler that is there...but no one seems to know.

I think it would have been much easier if the pywin32 stuff was included, but its not.

Thanks again for the help!


ockham ( ) posted Thu, 27 June 2013 at 3:45 AM

Would have been even easier if the programmers had included a function to get the bloody name! 

A couple other things that have been needed for 14 years but never supplied:  SetNumFrames and CreateGroup.

My python page
My ShareCG freebies


3doutlaw ( ) posted Thu, 27 June 2013 at 7:46 AM

That is true!  :tongue1:


Cage ( ) posted Thu, 27 June 2013 at 2:14 PM

Quote - A couple other things that have been needed for 14 years but never supplied:  SetNumFrames and CreateGroup.

You can sort of create a group, using Poser Python.  You can create a Hair Group, which is still a common group at its core, although obviously Poser treats it differently internally.  I never tested whether a group created that way could be exported as obj.  Depending on how you need to use the group, it may or may not prove a useful workaround.

Poser Python is full of some strange and frustrating holes.  I would like to have access to mouse events in the preview window and be able to customize smoothing methods for the Morph Brush.  Let us have access to the mesh comparison methods underlying the weight and morph transfers.  Let us set rotations as quaternions.  Poser Python is great, but, man.  It could really be a lot more betterer.  :laugh:

===========================sigline======================================================

Cage can be an opinionated jerk who posts without thinking.  He apologizes for this.  He's honestly not trying to be a turkeyhead.

Cage had some freebies, compatible with Poser 11 and below.  His Python scripts were saved at archive.org, along with the rest of the Morphography site, where they were hosted.


TrekkieGrrrl ( ) posted Thu, 27 June 2013 at 5:38 PM

In PP2014 you can make groups. As far as I can tell (only tried it once to sorta test it) it works like the old hierachy grouping. But I MAY have done it the wrong way.

So perhaps Python also has a way of accessing that?

FREEBIES! | My Gallery | My Store | My FB | Tumblr |
You just can't put the words "Poserites" and "happy" in the same sentence - didn't you know that? LaurieA
  Using Poser since 2002. Currently at Version 11.1 - Win 10.



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.