Skip to content

Instantly share code, notes, and snippets.

View lukpazera's full-sized avatar

Lukasz Pazera lukpazera

View GitHub Profile
@lukpazera
lukpazera / cmdItemArg.py
Last active January 28, 2016 14:48
One way to pass item argument to command. Doing the same by using lx.eval and passing item ident is much easier though.
import modo
item = modo.Scene().selected[0]
cmdSvc = lx.service.Command()
cmd = cmdSvc.Spawn(lx.symbol.iCTAG_NULL, 'texture.reference')
attr = lx.object.Attributes(cmd)
val = attr.Value(attr.Lookup("item"), True)
valRef = lx.object.ValueReference(val)
valRef.SetObject(item)
cmd.Execute(lx.symbol.fCMD_EXEC_DEFAULT)
@lukpazera
lukpazera / chanUIDepend.cpp
Last active November 25, 2015 14:01
Setting up dependencies between channels on a custom item requires implementing ChannelUI interface .
/*
* If you want to create dependencies between channels on a custom item
* such that one channel enable state depends on some other channel value
* (on the same item) you need to implement ChannelUI interface for your item.
*/
/* This is needed to obtain the implemented custom item type.
* (see DependencyCountIndex() method below)
*/
static CLxItemType cit_self (MY_CUSTOM_ITEM_TYPE_NAME);
@lukpazera
lukpazera / itemGradChannel.cpp
Last active November 25, 2015 13:26
How to add gradient channel to an item.
/*
* An example on how to add gradient channel to a custom item.
* Gradient will also have default 1.0 flat value.
*/
LxResult
CPackage::pkg_SetupChannels (
ILxUnknownID addChan)
{
CLxUser_AddChannel ac (addChan);
@lukpazera
lukpazera / cmdNotifier.cpp
Created November 24, 2015 13:07
CLxCommandNotifier class can be used to create custom notifiers for use in commands.
#include <lxu_command.hpp>
class CustomNotifier : public CLxCommandNotifier
{
public:
CustomNotifier ();
virtual ~CustomNotifier () {}
virtual void cn_Parse (std::string &args) {};
virtual unsigned int cn_Flags (int code) { return LXfCMDNOTIFY_VALUE; };
@lukpazera
lukpazera / cmdArgQuery.cpp
Created November 19, 2015 09:54
An example function showing how to query command's argument from C++ MODO SDK.
/*
* This function allows for querying a command argument.
* It's possible to set any other command's arguments first
* prior to the query. This is done by passing a map with
* argument name/value pairs.
*/
bool queryCmdArg(const char* cmdName, const char* argName, std::map<std::string, CLxUser_Value>& otherArgs, CLxUser_ValueArray& valArray)
{
CLxUser_CommandService cmdSrv;
CLxUser_Command cmd;
@lukpazera
lukpazera / baseEvalMesh.cpp
Last active November 19, 2015 09:50
Accessing base and evaluated meshes in MODO.
unsigned index;
CLxUser_Scene scene;
CLxUser_ChannelRead rchan;
CLxUser_Mesh umesh;
// Base mesh is CLxUser_Mesh
if (LXx_OK(item.ChannelLookup (LXsICHAN_MESH_MESH, &index))) {
item.GetContext (scene);
scene.GetChannels (rchan, LXs_ACTIONLAYER_EDIT);
if (rchan.Object (itm, index, umesh))
@lukpazera
lukpazera / openYesNoDialog.cpp
Created October 27, 2015 08:59
How to open a Yes/No dialog using dialog service (MODO SDK).
/* This snippet demonstrates a function that will open a Yes/No dialog in MODO using dialog service.
*
* To create a dialog we need dialog service. We use dialog service to allocate message object
* that will determine the type of dialog that we will open and will contain the text of the message
* that we want to display. The text needs to be set in the message table in a config file.
* Next we set message object to our message passing message table name and message key
* and we use SetCode() method to set the type of a dialog that we want to open.
* Finally, we open such prepared message via dialog service
* and translate the result into boolean value.
*/
@lukpazera
lukpazera / getUserValue.cpp
Last active October 27, 2015 08:47
Snippet showing how to read user value via C++ MODO SDK.
/* To read user value we spawn a new user value command.
* Then, we are using the attributes interface set to the command
* to set command's first argument to the name of the user value
* that we want to read.
* Next we obtain the index the of "value" argument so we can query
* command for this argument and store user value's value in the value array.
* The final step is to read the value from value array and put it
* inside value int variable. In this case we know it's an int
* so we go with GetInt() directly. If you do not know value's type
* you can get it using .Type() method on the ValueArray interface.
@lukpazera
lukpazera / get_current_scene.cpp
Created September 17, 2014 15:48
How to get current scene interface and read number of mesh items in scene from it.
/*
This snippet demonstrates how to get currently selected scene interface and
obtain number of mesh items in the scene from it.
Generally, selections are managed via selection service and are stored
as packets. So what we are doing is we are getting recent selection
of the cinema type from the selection service which comes as a pointer
to the selection packet. We then use scene packet translation object
to extract scene interface out of the packet we received pointer to from
selection service.
@lukpazera
lukpazera / log.py
Last active August 29, 2015 13:58
An example of a simple class that allows for writing messages into desired log.
# python
""" Log allows for writing messages into choosen log subsystem.
Messages can have simple hierarchical format:
- Head Message,
- Child Message 1,
- Child Message 2,
- Child Message 3,
- etc.