Setting a string channels default value¶
Introduction¶
This article provides the sample code for setting a default value of a string channel on a very simple item plugin.
Code¶
stringTest_main.cpp¶
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | //---------------------------------------------------------------------------------
//
// Simple example plugin demonstrating setting a default value on a string.
//
//---------------------------------------------------------------------------------
// Include the required modo SDK headers
#include <lx_plugin.hpp>
#include <lx_package.hpp>
#include <lxidef.h>
#include <lx_item.hpp>
#include <lx_value.hpp>
// Define the server names.
#define SERVER "stringTest"
#define SERVER_INST "stringTest.inst"
#define STRING_CHAN "stringChannel"
//---------------------------------------------------------------------------------
// Classes for stringTest
//---------------------------------------------------------------------------------
class item_package;
class item_instance : public CLxImpl_PackageInstance
{
public:
item_package *src_pkg;
CLxUser_Item item_loc;
LxResult pins_Initialize (ILxUnknownID item, ILxUnknownID super) LXx_OVERRIDE;
void pins_Cleanup (void) LXx_OVERRIDE;
LxResult pins_Newborn (ILxUnknownID original) LXx_OVERRIDE;
LxResult pins_AfterLoad (void) LXx_OVERRIDE;
void pins_Doomed (void) LXx_OVERRIDE;
};
class item_package : public CLxImpl_Package
{
public:
static LXtTagInfoDesc descInfo[];
CLxUser_Item item_loc;
CLxSpawner<item_instance> inst_spawn;
item_package () : inst_spawn (SERVER_INST) {}
LxResult pkg_SetupChannels (ILxUnknownID addChan) LXx_OVERRIDE;
LxResult pkg_TestInterface (const LXtGUID *guid) LXx_OVERRIDE;
LxResult pkg_Attach (void **ppvObj) LXx_OVERRIDE;
};
//---------------------------------------------------------------------------------
// Methods for stringTest
//---------------------------------------------------------------------------------
LxResult item_instance::pins_Initialize(ILxUnknownID item, ILxUnknownID super)
{
/*
pins_Initialize is called when the instance is associated with the item.
The item is not part of the scene yet.
*/
item_loc.set (item);
return LXe_OK;
}
LxResult item_instance::pins_Newborn (ILxUnknownID original)
{
/*
pins_Newborn is called once the item is created and is part of the scene.
*/
return LXe_OK;
}
LxResult item_instance::pins_AfterLoad (void)
{
/*
pins_Newborn is called once the item is loaded and is part of the scene.
*/
return LXe_OK;
}
void item_instance::pins_Doomed(void)
{
/*
pins_Doomed is called once the item is destined to be deleted.
*/
item_loc.clear();
}
void item_instance::pins_Cleanup(void)
{
/*
pins_Cleanup is called when the instance is about to be deleted.
*/
item_loc.clear();
}
LXtTagInfoDesc item_package::descInfo[] = {
{ LXsPKG_SUPERTYPE, LXsITYPE_LOCATOR },
{ 0 }
};
LxResult item_package::pkg_SetupChannels (ILxUnknownID addChan)
{
/*
The pkg_SetupChannels functions is used to add channels
to the item plugin.
*/
// Add a CLxUser_AddChannel Interface - used for defining channels.
CLxUser_AddChannel ac(addChan);
// Create a new LXtObjectID. This will be used for storing the default value.
LXtObjectID obj;
// CLxUser_Value SetString() method will be used to set the value of the string channel.
CLxUser_Value val;
// Add the new channel. Define it as a string channel.
ac.NewChannel(STRING_CHAN, LXsTYPE_STRING);
// Next, set the storage type as a string. This is the type of value
// that will be stored in the action layer.
ac.SetStorage(LXsTYPE_STRING);
// Finally we set the default object to be the LXtObjectID (obj).
// This returns an object which we can use to store the value.
ac.SetDefaultObj(&obj);
// Localize the LXtObjectID.
val.take(obj);
// Finally, the SetString method is called to set the default
// value to be "Some string value."
val.SetString("Some string value.");
return LXe_OK;
}
LxResult item_package::pkg_TestInterface (const LXtGUID *guid)
{
return inst_spawn.TestInterfaceRC (guid);
}
LxResult item_package::pkg_Attach (void **ppvObj)
{
item_instance *inst = inst_spawn.Alloc (ppvObj);
return LXe_OK;
}
//---------------------------------------------------------------------------------
// Initialize the servers
//---------------------------------------------------------------------------------
void initialize ()
{
/*
Initialize the servers in turn.
*/
CLxGenericPolymorph *srv;
srv = new CLxPolymorph <item_package>;
srv->AddInterface (new CLxIfc_Package <item_package>);
srv->AddInterface (new CLxIfc_StaticDesc <item_package>);
thisModule.AddServer (SERVER, srv);
srv = new CLxPolymorph <item_instance>;
srv->AddInterface (new CLxIfc_PackageInstance <item_instance>);
thisModule.AddSpawner(SERVER_INST, srv);
}
void cleanup()
{
}
//---------------------------------------------------------------------------------
|
Testing¶
Once the code above has been built using the modo SDK. You should be able to add the item plugin to modo.
Launch modo.
From the system menu, choose “Add Plug-in”.
Add the *.lx plugin file that the build process has created.
Modo should inform you that the package “stringTest” was successfully loaded.
From the item menu, choose: “Add Item > Other > stringTest”. This will add the a new stringTest item to your scene.
Select the stringTest item and from the modo command prompt, enter: “item.channel stringChannel ?”. This queries the value of the string channel on the stringTest item.
In the modo event log, modo should return: “Some string value.”. This is the default value that was defined in pkg_SetupChannels().
More Info: