# 3.7.3.2 Graphic Objects

Graphic objects can be created by the Origin user and placed in an Origin child window. These objects include labels, arrows, lines, and other user-created graphic elements. These objects are accessed from script by their name, as defined on Programming tab of Object Properties dialog. In versions before Origin 2017, it's called Programming Control dialog box.

To open the dialog box, use one of these methods:

• Click on the object to select it, then choose Format: Object Properties... menu. In versions before Origin 2017, it's called Format: Programming Control.
• Right Click on the Object and select Properties.... Then go to Programming tab. In versions before Origin 2017, there is Programming Control context menu.
• Alt+DoubleClick on the object.
 Note: Objects can be set as not selectable. To access such objects you need to first check Edit: Edit Mode menu. In versions before Origin 2017, it was called Button Edit Mode.

Scripts can be attached to these labels by typing the script into the text box of the Programming tab of the dialog box. The Script execution trigger is set from the Script, Run After drop-down list.

In general, only named objects can be accessed from LabTalk script. However, an unnamed object can be accessed by a script from Programming tab of the dialog using this. notation, as described below.

## GObject Variable Type

GObject is a LabTalk variable type to represent graphic objects in a layer. You can use Label -r objectName command to delete it.

The general syntax is:

GObject name = [GraphPageName]LayerName!ObjectName; // Use page name, layer name, object name

GObject name = [GraphPageName]LayerIndex!ObjectName; // Use page name, layer number, object name

GObject name = LayerName!ObjectName; // Active page, use layer name, object name

GObject name = LayerIndex!ObjectName; // Active page, use layer number, object name

GObject name = ObjectName; // Active page, active layer, use object name

You can declare GObject variables for both existing objects as well as for not-yet created object.

For example:

// Here we declare a GObject then create its Graphic Object.
win -t plot;          // Create a graph window

// Declare a GObject named myLine attached to 'line1'
GObject myLine = line1;
// Now create the object (list o shows 'line1')
draw -n myLine -lm {1,2,3,4};
win -t plot;          // Create a new graph window

// Even though myLine is in a different graph that is not active,
// You can still control it with the GObject name ...
myLine.X += 2; // Move the line

label -r myLine; //Delete the object

// More often the Graphic Object exists already
GObject leg = legend; // Attach to the legend object
leg.fsize = 28; // Set font size to 28
leg.color = color(blue); // Set text color to blue
leg.background = 0; // Turn off the surrounding box

Note: A list o with the original graph active will show line1 which is the physical object name, but will not show myLine which is a programming construct.

## Properties

The generic properties of these objects are listed below. Not all properties apply to all objects. For example, the text property does not apply to a Line object.

### Syntax

[winName!]objName.property = value;

or

this.property = value;

• WinName! is required if a Graphic Object exists in a non-active page. It specifies the window that the named object resides in. The layer the object resides in must be the active layer of that page. When using a declared GObject, WinName is never needed.
• objName is the object's name, as shown in the Object Name text box in the Programming Control dialog box or the name of a declared GObject variable.
• Property is one of the available objName properties.
 Run objectName.= to see almost all properties of the object. 

### General Properties

Property Access Description
Numeric
Only applicable for 2D graph legend object (Object name = Legend). It controls whether to align each column when dragging legend entries into multiple columns. 0 = Do not align, 1 = Align legend entries for each column. (Origin 2015 SR0)
Numeric
Length of beginning arrow heads in point size.
Numeric
Shape of beginning arrow heads by position in drop down list, Object Control dialog box: 0 = none, 1 = filled, 2 = chevron, etc.
Numeric
Width of beginning arrow heads in point size.
Numeric
Length of end arrow heads in point size.
Numeric
Shape of end arrow heads by position in drop down list, Object Control dialog box: 0 = none, 1 = filled, 2 = chevron, etc.
Numeric
Width of end arrow heads in point size.
Numeric
Controls the display of arrow heads for each line segment of polyline and freehand objects:

1 = arrow at beginning of each segment.
2 = arrow at end of each segment.
3 = arrow at both ends of each segment.

Note: arrowBeginShape and arrowEndShape must also be set.

Numeric
Attach to method:

0 = layer
1 = page
2 = axes scales

attach$Read Only String Page name if the object attaches to page. Otherwise, returns layer name in format [PageName]LayerName! Origin 8.5 SR0 auto Read/Write Numeric Redraw automatically after property changes: 0 = disable, 1 = enable. background Read/Write Numeric Control the background of an object as follows: 0 = no background, 1 = black line, 2 = shadow, 3 = dark marble, 4 = white out, and 5 = black out. borderColor Read/Write Numeric Object border color which be written or read as the color index from LabTalk List of Colors. Alternately, use the Color function to assign color to the object (e.g. text.bordercolor=color("#2F1BE3")) using names (LT List of Colors only), HTML color codes or RGB values. clip Read/Write Numeric Determine whether display of graphic objects associated with the layer should follow the layer's Clip Data to Frame setting: 0 (default) = do not clip objects to layer frame, 1 = follow layer Clip Data to Frame setting and clip (hide) objects that lie outside the layer frame if data clipping is enabled. color Read/Write Numeric Line, text, or outline color index number. Use the Color function, as in name.color=color(red);' dx dy Read/Write Numeric Width and height in axes units. direction Read/Write Numeric Control how to stretch/span the graphic object line in horizontal/vertical direction: 0 = None 1 = Horizontal 2 = Vertical 3 = No corners 4 = Corners only 5 = Horizontal Span All Layers 6 = Vertical Span All Layers 7 = Horizontal Span Whole Page 8 = Vertical Span Whole Page 9 = Horizontal Span Whole Layer 10 = Vertical Span Whole Layer enable Read/Write Numeric Enable hotspots on the object: 0 = disable, 1 = enable. event Read Only Numeric Actions that trigger an object's script execution: 0 = None; 1 = Button Up; 2 = Moved; 3 = Sized; 4 = Moved or Sized; 5 = Redrawn, 6 = Real-Time; 7 = Window Create; 8 = Window Close; 9 = Window Activate; 10 = Window Deactivate; 11 = New Selection; 12 = Before Save; 13 = Axes Rescale; 14 = All Events; 15 = Mask Change; 16 = Data Change. fillColor Read/Write Numeric Object fill color which be written or read as the color index from LabTalk List of Colors. Alternately, use the Color function to assign color to the object (e.g. text.bordercolor=color("#2F1BE3")) using names (LT List of Colors only), HTML color codes or RGB values. font Read/Write Numeric Text label font index number. Use the Font function, as in name.font = font(arial);' fSize Read/Write Numeric Text label font size. getXY Write only Numeric Copy xy values from object to dataset. height Read Only Numeric Height in layer coordinate units. hGap Read/Write Numeric Only applicable to 2D graph legend object (Object name = Legend). It specifies the horizontal gap between each legend entry column in percentage of font height. (Origin 2015 SR0) hMove Read/Write Numeric Horizontal movement: 0 = disable, 1 = enable. index Read Only Numeric Only applicable for objects composed of multiple items, such as the UIM objects. Indicates which item in an object has been affected by a Windows action. keepInside Read/Write Numeric Restrict object's movement to within the layer frame: 0 = disable, 1 = enable. left Read/Write Numeric Left location of the object in physical coordinates. lineType Read/Write Numeric Line and arrow object line type: 1 = solid, 2 = dash, and 3 = dot. lineWidth Read/Write Numeric Line or arrow object line width. link Read/Write Numeric The substitution level: 0 = no link, 1 = Link and resolve recursively, 2 = Link and resolve only first level and 3 = Link and resolve up to two levels. (Origin 2015 SR1) margin.unit Read/Write Numeric This is only available when the graphic object is a text object. It specifies the unit to define the margin between the text and its borders: 1 = in percent of font height (Default); 0 = in percent of whole text height.(Origin 2015 SR0) margin.left margin.right margin.top margin.bottom Read/Write Numeric These are only available when the graphic object is a text object. It specifies the left/right/top/bottom margin between the text and its borders. The value is in percentage of the text margin unit, and the unit is defined by margin.unit property. (Origin 2015 SR0) mouse Read/Write Numeric Mouse access to the object: 0 = disable, 1 = enable. name$ Write Only
String
Object name.
Numeric
Number of points of a poly object (polygon, polyline).
Numeric
Real-time update of substitution notation in a text label message: 0 = disable, 1 = enable.
Numeric
Reverse video display: 0 = disable, 1 = enable.
Numeric
Text label rotation in degrees.
Numeric
Script, Run After mode index number, from the drop-down list in the Label Control dialog box.
setXY Write only
Numeric
Copy xy values from dataset to object.
Numeric
Object display: 1 = visible, 0 = hidden. Hidden objects are not selectable
Numeric
Text object shadow color which be written or read as the color index from LabTalk List of Colors. Alternately, use the Color function to assign color to the object (e.g. text.bordercolor=color("#2F1BE3")) using names (LT List of Colors only), HTML color codes or RGB values.
Numeric
Text object shadow width in point size.
Numeric
Controls object edit states. The property is bit-oriented so that values can be added.

Example: polygon.states = 3, disables resizing and rotating for the object named polygon.

0 = all controls are enabled.
1 = resizing is disabled.
2 = rotating is disabled.
4 = skewing is disabled.
8 = moving individual points is disabled.
16 = in place editing is disabled.
32 = resize text label border disabled.
64 = horizontal movement is disabled.
128 = vertical movement is disabled.

text$Read/Write String Message displayed by a text label. top Read/Write Numeric Top of the object in physical coordinates. transparency Read/Write Numeric Set transparency of the object. Only available for rectangle, circle, polygon and region objects. (Origin 9.0 SR0) rect.transparency = 50; // Set transparency to 50% type Read Only Numeric Return the type of graphic object.(Origin 9.0 SR1) 0 = text 1 = rectangle 2 = arrow or line 3 = handle 5 = group 6 = string 7 = data type$ Read Only
String
Return the type strings of graphic object.(Origin 2015 SR0)
Numeric
Only applicable to 2D graph legend object (Object name = Legend). It specifies the vertical gap between each legend entry row in percentage of font height. (Origin 2015 SR0)
Numeric
Vertical movement: 0 = disable, 1 = enable.
Numeric
Enable White Out for text objects: 0 = disable, 1 = enable.
Numeric
Width in layer coordinate units.
Numeric
Enable wrapping of text upon resizing object: 0 = disable, 1 = enable (Origin 2015 SR0)
Numeric
Specify the wrapping width of text in object. Enabled only when wrap is set to be 1. (Origin 2015 SR0)
x
y
Numeric
Axes X Y coordinates of the center of the object.

Notes:

1. To align another object with the current object, you can use the dx, dy, x and y of the current object to calculate the x and y of the object to be moved. (See an example below.)
2. In fact, any graphic object has an invisible rectangle associated with it. X and Y are actually the center of the rectangle. In addition, they are in pixel units, so there might be some loss of precision when converted to scale units. If you want to know the axis position of a line object, it is better to use x#, y# instead of x, y.
x#
y#
Numeric
x# and y# are the axes position of the #th point of an object. Straight lines and Arrows have 2 points, rectangles and circles have 4 points and other objects may have many points.

loop(ii,1,4) {circle.x$(ii)=;circle.y$(ii)=;}

### Examples

• Position the legend in the upper left of a layer
legend.background = 1;
legend.y = layer1.y.to - legend.dy / 2;
legend.x = layer1.x.from + legend.dx / 2;
• Change colors of a circle object named circle1
// First of all, create a circle object on a graph
// then rename it to "circle1" for the two lines script below
circle1.color = 1; // Black border
circle1.fillcolor = color(yellow); // Yellow fill
• Obtain the source graph name of the floating graph object, this assumes the floating graph object is named as "bmp" and is in the active worksheet.
// bmp.type$returns "Embedded Graph: [GraphName]" // GraphName is the actual name of the source graph // the following script can be used to retrieve GraphName from bmp.type$
%A = %[%(bmp.type$), >18]; ty %[%A, %[%A]];//Should print out the value of GraphName Note: Substring Notation is used to retrieve GraphName. • Position object "polyline" by copying xy coordinates from worksheet to object. polyline.setXY([Book1]1!A, [Book1]1!B); ## Selected Ojbect Properties The basic properties of the selected graphic object can be controlled syntax s.property = value; The available properties are listed below. ### Properties Property Access Description FONT Read/Write Numeric Font size of the selected text object. Use the Font function, as in name.font = font(arial); SIZE Read/Write Numeric Size of the selected object. BOLD Read/Write Numeric Set Bold to the selected text object. ANGLE Read/Write Numeric Rotation angle of the selected object. For example, you can use s.size = 50; to control the size of a text object if it is selected. . ## Methods The generic methods of these objects are listed below. Not all methods apply to all objects. For example, the addtext method does not apply to a Line object. ### Syntax [winName!]objName.Method(arguments) or this.Method(argument) • WinName! is required if a Graphic Object exists in a non-active page. It specifies the window that the named object resides in. The layer the object resides in must be the active layer of that page. When using a declared GObject, WinName is never needed. • objName is the object's name, as shown in the Object Name text box in the Programming Control dialog box or the name of a declared GObject variable. • Method is one of the available objName methods. • arguments are specific to the method.  Run objectName.()= to see all methods of the object.  ### General Methods Method Description addText(string) Append the string to a text label. Requires a screen refresh to view the change. click(n) Simulate a click on the nth hot spot of the object. Multiple hot spots are a feature of UIM objects. draw(option) Redraw the object. option = local : Redraw the hot spots of an object option = global : Redraw the entire object run() Run the script contained in an object. ### Examples • Append text. // Declare a string variable and assign a value string stringVariable$ = " (modified)";
// Assign a value to a string register (A)
// Note how new line is contained in the value
%A = "
Final";
// Now add various text to an existing object named 'text'
}
}

## General Examples

• This script disables horizontal movement for the Arrow object in the Graph2 window.
Graph2!Arrow.hmove = 0;
• When entered in the Script window, the next script prints the X and Y coordinates of the center of the Button object to the Script window.
Button.x =;
Button.y =;
• The following script runs the script associated with an object named Mode in the Graph1 window.
Graph1!mode.run();
• The last script uses the draw() method to redraw the WksData object in the Data2 window.
Data2!WksData.draw(global);