PrevUpNext usersguide-8.htmlThe Script Registry
usersguide-5.htmlUser Scripting
usersguide-10.htmlCommon Tasks Skencil's API
If you want to write scripts for Skencil you have to know how to access
the objects in the document and how to manipulate them. This section
gives a brief introduction to the structure of Skencil's modules and
objects from script author's point of view.
A more detailed description of Skencil's internals can be found in the
devguide.htmlDeveloper's Guide .
Module Structure
Skencil's code is organized in a hierarchy of packages. The top-level
package that contains all of Skencil's core components is 
Sketch.
It directly contains references to most of Skencil's graphics classes and
functions.
Conventions
Skencil's objects have methods that are meant for public use and
methods for internal purposes. Naturally, a script is expected to only
use the public interface. Since Python has no builtin distinction
between public and private/protected methods we have to rely on
conventions. 
Skencil uses a naming convention for this. Methods with capitalized
names, e.g. "
SetRadius", are public methods and Methods with
lowercase name, e.g. "
set_radius", are protected.
Undo Handling
As pointed out above, advanced scripts have to deal with undo
information. This isn't difficult, but you have to know which methods
return undo information and what you have to do with it.
You only have to deal with undo info if you modify an object that is
part of a document. These objects include instances of classes derived
from 
devguide-11.html#N2GraphicsObject  ( devguide-10.htmlclass hierarchy ) and the objects that
define the properties of a graphics object, like patterns.
All methods that modify such an object return an undo info object. What
this object looks like is irrelevant here, all you need to know for now
is that you have to pass it immediately on to the document method
AddUndo.
A typical example:
context.document.AddUndo(object.Translate(offset))
The devguide-11.html#N8Translate  method translates
an object by 
offset, a devguide-5.htmlpoint
object
 that stands for a 2D-vector.
There are some exceptions to the rule that methods that modify the
document return undo info. 
Firstly, the document methods that modify the selection, that is, that
modify which objects are selected not the selected objects themselves,
don't return undo info because changing the selection is not considered
changing the document.
Secondly, public document methods that modify the selected objects
themselves already take care of undo info themselves. The reason for
this is that they are called directly as a result of a menu command,
button or key-press event.
For more information about undo information in Skencil, have a look at
the 
devguide-19.htmlcorresponding section  in the
Developer's Guide.
Further Information
The example scripts in the Script directory contain extensive
comments on what's going on.
The devguide.htmlDeveloper's Guide  covers Skencil's
internals in more detail. Although it's incomplete it already contains a
lot of information about the structure of Skencil's sources, the class
hierarchy and some of the base classes, coordinate systems, plugins and
more.
And, of course: Use The Source, Luke!
usersguide-8.htmlThe Script Registry
usersguide-5.htmlUser Scripting
usersguide-10.htmlCommon Tasks PrevUpNext