The Python Script plug-in is a Silo Plug-in that allows you to create Python scripts that run against the Silo SDK. Using Python Script Plug-in you can create python scripts and bind those scripts to keys, mouse actions, and buttons using Silo’s customization features.
If you are not familiar with Python, it is an easy to learn
but powerful programming language that is increasingly being used as a scripting
language for applications. There are
many online resources for learning Python. Python.org contains a good list of resources
for learning Python at http://www.python.org/doc/.
Requirements:
Silo version 1.42.
Python version 2.4 or later
Installation:
The Python Script Plug-in requires Python be installed in your computer. Python is available for free from www.python.org/download/. The Python Script Plug-in was built against version 2.4.3 of Python. The Windows installer for this version can be found at: http://www.python.org/ftp/python/2.4.3/python-2.4.3.msi
In addition to Python, you will also need PythonPlugin.dll, which can be found here. It is a Silo plug-in that connects to Python and exposes the Python SDK to python scripts. Put PytonPlugin.dll in your Silo “Startup Plugins” directory. For a typical install the directory would be “C:\Program Files\Silo\Plugins\Startup Plugins”. Your location may differ.
The python scripts that you write for Silo will be text files. You edit them using any text editor (you can use the Windows Notepad application). The script files should have a file extension of “.py”. Each script will be a separate file and all script files need to be stored in the Silo “Startup Plugins” directory. For a typical install the Silo plug-in directory would be “C:\Program Files\Silo\Plugins\Startup Plugins”.
Once the script file is in the plugin directory you can then assign your script to a key, mouse action or button in Silo. When you run Silo and look under the list of commands available for key, mouse, and button customizations and you will find your script name in list of available commands. The name shown will match the file name of your script. For example if your script file name was "MyScript.py", then the commnad name would be "MyScript".
You can create multiple scripts and each script can be assigned to different keys, mouse actions, or buttons using Silo’s customization features.
Lets create a simple script that will display the message “Hello World” when executed. Not very useful but will demonstrate the steps necessary to set up a script.
import silo
silo.PopupMessage(“Hello World”)
The first line of code tells Python to import the silo module which contains definitions for the Silo SDK. See the reference documentation for all the interfaces defined in the silo module. The second line tells Silo to display the message “Hello World”.
Now that you have a running script it is easy to modify it and try your changes. For example if now change the message text in your HelloWorld script file and save the changes, hitting the ‘U’ key again in Silo will run your modified script and you should see your new message. No need to re-start Silo. Since Python is an interpreted language it picks up the latest changes to your script each time it is run.
One of the methods defined in the silo module is the ExecuteCommand() API. This method allows you to invoke almost any Silo command (see the online reference for a list of all the commands that can be executed). Creating scripts that can play multiple commands is very simple. For example the following script will invoke the Extrude command, immediately followed by the Inset command.
import silo
silo.ExecuteCommand(silo.COM_EXTRUDE_SELECTION)
silo.ExecuteCommand(silo.COM_INSET_SCALE)
Important Note about ExecuteCommand(): Some of the Silo commands, such as Extrude Normal, Bevel, and others, have an interactive mode. Once the command is executed the tool manipulator becomes active and the user can use the mouse to modify the affect of the tool. The tool does not get dropped until the user does a right click, or invokes another command that modifies the mesh. For example, if you use the “Extrude By Normal” command it performs the extrude and then switches to the tool manipulator so that you can control the amount of extrusion. If you then issue another Extrude By Normal command it will drop the first command and do another Extrude By Normal command. When using ExecuteCommand to invoke commands such as Extrude By Normal, that have an interactive mode, the call will return control back to the script before the user has a chance to adjust the extrusion. If the call to ExecuteCommand is followed by another ExecuteCommand it can cause the tool for the first call to be dropped before being able to adjust it. For example the following script will perform two Extrude By Normal commands:
import silo
silo.ExecuteCommand(silo.COM_EXTRUDE_NORMALS)
silo.ExecuteCommand(silo.COM_EXTRUDE_NORMALS)
Unfortunately the second Extrude By Normal will cause the first Extrude By Normal to drop immediately before being able to adjust the extrusion amount.
The above example scripts are just a small sampling of what can be done using the Python Plugin for Silo. Your Pyton scripts can access the geometry of your models allowing you create very powerful scripts. More interesting sample scripts can be found here.
There are also a few python scripts that I created that you may find useful. They also provide good examples of how to use callbacks in you python scrpts. They can be found here.