This module provides functions to query drawing content. It contains these submodules:
geometry
and
query
.
Methods
Each drawig has a set of metadata that can be defined and retrieved. These metadata are stored in the drawing file. Each metadata is assigned to a key.
Example
This example will retrieve the metada of the current drawing associated to owner "com.mycompany.scripting".
var settings = Tools.getToolSettings();
var config = {
drawing : settings.currentDrawing,
owner : "com.mycompany.script"
};
var metadata = Drawing.getMetaData(config);
Parameters:
Name |
Type |
Description |
args |
Object
|
Dictionary of arguments.
Properties
Name |
Type |
Description |
drawing |
Object
|
Drawing descriptor. |
owner |
String
|
The metada data unique identifier. It is strongly suggested to use reverse DNS to make sure your key is not conflicting with another one. |
|
(static) getModificationCounter(args)
At any time, a drawing has a modification counter. No drawing can have the same modification counter. When a drawing changes, this counter increases. Capturing this can be useful for situation where a complex computation needs to be cached until the drawing is changed.
Example
This example will retrieve the modification counter of the current drawing or false if there is no current drawing.
var settings = Tools.getToolSettings();
var config = {
drawing : settings.currentDrawing
};
var counter = Drawing.getModificationCounter(config);
// If there are no current drawing
counter = false;
// example of returned value
counter = 59;
// Add a brush in the drawing... and run the example again
counter = 72;
Parameters:
Name |
Type |
Description |
args |
Object
|
Dictionary of arguments.
Properties
Name |
Type |
Description |
drawing |
Object
|
Drawing descriptor. |
|
(static) getPivot(args)
Returns the drawing pivot.
Example
This example will retrieve the drawing pivot.
var settings = Tools.getToolSettings();
var config = {
drawing : settings.currentDrawing
};
var pivot = Drawing.getPivot(config);
// Example of return value
pivot = {
x: 534.2, y: 20.1
};
pivot = false; // If the drawing is invalid.
Parameters:
Name |
Type |
Description |
args |
Object
|
Dictionary of arguments.
Properties
Name |
Type |
Description |
drawing |
Object
|
Drawing descriptor. |
|
Example
This example will store and retrieve some metadata from the current drawing. One of is value is a complex object stored as a JSON string.
var settings = Tools.getToolSettings();
var complexObject = {
strings : [ "a", "b"],
a : 12
};
var arguments = {
owner: "com.mycompany.script",
drawing: settings.currentDrawing,
metadata: [
{ key: "key1", value: "1"},
{ key: "key2", value: "2"},
{ key: "key3", value: JSON.stringify(complexObject)}
]
}
Drawing.setMetaData(arguments);
var retrieved = Drawing.getMetaData({ drawing : arguments.drawing, owner : arguments.owner});
// The key/value at index 2 is a complex object. Parse it.
if (retrieved)
retrieved[2].value = JSON.parse(retrieved[2].value);
System.println("retrieved: " + JSON.stringify(retrieved));
// console displays:
// retrieved: [{"key":"key1","value":"1"},{"key":"key2","value":"2"},{"key":"key3","value":{"strings":["a","b"],"a":12}}]
Parameters:
Name |
Type |
Description |
args |
Objet
|
Dictionary of arguments
Properties
Name |
Type |
Description |
drawing |
Object
|
Drawing descriptor. |
owner |
String
|
The metada data unique identifier. It is strongly suggested to use reverse DNS to make sure your key is not conflicting with another one. |
metadata |
Array
|
An array of key/value pairs. The key and value must be strings. If you want to store a more complex object, you can store its JSON representation using JSON.stringify() and restore it on reading using JSON.parse(). |
|
(static) setPivot(args)
Returns the drawing pivot.
Example
This example will retrieve the drawing pivot and increate the x coordinate and set it.
var settings = Tools.getToolSettings();
var config = {
drawing : settings.currentDrawing
};
var pivot = Drawing.getPivot(config);
System.println("pivot before = " + JSON.stringify(pivot, null, ' ') + ";");
pivot.x += 100;
config.pivot = pivot;
Drawing.setPivot(config);
pivot = Drawing.getPivot(config);
System.println("pivot after = " + JSON.stringify(pivot, null, ' ') + ";");
Parameters:
Name |
Type |
Description |
args |
Object
|
Dictionary of arguments.
Properties
Name |
Type |
Description |
drawing |
Object
|
Drawing descriptor. |
pivot |
Object
|
Pivot object.
Properties
Name |
Type |
Description |
x |
Object
|
X coordinate of pivot. |
y |
Object
|
Y coordinate of pivot. |
|
|