The Becasso Scripting API

Introduction

This document describes the API for scripting Becasso, Sum Software's Paint and Imaging application for the BeOS.

Like all well-behaved BeOS applications, Becasso implements scripting in the form of a set of messages. The examples in this document use Attila Mezei's freely avaiable scripting application called hey, version 1.2 or greater. Hey is available from BeBits. For example, to make the WinGrab window be "always on top" (which can be handy if you are grabbing a lot of (partial) windows when writing documentation for an application), you can say

    hey Becasso set Feel of Window "WinGrab" to 3

Scripting General Settings

The five buttons visible in Becasso's main window show the various features of the settings Becasso is currently using. They show the mode, tool, foreground color, background color, and pattern, respectively. The first four of these can be scripted.

The four scriptable properties can be both set and queried:

    hey Becasso get Mode
returns the current mode (either Draw or Select) as property named result. The Mode and Tool properties can be set either by index or by name.

Note: When the sender of the scripting message is waiting for a reply (as hey does), Becasso will only send a reply message. If it isn't, Becasso will print the reply as a readable string to stderr on the terminal it was launched from.
The possible names of the Mode property are Draw and Select; the Tool can be either Brush, Eraser, Fill, Text, Spray Can, Freehand, Lines, Free Shape, Polygons, Rectangles, Ovals, Circles, or Ellipses. These names are the names displayed in the Becasso main window as help text when the mouse pointer is moved over the icons. Becasso is case insensitive, so
    hey Becasso set tool to "spray can"
    hey Becasso set Tool to "Spray Can"
are equivalent.

The foreground and background colors are scripted through the properties Foreground and Background, respectively. Querying Becasso for the current colors always yields them as a B_RGB_COLOR_TYPE entry named result in the reply message.

Note: This is different from the Mode and Tool properties, because these can also function as specifiers when scripting mode or tool parameters (see Scripting Tool Parameters, below).
Setting the colors, however, can be done by either specifying the components of an rgb_color, or by color name, i.e.
    hey Becasso set Foreground to "rgb_color(85,107,47,255)"
    hey Becasso set Foreground to DarkOliveGreen
are equivalent.

The color names are matched case-insensitively and also allow for variants with spaces, so

    hey Becasso set background to lightslategrey
    hey Becasso set Background to "Light Slate Grey"
    hey Becasso set Background to LightSlateGrey"
    hey Becasso set Background to "Light slate GREY"
are equivalent. Also, Becasso tries not to be pedantic about spelling, so Grey and Gray are considered equivalent.
Note: To find out all the names Becasso recognizes as colors, run Becasso from a terminal with the command line switch -c, i.e.
    Becasso -c
and it will print out all the color names to the terminal, preceded by the red, green, and blue components. Note that there are 752 entries, so the list is quite long. The color names are the ones that are in the file rgb.txt in most XWindow distributions.

Scripting Tool Parameters

Every tool parameter can be set through scripting calls. The syntax is is as in the following example:
    hey Becasso set ColorRatio of Tool Spraycan to 0.5
The following table lists all tool parameter names, types, and allowed values.

ToolParameterTypeValid Range
Brush Strength
Angle
Width (XSize)2
Height (YSize)
Spacing
Hardness
int
float1
int
int
float
int
0 .. 255
0 .. 45
1 .. 40
1 .. 40
1 .. 64
0 .. 100
Eraser XSize (Width, HSize)
YSize (Height, VSize)
Shape (Type)
float
float
string
1 .. 50
1 .. 50
Ellipse, Rectangle
Fill ToleranceType (Type)
Tolerance (Visual)
Red
Green
Blue
string
float
int
int
int
Visual, Absolute (RGB)
0 .. 255
0 .. 255
0 .. 255
0 .. 255
Text Family
Style
PtSize (Size)
Shear
Rotation
AntiAliasing
Text4
string
string
float
float
float
bool
string
Family Name3
Style Name
4 .. 144
45 .. 135
0 .. 360
true, false
Text
Spray Can Sigma
Ratio (ColorRatio)
Rate (FlowRate)
Fade
float
float
float
bool
1 .. 25
0 .. 1
1 .. 20
true, false
Clone4 Strength
Angle
Width (XSize)
Height (YSize)
Spacing
Hardness
int
float
int
int
float
int
0 .. 255
0 .. 45
1 .. 40
1 .. 40
1 .. 64
0 .. 100
Freehand PenSize float 0 .. 50
Lines PenSize
Corners (FillCorners)
float
bool
0 .. 50
true, false
Free Shape PenSize
ShapeType (Type)
float
string
0 .. 50
FilledOutline, Filled, Outline
Polygons PenSize
ShapeType (Type)
float
string
0 .. 50
FilledOutline, Filled, Outline
Rectangles PenSize
ShapeType (Type)
float
string
0 .. 50
FilledOutline, Filled, Outline
Ovals PenSize
ShapeType (Type)
RelativeWidth (RelX)
RelativeHeight (RelY)
AbsoluteWidth (AbsX)
AbsoluteHeight (AbsY)
Corners
float
string
float
float
float
float
string
0 .. 50
FilledOutline, Filled, Outline
0 .. 0.5
0 .. 0.5
0 .. 200
0 .. 200
Relative, Absolute
Circles PenSize
ShapeType (Type)
FixPoint (FirstClick)
float
string
string
0 .. 50
FilledOutline, Filled, Outline
Center, Perimeter
Ellipses PenSize
ShapeType (Type)
float
string
0 .. 50
FilledOutline, Filled, Outline
1Where it makes sense, Becasso also looks for integers in the scripting message, because hey defaults to integers for values without a decimal point.
2Names in brackets denote optional other names for the same parameter.
3Partial matches are supported, i.e. "Dutch" for "Dutch801 RM BT".
4New in Becasso 2.0.

All option names are case independent.

Scripting Filter Properties

Filter parameters can also be set through scripting calls. The syntax is as in the following example:
    hey Becasso set Method of Filter De-Interlace to Interpolate
You can apply filters via scripting using the following syntax:
    hey Becasso let Canvas Foo do ApplyFilter "Gaussian Blur"
or, when you are targeting the default canvas (see below), simply
    hey Becasso ApplyFilter "Gaussian Blur"
The following table lists all scripting parameter names, types, and allowed values.

FilterParameterTypeValid Range
Brightness/Contrast Brightness
Contrast
int
int
-100 .. 100
-100 .. 100
BumpMap Color
Elevation
Angle
Reflection
Specular
Translucent
string
int
int
int
int
int
White/Foreground/Background
0 .. 90
0 .. 360
0 .. 100
0 .. 100
0 .. 100
ChromaKey Color
Sigma
Threshold
string
int
int
Blue/Foreground/Background
0 .. 100
0 .. 100
Color Curves Gamma
Type
float
string
-3 .. 3
Straight/Smooth/Gamma
De-Interlace Frame
Method
string/int
string
Even/Odd/#2
Double/Interpolate
Diffuse x
y
int
int
1 .. 151
1 .. 151
DuoTone Mode string BW/Sepia/FB3
Gaussian Blur x
y
int
int
1 .. 151
1 .. 151
Motion Blur Distance
Angle
int
int
2 .. 50
0 .. 360
Noise Sigma
Type
int
string
1 .. 127
Additive/Multiplicative
OilPaint Size int 3 .. 151
Quantize Colors
Dither
Palette
int
string
string
1 .. 256
Yes/No
Foreground/Background
Solarize Threshood int 0 .. 100
1 Only odd values allowed
2 Frame number; even/odd is deducted
3 Current Foreground/Background colors

Other Global Properties and Commands

Apart from the Tool and Mode properties (and all their settings), the Foreground and Background colors, Becasso has a notion of the TabletArea, ExportFormat, and Scriptee properties.

The TabletArea is a BRect that specifies the rectangle and aspect ratio to be used by Becasso's internal Wacom tablet code. You can ask for the current active table area with

    hey Becasso get TabletArea
For example, the default for an UltraPad A5 the values are (0.0, 0.0, 10240.0, 7680.0). You can change it with
    hey Becasso set TabletArea to 'BRect(l,t,r,b)'
Note that TabletArea represents the area in tablet coordinates, which will be mapped onto the canvas coordinates. So if you have a square canvas, setting the TabletArea to something like (0,0,7680,7680) will give you maximum tablet use while keeping a 1:1 aspect ratio. To enable the built-in tablet support, you have to launch Becasso with a -t command line switch. This feature is obsolete; a separate tablet driver is included in the Becasso distribution.

To prevent the Export Format Window from popping up during scripted export of a canvas to a non-native format, Becasso uses a default export format which can be set via the ExportFormat property:

    hey Becasso set ExportFormat to image/jpeg
    hey Becasso set ExportFormat to 'JPG '
The default export format can be specified by its type code or its MIME type. Asking for it will return the type code.

To actually have Becasso export the canvas, send it an Export command:

    hey Becasso Export with Name=foo.jpg
If the format hasn't been set, Becasso will save in its native format. If there is no name given, Becasso will default to the canvas title (i.e. the window title, minus the (100%) part). If the path is not absolute, Becasso will default to the current working directory. If there is no path at all, it will default to the user's home directory (using the canvas title).

As a more elaborate example, the following snippet will convert all JPEG images in the current directory to PNG:

    hey Becasso set ExportFormat to image/png
    for x in *.jpg
    do
        hey Becasso load file\($x\)
        hey Becasso Export with Name=${x%.jpg}.png
    done
The reason Becasso knows which canvas to export, even though you are in fact sending the 'expt' messages to the main application, is that Becasso keeps track of a "current scriptee" to which it will forward all relevant scripting messages. This scriptee is automatically set to the last opened canvas, but can be set manually to any other window:
    hey Becasso set Scriptee to 'foobar (100%)'
    hey Becasso set Scriptee to 6
The scriptee can either be set through its window title or its window index. Note that there are quite a few windows (possibly hidden) when Becasso is running, which are not necessarily canvas windows. You can also ask for the current scriptee. This will return a BMessenger, so it will hardly be useful from the command line. For a better alternative, see Canvases, below.

Normally when Becasso loads a file, it performs a sanity check on the alpha channel of the new image. Many Translator add-ons have in the past used the alpha channel to denote transparency instead of opacity (even some by Be themselves), and images originating from other systems might suffer from the same inconvenient inversion of the alpha channel. Becasso uses a simple heuristic to guess whether a newly loaded image file might have this inversion of the alpha channel, and pops up an alert box offering to invert it for you. You can prevent Becasso from popping up that alert, if for example you want to minimize the risk of a script blocking on user input, by specifying the AskForAlpha flag:

    hey Becasso load file[foo.png] with AskForAlpha=bool[false]

There are other commands you can send to Becasso or to a specific canvas. For instance, you can do:

    hey Becasso let Canvas "foo" do Crop BRect[10,10,50,50]
or if Canvas "foo" happens to be the current scriptee, simply
    hey Becasso Crop BRect[10,10,50,50]
Becasso will send sensible error results if the crop rectangle it finds doesn't make sense (or it it can't find a rectangle at all).

You can also send the commands Rotate90, Rotate180, and Rotate270 to a canvas.

Canvases

The preceding scriptable properties each have a global effect on Becasso. However, also the properties of a specific canvas can be targeted. To have Becasso open a new canvas with the name "foo", dimensions 200 pixel high and 300 pixels wide, and placed on screen with the left top of the window at (100, 150), one would say
    hey Becasso create Canvas with Name=foo and Size=BRect'(100,150,400,350)'
Especially to avoid confusion with all the non-canvas windows of Becasso, it is also allowed to use the Canvas as a specifier instead of the normal Window specifier:
    hey Becasso set Look of Canvas "Untitled 1" to 20

You can query a canvas for its aspect ratio:

    hey Becasso get AspectRatio of Canvas "foo"
after which the aspect ratio will be returned as a double. Aspect ratios larger than one denote landscape canvases; aspect ratios between zero and one denote portrait canvases. (an aspect ratio of exactly one means a perfectly square canvas).

Canvases have Layer as sub-specifier, so you can say

    hey Becasso create Layer of Canvas "foo" with Name=MyLayer
You can select the currently active layer:
    hey Becasso set ActiveLayer of Canvas "foo" to MyLayer
Removing a layer is straightforward:
    hey Becasso delete Layer "Bar" of Canvas "foo"
A Layer can be used as a specifier as well. You can set the global alpha level of a given layer with the GlobalAlpha property. For example, the following gives a fade-in effect:
    for x in 0 50 100 150 200 255
    do
        hey Becasso set GlobalAlpha of Layer Background of Canvas foo to $x
    done
You can also set the contents of a given layer to an image by setting its Contents property:
    hey Becasso set Contents of Layer "bar" of Canvas "foo" to file[image.jpg]
The image wil be stretched to fit.

Future Directions

We plan to add the possibility of querying Becasso for all tool parameters too. Scripting on BeOS is very powerful, and if you have any suggestions for further scripting support in Becasso, please don't hesitate to contact us at becasso@sumware.demon.nl.
This documentation is © 1999 - 2003, Sum Software.
Last modification: 15 June 2003.
Be and the BeOS are registered trademarks of Be, Incorporated. Trademarks used herein belong to their respective owners.