Sat, Nov 9, 11:31 AM CST

Renderosity Forums / Poser Python Scripting



Welcome to the Poser Python Scripting Forum

Forum Moderators: Staff

Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)

We now have a ProPack Section in the Poser FreeStuff.
Check out the new Poser Python Wish List thread. If you have an idea for a script, jot it down and maybe someone can write it. If you're looking to write a script, check out this thread for useful suggestions.

Also, check out the official Python site for interpreters, sample code, applications, cool links and debuggers. This is THE central site for Python.

You can now attach text files to your posts to pass around scripts. Just attach the script as a txt file like you would a jpg or gif. Since the forum will use a random name for the file in the link, you should give instructions on what the file name should be and where to install it. Its a good idea to usually put that info right in the script file as well.

Checkout the Renderosity MarketPlace - Your source for digital art content!



Subject: Search example for working with poseraddon.py


Bastep ( ) posted Thu, 19 November 2020 at 3:11 AM · edited Thu, 07 November 2024 at 5:50 AM

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. Screenshot 2020-11-19 100528.png

The application is also not automatically recognized by Poser at program start. Who can help?

Greetings Stephan



structure ( ) posted Thu, 19 November 2020 at 7:25 AM
Forum Coordinator

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


Bastep ( ) posted Thu, 19 November 2020 at 9:38 AM · edited Thu, 19 November 2020 at 9:38 AM

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



structure ( ) posted Thu, 19 November 2020 at 10:13 AM · edited Thu, 19 November 2020 at 10:15 AM
Forum Coordinator

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


adp001 ( ) posted Thu, 19 November 2020 at 3:18 PM

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)





adp001 ( ) posted Thu, 19 November 2020 at 3:33 PM

Don't miss the last 2 lines :)




Bastep ( ) posted Fri, 20 November 2020 at 2:40 AM

Hello, that is exactly what I was looking for. Especially the second last line. Thanks Greetings Stephan



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.