Forum: Poser Python Scripting


Subject: What changes are needed to get this to work in Poser 12+ ?

3dcheapskate opened this issue on Jan 12, 2024 ยท 9 posts


Y-Phil posted Sun, 14 January 2024 at 2:39 PM

I had to add two "try: except:" blocs, probably because I didn't used your script the right way, but as is, it works with Poser11 and Poser13
The key is the very first line, and indeed the use of print(...) even with Poser11.

from __future__ import print_function

# RandomizeHexGeometries.py (Prototype 0.00)
# Test script for adding Ajax Easypose style ERC to a figure.
# 0.00:

import poser,random


# I put my scripts into a class simply to avoid possible conflict with stuff in the __main__ module.

class cheapskatesTemporaryClass(object):
    def main(self):
        # Get Poser version for doing version-specific stuff
        poserversion = '0'
        posermainversion = '0'
        try:
            self.poserversion = poser.AppVersion()
            temp = self.poserversion.split('.')
            self.posermainversion = temp[0]
        except:
            pass

        # Abort if the user gets cold feet right at the start
        confirmed = poser.DialogSimple.YesNo("This script randomizes hex geometries.\n\nDo you wish to continue?")
        if not confirmed:
            confirmed = poser.DialogSimple.YesNo("Do you want to see more information about what this script does?\n\n(This opens a debug window with extra information and terminates the script. You'll probably need to resize the debug window to read the information.)")
            if confirmed:
                # Briefly explain to the user what this script does and give an option toabort straight away
                print("This script randomizes hex geometries... MORE EXPLANATION TO GO HERE")
            return

        # Abort if no figure selected
        scn = poser.Scene()
        curfig = scn.CurrentFigure()
        curact = scn.CurrentActor()
        if not curfig:
            poser.DialogSimple.MessageBox("You need to have a figure selected for this script to do anything.\n\nScript aborted, no changes made.")
            return

        # Abort if the currently selected actor is NOT part of the figure (parented props are NOT part of the figure)
        if not(curact.IsBodyPart() and curact.ItsFigure().Name()==curfig.Name()):
            poser.DialogSimple.MessageBox("The selected actor is not an integral part of the selected figure.\n\nScript aborted, no changes made.")
            return


        # Let user select random grass or bump geometries
        confirm1=poser.DialogSimple.YesNo("Set random geometry for each hex?")
        if confirm1:
            fromgrass = 1
            tograss = 10
            grassMenu = ["All grass (01-10)","Just old grass (01-05)","Just new grass (06-10)"]
            sel = poser.DialogSimple.AskMenu('Subset only ?','Select subset range:',grassMenu)
            if sel == grassMenu[0]:
                fromgrass = 1
                tograss = 5
            elif sel == grassMenu[1]:
                fromgrass = 1
                tograss = 5
            elif sel == grassMenu[2]:
                fromgrass = 6
                tograss = 10

            # Reset the master geometry variant in the body
            try:
                act = curfig.ActorByInternalName("BODY")
                act.Parameter("Geometry Variant").SetValue(0)
            except:
                pass
            print("Master geometry variant reset to 0")

            # Randomize the geometry variants for each bone
            i = 1
            while i < 38:
                if i < 10:
                    bone = "subhex0" + str(i)
                else:
                    bone = "subhex" + str(i)
                randgeom = random.randint(fromgrass,tograss)
                print(bone + " geometry set to " + str(randgeom))
                try:
                    act = curfig.ActorByInternalName(bone)
                    act.Parameter(bone+"_variants").SetValue(randgeom)
                except:
                    pass
                i = i + 1

        # Redraw what we've modified    
        scn.Draw()

        # Inform the user that it's all done
        poser.DialogSimple.MessageBox("All done")

poser.DialogSimple.MessageBox("Running 3DCheapskates RandomizeHexGeometries.py script (prototype 0.00)\n\n(N.B. You should see a similar message when the script finishes. If you don't then the script has crashed!)")
cheapskatesTemporaryInstance = cheapskatesTemporaryClass()
cheapskatesTemporaryInstance.main()

poser.DialogSimple.MessageBox("3DCheapskates RandomizeHexGeometries.py script (prototype 0.00) all done.")

๐’ซ๐’ฝ๐“Ž๐“


(ใฃโ—”โ—กโ—”)ใฃ

๐Ÿ‘ฟ Win11 on i9-13900K@5GHz, 64GB, RoG Strix B760F Gamng, Asus Tuf Gaming RTX 4070 OC Edition, 1 TB SSD, 6+4+8TB HD
๐Ÿ‘ฟ Mac Mini M2, Sonoma 14.6.1, 16GB, 500GB SSD
๐Ÿ‘ฟ Nas 10TB
๐Ÿ‘ฟ Poser 13 and soon 14 โค๏ธ