Skip to content

Instantly share code, notes, and snippets.

View lukpazera's full-sized avatar

Lukasz Pazera lukpazera

View GitHub Profile
@lukpazera
lukpazera / getChannelSelection.py
Last active February 17, 2023 13:15
A simple script for MODO that reads current channel selection from scene and outputs it to Event Log.
# python
""" Get Channel Selection.
There is no utility class for handling channel selection
like there is for items and scenes so it has to be done manually.
"""
import lx
selection_service = lx.service.Selection()
@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 / item_selection_filter.py
Last active March 10, 2021 19:56
Simple example of filtering item selection to group items only.
# python
""" Snippet demonstrates how to filter item selection out so it contains
only items of required type (group items in this case).
Filtered items are printed out in Event Log.
"""
import lx
import lxu.select
@lukpazera
lukpazera / getUserValueCompare.cpp
Created June 15, 2020 09:15
This snippet compares two methods of getting user value from MODO SDK. They give the same result but watch out for getting value via the ScriptSys service - it is MUCH slower, especially in MODO 14.1.
/*
* The first method is by using user.value command.
* This seems like indirect way compared to direct API call but it is actually WAY faster.
* Especially as of MODO 14.1 release.
* Use this one to get user value!
*/
CLxUser_CommandService cmdSrv;
CLxUser_Command userValCmd;
int value = 0;
@lukpazera
lukpazera / setupChannels.py
Created August 21, 2019 11:44
This is how to read evaluated setup channels using MODO python SDK. The crucial bit is using scene.SetupChannels() in line 11. Stolen from Foundry's coding slack channel.
scene_svc = lx.service.Scene()
sel_svc = lx.service.Selection()
pkt_trans = lx.object.ItemPacketTranslation(sel_svc.Allocate(lx.symbol.sSELTYP_ITEM))
sel_type = sel_svc.LookupType(lx.symbol.sSELTYP_ITEM)
for i in xrange(sel_svc.Count(sel_type)):
pkt = sel_svc.ByIndex(sel_type, i)
item = pkt_trans.Item(pkt)
scene = item.Context()
@lukpazera
lukpazera / getPolyUnderMouse.py
Last active May 23, 2020 09:30
Gets mesh and and an index of a polygon that is under the mouse in MODO viewport.
# python
import lx
import modo
# This snippet queries polygon that is under a mouse.
# Querying polygon only works correctly on active meshes.
# That means that if mouse is over the mesh that is not active
# (was not selected prior to entering component mode),
@lukpazera
lukpazera / queryComponentMode.cpp
Created March 18, 2020 09:21
Test current component mode using MODO SDK. Posted by Ben Halling on MODO's #coding slack channel.
LXtID4 currentTypes[4];
LXtID4 vertex_type = srv_sel.LookupType(LXsSELTYP_VERTEX);
LXtID4 edge_type = srv_sel.LookupType(LXsSELTYP_EDGE);
LXtID4 poly_type = srv_sel.LookupType(LXsSELTYP_POLYGON);
LXtID4 item_type = srv_sel.LookupType(LXsSELTYP_ITEM);
currentTypes[0] = vertex_type;
currentTypes[1] = edge_type;
currentTypes[2] = poly_type;
currentTypes[3] = item_type;
LXtID4 cur = srv_sel.CurrentType(currentTypes);
@lukpazera
lukpazera / toolHandle.cpp
Created March 18, 2020 09:12
Tool with handle example. Lifted from sample code posted by Mario Baldi on MODO's #coding Slack channel. I have not tested this code, saving for future reference.
#include <lx_tool.hpp>
#include <lx_toolui.hpp>
#include <lx_vmodel.hpp>
#include <lx_vector.hpp>
#include <lxu_attributes.hpp>
#include <lx_plugin.hpp>
#include <lx_layer.hpp>
#include <lx_mesh.hpp>
#include <lx_log.hpp>
@lukpazera
lukpazera / toolPixelDraw.cpp
Created March 18, 2020 09:10
Tool implementation - drawing in screen space. Lifted from MODO's #coding channel on Slack.
/*
You return LXfTMOD_DRAW_PIXEL from your ToolModel::Flags method.
Then you'll be called for drawing into screen space.
If you support multiple drawing modes; 3D and screen space,
you can test in your Draw callback by calling ILxView::Flags,
and testing the return type for LXiVIEWv_PIXEL.
You can query the StrokeDraw object passed to your draw method for an ILxView.
When you're in your drawing call, you can call ILxView::Dimensions to get the size of the viewport
to calculate the position to draw.
*/
@lukpazera
lukpazera / mouseProximity.cpp
Last active February 20, 2020 16:40
A WIP sample on how to measure the distance from a given object in viewport to mouse - in pixels.
// This is not entirely working as it crashes MODO when an item with this drawing
// is selected and transform tool is enable. So something somewhere has to return bad value at some point
// and this sample is not handling that.
// This code needs to be executed from within item's Draw method.
// Drawing is aborted if mouse pointer is more then 120 pixels from the item to be drawn.
// The idea is to only draw the item when mouse pointer is close enough to it.
#include <lx_vp.hpp>
CLxUser_View view(stroke);