Compost4 Scripting

From Compost Wiki
Revision as of 19:30, 12 February 2014 by Jeffm (talk | contribs) (Created page with "==Overview== Compost 4 contains a built in scripting system built around the Iron Python(http://ironpython.net/) scripting language. ==Scripts== Compost4 scripts are loaded f...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Overview

Compost 4 contains a built in scripting system built around the Iron Python(http://ironpython.net/) scripting language.

Scripts

Compost4 scripts are loaded from the following paths

  • [APPLICATION INSTAL DIRECTIORY]\Macros
  • [USER PROFILE DIRECTORY]\AppData\Roaming\Gibbs\Compost4\Macros

These scripts are scanned when the application is first started.

Script Types

There are 2 main types of scripts that can be made, simple scripts, and Callback Scripts.

Simple Scripts

Simple Scripts contain the code for a single function and are automatically added to the end of the Scripts menu in Compost Application. When executed from the menu the entirety of the script is run from the first command in a similar way to how post processors are run.

Callback Scripts

A Callback Script is capable of much tighter integration with the Compost Editor, and works by implementing an Initialization function that is called on start-up and then registering one or more script functions with the system that can be called during various events. These events are how scripts can create complex menu structures with multiple options and install hooks into other features such as custom error checking and axis set building.

ScriptAPI

All Scripts have access to a Class that is called the ScriptAPI. This is a .net class that gives a script information about the current documents that are open as well as compost specific functions that they can call. Some examples include:

  • Functions to create menus and sub-menus
  • Access to the currently selected document
  • Access to the currently selected POST form
  • Access to the Prog code for the current POST
  • Access to the MDD for the selected POST
  • Functions to compile a post and display errors
  • Functions to manipulate the text area for the current document

As compost is developed more functions and features will be added to this class to give scripts the powers they need. The All the data from the class can be seen in Visual Studio's object browser if Compost4.exe is included as a reference.


The Init Function

All Callback macros must implement the init system. This is done by creating the following function

 def InitCompostMacro():
 	return;

In this function you have access to the global;

 ScriptAPI.API