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


3dcheapskate posted Fri, 12 January 2024 at 1:45 AM

This is  a simple crappy cobbled together Poser 11 Python 2 script, one of four, from something I'm playing with over on the HiveWire3D forum here, post #66 - Towards better grass in Poser... | Page 4 | HiveWire 3D Community - and I'd like to get it working in Poser 12+ Python 3 too

1) Since I only have Poser 11 I can't test any changes I make to it

2) I don't really want to import compatibility libraries if I can do it without.

3) I know that I need to include brackets in my print "stuff" statements, thusly print ( "stuff" ) to get them to workin both Python 2 and 3

4) The try...except version stuff can go - that's a bit I forgot to delete from the source scrpt that I bashed about

5) Ideally I want one script that works in both Poser 11 and Poser 12+


P.S. Don't forget to put on your peril-sensitive sunglasses before looking at the 'code' ;o)


# 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

act = curfig.ActorByInternalName("BODY")

act.Parameter("Geometry Variant").SetValue(0)

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)

act = curfig.ActorByInternalName(bone)

act.Parameter(bone+"_variants").SetValue(randgeom)

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.")



Footnote: code above cut-and-pasted from NotePad++ after changing EOLs to just LF. Also attempting to add RandomizeHexGeometries.txt to this post below




The 3Dcheapskate* occasionally posts sensible stuff. Usually by accident.
And it usually uses Poser 11, with units set to inches. Except when it's using Poser 6 or PP2014, or when its units are set to PNU.

*also available in ShareCG, DAZ, and HiveWire3D flavours (the DeviantArt and CGBytes flavour have been discontinued).