Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)
from the manual
The Addon Menu
The Window > Addon menu command is provided to allow for the addition of scripts by third-party developers. Developers can find base classes and example add-ons in the Runtime/Python/addons folder.
For Further Information The preceding information was a very brief glimpse into Python and the PoserPython extensions. If you do not currently know Python, you may want to read and learn more. With the power and flexibility this interface offers, developing Python expertise would be well worth it.
To view the Poser Python Methods Manual, choose Help >PoserPython Manual from the menu commands.
Locked Out
Hello!
In my P12 Runtime/Python/addons folder I only find the file poseraddon.py and the folder PythonShell. The file init.py there is not very helpful. I am familiar with Python. I am interested in the exact structure of an addon for Poser. I know the old way for an addon in Poser. My last work and first Poser 12 Addon: P12 Script Starter The Poser Methods Manual is also not very helpful when it comes to building an addon.
Greetings Stephan
Make sure your addon details fill the requirements.
# addons must fill this dictionary
addonInfo = { 'id' : 'com.bondware.addon', # set this to a unique ID
'author' : 'Bondware, Inc', # author info
'copyright' : '(c) 2019 Bondware, Inc',
'name' : 'MyAddOn', # this is the name of your plugin that will be visible in the GUI
'version' : '1.1',
'observer' : 0, # set to 1 if your addon implements the methods from SceneObserver
'scenedata' : 0, # set to 1 if your addon implements the methods from SceneDataSaver
'prefsdata' : 0, # set to 1 if your addon implements the methods from PrefsSaver
# 'apiversion' : '1.0' # set this to the version of the addon API your addon is built for
# this defaults to 1.0 so that older scripts that did not set this field will run in 1.0 mode
# make sure to set this to the current version in your addon!
}
ensure your addon is in a poser library which is loaded on startup. Edit the poser startup file by adding the following lines:
myAddonPath = os.path.join(os.path.dirname(poser.AppLocation()), "Runtime", "Python", "PoserScripts", "myaddon", "myaddon.py")
try:
poser.ExecFile(myAddonPath)
except:
pass
the following is adapted from Snarlygribbly's AVFIX
IMPORTANT: The installation requires you to make changes in the Runtime within the folder in which you installed Poser.
Depending upon your operating system, and where you have installed Poser, you may need to perform these steps with Administrator privileges.
STEP 1
1.0 Create a folder called myFolder in the Runtime/Python/poserScripts folder ( this can also be Runtime/Python/poserScripts/ScriptsMenu )
1.1 Copy myFile.py file into myFolder
When you have done this you should have this file in your runtime:
Poser SoftwarePoser 11RuntimePythonposerScriptsmyFoldermyFile.py
STEP 2 (OPTIONAL)
Locked Out
Here is an early test class for my MQTT script for Poser. You should be able to extract the most important information to get something running.
import poser
import poseraddon
import helper
reload(helper)
#from helper import publish, disconnect, clear_callbacks, attach_callbacks,
# MQTT_PUB, MQTT_MES, MQTT_SERVER, on_message, on_connect, on_disconnect, error_string
_ADDON_ID = "de.ADP.MQTT"
_ADDON_NAME = "PoserMQTT"
helper.CURRENT_ACTOR = None
class poserMQTT(poseraddon.Addon,
poseraddon.SceneObserver,
poseraddon.PrefsSaver,
poseraddon.SceneDataSaver):
def __init__(self):
self.addonInfo["id"] = _ADDON_ID
self.addonInfo["author"] = "A::D:P"
self.addonInfo["copyright"] = "(c) 2018 ADP, Germany"
self.addonInfo["name"] = _ADDON_NAME
self.addonInfo["version"] = "1.2"
self.addonInfo["observer"] = 1
self.addonInfo["scenedata"] = 1
def load(self):
import wx
import MenuButtons
reload(MenuButtons)
try:
helper.MQTT_PUB.on_connect = helper.on_connect
helper.MQTT_PUB.on_disconnect = helper.on_disconnect
helper.MQTT_MSG.on_connect = helper.on_connect
helper.MQTT_MSG.on_disconnect = helper.on_disconnect
helper.MQTT_MSG.on_message = helper.on_message
MenuButtons.initScriptButtons()
except Exception as err:
def do():
print("Error while initializing MQTT:", err)
wx.CallLater(1000, do)
def unload(self):
helper.disconnect()
#print "MQTT UNLOADED."
def objectsAdded(self, objects):
helper.publish("Scene/Objects/added", ", ".join(obj.InternalName() for obj in objects))
helper.set_current_figure()
def objectsDeleted(self, objects):
names = [obj.InternalName() for obj in objects]
helper.publish("Scene/Objects/deleted", ", ".join(names))
helper.set_current_figure()
def objectsRenamed(self, objectsOldNames):
helper.publish("Scene/Objects/renamed", ), ", ".join(objectsOldNames)
helper.set_current_figure()
def objectsInternalRenamed(self, objectsOldInternalNames): # API V1.1 or higher
helper.publish("Scene/Objects/renamed", ", ".join(objectsOldInternalNames))
def objectSelected(self, selection):
if not helper.BUTTON_MENU.MQTT_PUB_ACTIVE:
return
ca = helper.CURRENT_ACTOR
iname = selection.InternalName()
helper.CALLBACK_PARAMS.setdefault(iname, dict())
if ca != iname:
try:
helper.set_current_figure()
except Exception as err:
pass
if ca is not None:
helper.clear_callbacks(ca)
helper.publish("Scene/CurrentActor", "%s, %s" % (iname, selection.Name()))
helper.attach_callbacks(iname)
def sceneDeleting(self, scene):
import ClassMenuButtons, MenuButtons
ClassMenuButtons.restore_buttons()
MenuButtons.initScriptButtons()
helper.CURRENT_FIGURE = None
helper.CURRENT_ACTOR = None
helper.CALLBACK_PARAMS.clear()
helper.publish("Scene", "Scene deleted.")
def sceneCreated(self, scene):
helper.publish("Scene", "Scene created.")
def frameChanged(self):
helper.publish("Scene/Frame", helper.SCENE.Frame())
def materialsChanged(self, materials):
helper.publish("Scene/Material", [mat.Name() for mat in materials])
def cameraChanged(self): # API V1.2 or higher
helper.publish("Scene/Camera", helper.SCENE.CurrentCamera().InternalName())
def lightsChanged(self): # API V1.2 or higher
helper.publish("Light", helper.SCENE.CurrentLight().InternalName())
def saveData(self):
# This method will be called when a Poser scene is saved.
# Your addon should return a dictionary that can be serialized.
# Do not make any assumptions about how and where your dictionary is stored.
# It may be in the PZ3, it may be outside of the PZ3,
# it may be as ASCII text or as binary. Under no circumstances
# try to read, write or modify the addon data stored in a PZ3 directly.
#print "Save Addon-Data."
return None
def loadData(self, data):
# Only called if addon-data is saved in a loaded scene.
#print "Load Addon-Data."
pass
def savePrefs(self):
# This method is called when Poser asks your addon to save its preferences.
# Typically this happens when Poser exits or when an addon explicitly asked
# for the preferences to be saved.
# Return a dictionary that can be serialized.
#print "Save Addon-Preferences"
return None
def loadPrefs(self):
#rint "Load Addon-Preferences"
pass
pMQTT = poserMQTT()
poser.RegisterAddon(_ADDON_ID, pMQTT)
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.
Hello and good day. I am looking for an example how to work with poseraddon.py correctly. My efforts to do so end in a modest window.
The application is also not automatically recognized by Poser at program start. Who can help?
Greetings Stephan