Master Class

Note

These interface classes are not intended for direct usage; rather they should be inherited by your own subclass. (See Anatomy of a LightWave Python Plug-in)

Handler

class lwsdk.IMaster(self)

Bases: lwsdk.lwsdk.IHandlerFuncs, lwsdk.lwsdk.IInterfaceFuncs, lwsdk.lwsdk.IGizmoFuncs, lwsdk.lwsdk.IItemFuncs

Proxy of C++ PCore::IMaster class

 event(LWMasterAccess access) → double

The event function is called to notify the handler that something has happened. Information about the event is included in the access structure, described below. The handler can respond to the event by issuing commands through functions provided in the access structure. The return value is currently ignored and should be set to 0.0.

 flags() → unsigned int

Returns flag bits combined using bitwise-or.

 type → int

Indicates the type of the Master instance. The lwsdk.LWMAST_SCENE type is the most common. lwsdk.LWMAST_OBJECTS and lwsdk.LWMAST_EFFECTS types are reserved for future enhancement of the class. lwsdk.LWMAST_LAYOUT Masters are like lwsdk.LWMAST_SCENE Masters, but they are persistent across scene clearing, and can therefore be used to automate scene management.

Access

class lwsdk.LWMasterAccess(self, LWMasterAccess source_)

Bases: object

Proxy of C++ PCore::LWMasterAccess class

 data → void

An opaque pointer to data used internally by Layout. Pass this as the first argument to the LWModCommand::lookup(), LWModCommand::execute() and LWModCommand::evaluate() methods.

 data_as_change() → PyEventNotifyPluginChange

This is a Python-only helper function that will take the LWMasterAccess::eventData pointer and convert it into a lwsdk.PyEventNotifyPluginChange structure. This structure is identical to the SDK's LWEventNotifyPluginChange that is provided to native-code plug-ins, but it has an additional data member called 'instance' that holds the instance pointer of the affected Master plug-in.

Please be aware that this value may not represent a Python object. It may be the instance pointer from another type of plug-in (e.g., C++) and there's no guarantee that using it like a Python object will not result in an exception (or crash). Within the Python environment, its usage should be limited to equality testing of the current instance to determine the scope of the event. (See the included Python Master script "master_test.py" for a usage example.)

NOTE: lwsdk.PyEventNotifyPluginChange was introduced in LightWave 11.5. In versions of LightWave Python prior to this release, the return value is lwsdk.LWEventNotifyPluginChange, which lacks the additional 'instance' data member.

 data_as_imageid() → LWImageID

This is a Python-only helper function that will take the LWMasterAccess::eventData pointer and convert it into a LWImageID value.

 data_as_itemid() → LWItemID

This is a Python-only helper function that will take the LWMasterAccess::eventData pointer and convert it into a LWItemID value.

 data_as_string() → char

This is a Python-only helper function that will take the LWMasterAccess::eventData pointer and convert it into a string value.

 data_as_surfid() → LWSurfID

This is a Python-only helper function that will take the LWMasterAccess::eventData pointer and convert it into a LWSurfID value.

 data_as_textid() → LWTextureID

This is a Python-only helper function that will take the LWMasterAccess::eventData pointer and convert it into a LWTextureID value.

 data_as_time() → double

This is a Python-only helper function that will take the LWMasterAccess::eventData pointer and convert it into a LWTime (double) value.

 evaluate(void data, char command) → int

Issue the command with the name and arguments in the command string. This is an alternative to using LWMasterAccess::lookup() and LWMasterAccess::execute(). The command and its arguments are written to a single string and delimited by spaces.

 eventCode → int

This is a code value that indicates the type of the event. Please see the example Python Master script "master_test.py" for a detailed listing of all the possible event codes that may be passed to this method.

 eventData → void

This is an opaque pointer to data that is associated with the event. When data is provided, you should use one of the LWMasterAccess::data_as_*() helper functions to convert the opaque data into something directly useful within Python.

 execute(void data, LWCommandCode cmd, int argc, argv, result) → int

Issue the command given by the command code argument. py_dyna_values is an array of DynaValue arguments.

 lookup(void data, char cmdName) → LWCommandCode

Returns an integer code corresponding to the command name. The command is issued by passing the command code to the LWMasterAccess::execute() method. Command codes are constant for a given Layout session, so this only needs to be called once per command, after which the codes can be cached and then used in any number of calls to LWMasterAccess::execute().

Factory

class lwsdk.MasterFactory(name, klass)

Bases: lwsdk.lwsdk.IMasterFactory

Default Python Factory for IMaster

 create(context)
 destroy(instance)

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class master_test(lwsdk.IMaster):
    def __init__(self, context, count):
        super(master_test, self).__init__()
        # context has no relevant value in a Master plug-in
        self._instance_count = count

    # LWMaster --------------------------------------------
    def flags(self):
        return lwsdk.LWMAST_SCENE | lwsdk.LWMASTF_RECEIVE_NOTIFICATIONS

    def event(self, ma):
        if ma.eventCode == lwsdk.LWEVNT_COMMAND:
            msg = ma.data_as_string()
            print msg     # print a copy on the Python console
            ma.evaluate(ma.data, "StatusMsg [ %s ]" % msg)
[...]
        elif ma.eventCode == lwsdk.LWEVNT_NOTIFY_SCENE_SAVE_COMPLETE:
            scene_name = ma.data_as_string()    # convert data to a string value
        elif ma.eventCode == lwsdk.LWEVNT_NOTIFY_ITEM_ADDED:
            item_id = ma.data_as_itemid()       # convert data to a LWItemID
[...]
        elif ma.eventCode == lwsdk.LWEVNT_NOTIFY_PLUGIN_CHANGED:
            change_struct = ma.data_as_change() # convert data to Plugin Change Event structure
            if change_struct.pluginevent == lwsdk.LWEVNT_PLUGIN_UPDATED:
[...]
ServerRecord = { lwsdk.MasterFactory("LW_PyMasterTest", master_test) : ServerTagInfo }

Table Of Contents

Previous topic

Handler Interfaces

Next topic

Generic Class

This Page