Topic - Scripting Tutorials for Modo

Hi Everyone,

are there any good scripting tutorials (video or written) available for modo? I have been searching on the forum, and was surprised not to find any thread about this topic.

I am familiar with various scripting languages and 3d packages and am just looking for a small introductory tutorial, which would just give me the basics to make the transition easier.

If anybody at Luxology is reading this:
I think one of the fantastic Lux-Video tutorials about scripting/programming in Modo would greatly appeal to a lot of people who are using Modo in a Studio environment and give TDs a good starting point for integrating Modo in the studio pipeline.
I found the Scripting XSI tut, that Helge Mathee made (Free and legal! download here: http://redi-vivus.com) extremely helpful when learning Xsi scripting and would be very thrilled if you would come out with something like this for Modo!

Thanks a lot,
Jonathan
Hi Jonathan

There is an entire scripting document PDF included with modo and is located in the root of your modo install directory.

Help | Scripting_and_Commands.PDF

The other thing I find is great for learning is to simply do the task in modo and use the commands from the history panel.

Cheers.
Quote from Philip Lawson :
Hi Jonathan
There is an entire scripting document PDF included with modo and is located in the root of your modo install directory.
Help | Scripting_and_Commands.PDF



Yes, I looked at that. I usually like to have a small introductory tutorial to the general approach of scripting in an app, a simple step by step tut for, lets say, randomly generating objects or something like this. Something that familiarizes you with all the basics while working on a real script so that you can start to look up specifics only after you have at least a basic sense about the scripting approach.
Then, as 2nd step, i will look into the help PDF. That usually works best for me. Maybe that is just my personal preference...
If you're already familiar with several languages and scripting in other applications transitioning to modo is trivial to say the least. There's no API to learn just a handfull, and I do mean a handfull (@ half a dozen depending on which language you choose), of 'glue' commands to learn. After that you can pretty much just consider modo scripting as 'macros with logic'. Any half decent TD with a solid grounding in Perl or Python should be up and running within a few hours. There are plenty of example scripts available for perusal:

http://www.vertexmonkey.com/scripts_modeling_create.php
http://www.modonize.com/Scripts/default.aspx
What task would you like to do? I'm sure something could be written quickly to explain that process.
Quote from Philip Lawson :
What task would you like to do? I'm sure something could be written quickly to explain that process.


WOW. That is a generous offer. I wanted to dive into Modo Scripting for some time now (So far i have worked with Python, Jscript, Mel, Lua; in Maya, XSI and Fusion; a fair amount of Web stuff in PHP ).

For a project i needed to convert quiet a few replicators to normal meshes. I found this script http://forums.luxology.com/discussion/topic.aspx?id=36875&show=solidworks%20import%20replicators but it only works, if the replicas have been generated automatically. Now i want to rework it so that it also supports polys and points point as sources.

What i am looking for is a simple tutorial that explains the most essential tasks. How do i query a value, how do i change a value, how do i echo/messagebox, is there a way to interactively debug, how do i create and use a simple UI.
Now I realize, that i can find all these things in sample scripts and the PDF. I don't want to be a lazy bum, I just thought, that someone must have had these same essential questions before and wanted to avoid reinventing the wheel.

There are NO scripting tuts for Modo? Maybe the next Luxology.TV could just give a little introduction. I think that could get a lot of people excited about scripting in Modo

Message edited by Jonathan Josenhans on 1/19/2010 - 1:26 PM

I'll use the camera properties as an example of how to set about writing a script for some functionality.

The Goal
To toggle the default camera visibility on and off.

Scripting
The first thing I would do is to actually use modo to set the channel property and record what modo is actually using via the history panel. When we have the visibility channel selected...

channel.value on sets the camera on.
channel.value off sets the camera off.

So how do I query this to find its current value? Well, in modo if you replace a value of a command with a '?' you get a result returned.

Drag the command line divider up and you will be presented with several tabs - click on the results tab. Select the camera manually, then click on the channels tab and select the Visibility channel and enter the following to the command line:-

channel.value ?

A result will be printed out and will also appear in the event log. Toggle commands (?+) can also be used, but for the sake of this guide, we'll use an if statement.

To write this as a python script we should use the following:-

#python

#Selects the camera item.
lx.eval("select.item Camera set")

#Selects the Visibility channel
lx.eval("select.channel {Camera:visible} set")

#Stores the result of the command into myVariable.
myVariable = lx.eval("channel.value ?")

#If myVariable equals on or default, turn it off, else turn it on.
if myVariable == "on" or myVariable == "default":
   lx.eval("channel.value off")
else:
   lx.eval("channel.value on")

#Print out the result of myVariable to the event log.
lx.out("The camera is currently ",myVariable)


lx.eval in python is used to push commands while lx.out prints the result or whatever is included in the () to the event log.

Hope this is of some help.

Message edited by Philip Lawson on 1/19/2010 - 2:05 PM

I should point out that if you simply select the camera and run the command channel.value ? you will get an error as you must select the channel you wish to query, which is what lx.eval("select.channel {Camera:visible} set") does.

EDIT: I should also point out that there are other ways to do this.

Message edited by Philip Lawson on 1/19/2010 - 2:29 PM

edit: ha, Phil beat me to it :)

Prob worth pointing out that there's always more than one way to skin a cat in modo, even when you;re scripting, so you can achieve the same thing that Phil's oulined without actually selecting anything by using the command item.channel and passing the channel name and item name as arguments:

item.channel visible ? item:{Camera}

The curly brackets around Camera simply denote that what you're passing is a string and you only really need it if the string you're passing is likely to contain spaces. general rule of thumb is always use curly brackets whan you're passing an item name, item IDs don't contain spaces so they don't need them.

to answer a couple of your other queries ...

interactive debugging: not built into modo, no. This is partly because modo uses a generic scripting interface, language support is provided by language specific plugins, you can potentially hook up any embedable scripting language you wanted. Whether interactive debugging support could be written as part of the plugin I'm not entirely sure. I suspect it coul. If you do a search for WingIDE in the scripting forum you'll find that someone has managed to get interactive Python debugging working with that. But, to be honest, after 3 years scripting in modo I haven't found the lack of interactive debugging much of an issue, certainly not enough to tempt me away from Komodo - most modo scripts simply aren't long or complex enough for it to matter (macros with logic).

UIs: This is actually a more tricky question. Creating UIs for scripts IMO is actually a topic worthy of a tutorial. The basic answer is that Uis are a separate issue to scripting, they (mostly) operate outside the scope of the script. What I mean by that is, if you've used libraries like tKinter or wxPython or built UIs in other languages where building the UI - creating/showing windows, creating/adding widgets, assigning actions and callbacks etc is part of the script and the script interacts with the user via the GUI while the script is running (ie the GUI is the front end for the running script), then modo doesn't have anything like that.

Message edited by GwynneR on 1/19/2010 - 2:57 PM

Good advice Gwynne - and indeed, my above example could be written in two lines if a toggle and output is all that would have been required.


#python

lx.eval("item.channel visible ?+ item:{Camera}")
lx.out("The camera is currently set to ",lx.eval("item.channel visible ? item:{Camera}"))
Thanks a log Philip and GwynneR!

I am starting to make my first steps with modo scripting. Something like this was exactly what i needed.

I think, once I have a little more time again and the necessary experience, i will write the small beginners tutorial which i was looking for myself.

Thanks again,
Jonathan
Quote from Jonathan Josenhans :
Thanks a log Philip and GwynneR!

I am starting to make my first steps with modo scripting. Something like this was exactly what i needed.

I think, once I have a little more time again and the necessary experience, i will write the small beginners tutorial which i was looking for myself.

Thanks again,
Jonathan


This would be wonderful, there are a few people around here that would love to start picking up a few extra tricks :)

Leif