|
Unless otherwise noted, all functions and classes mentioned here are directly accessible from the Sketch package. E.g. the CreateRGBColor function is accessible either with:
import Sketch blue = Sketch.CreateRGBColor(0, 0, 1) |
or
from Sketch import CreateRGBColor blue = CreateRGBColor(0, 0, 1) |
This function creates a rectangle object described by trafo. trafo is an affine transformation (represented by a a transformation object that transforms the unit square into the desired rectangle.
Transformation objects are created by the functions Trafo, Scale, Rotation and Translation.
In the most common case where you want to create a rectangle with a specific width and height at a specific position (x, y) (the position of the lower left corner of the rectangle) and edges parallel to the edges of the page, you could create the rectangle like this:
Rectangle(Trafo(width, 0, 0, height, x, y)) |
or like this
Rectangle(Translation(x, y)(Scale(width, height))) |
To create a PolyBezier object you have to first create the paths and then the PolyBezier instance. A path is created by starting with an empty path returned by the CreatePath function and then appending line- and curve-segments to construct the path. How paths are constructed is covered in detail in the corresponding section in the developer's guide.
Once you have constructed your paths, you create the PolyBezier instance with:
The argument path_tuple must be a tuple of paths. If you have just one path path, you can use the expression (path,).
For an example, see the sample script create_star.py.
Create a simple text object with the text string text. The position and orientation is given by trafo, a a transformation object.
For an example, see the sample scripts create_text.py.
Create a group object with the objects in the list children as children. The children must not be contained in a document.
If you want to create a group of objects that are already contained in the document, the easiest way is to make sure those objects are selected and then to call the document method GroupSelected. Like all document methods this method takes care of undo itself.
Insert the object object into the document. The object becomes the topmost object in the current layer. The selection is set to just this object.
Move the object by offset. offset must be a point object. For an example, see the sample scripts abut_horizontal.py and abut_vertical.py.
Apply the affine transformation trafo to the object.
The fill is defined by a pattern object. There are several kinds of pattern types:
The EmptyPattern is a predefined object that means the object is not filled.
Return a solid pattern object for color color. The solid pattern fills the object uniformly.
color has to be a color object which can be created with the following function:
CreateRGBColor(red, green, blue)
which returns a color object for the color given by the RGB components red, green, blue which are floats in the range 0 - 1.
There are also some predefined color objects for some standard colors. They are attributes of the StandardColors object, e.g. StandardColors.blue is blue.
To set the properties of an object, call this method
Set the properties described by the keyword arguments and return undo information. The accepted keyword arguments are
The fill pattern. It can be of any pattern type.
A boolean (i.e. 0 or 1) that defines whether the pattern is transformed as well if the object is transformed.
The pattern for the outline. Must be either EmptyPattern or a SolidPattern. If it's EmptyPattern, no outline is drawn.
The line width as a float in pt.
The cap style. One of CapButt, CapRound or CapProjecting. These constants are defined in Sketch.const
The join style. One of JoinMiter, JoinRound or JoinBevel. These constants are defined in Sketch.const
The dash-pattern as a tuple of floats. The items of the tuple define the dashes and gaps terms of the line-width. The number of items in the tuple should be even.
The arrow heads. Arrow heads are objects you can create with the function Arrow.
The font for a text object. The value must be a font object which you can get with the function GetFont(name) where name is the PostScript-name of the font.
The size of the font in pt.
Return true if the selection is not empty.
Return the number of selected objects.
Return a list containing the currently selected objects.
Return the currently selected object if exactly one object is selected, return None otherwise.
Make the selection empty.
If mode is SelectSet, make object the selected object, otherwise, if mode is SelectAdd, add object to the selection. mode defaults to SelectSet.
object may be a single object or a list of objects.
Remove object from the selection.
|
|