element Class Reference

The element JavaScript global object. Add, remove, modify or get information about element nodes in the scene. More...

Public Slots

Elements Data
int numberOf ()
 Returns the number of elements in the scene. More...
 
int id (int elementIndex)
 Returns the id (key) of the element. More...
 
String getNameById (int elementId)
 Returns the current element name. More...
 
String scanType (int elementId)
 Returns a string that is the scan type of the element. The scan type is either: COLOR, GRAY_SCALE or BW. More...
 
double fieldChart (int elementId)
 This function returns the field chart size for a given element. The element ID must be provided. The field chart is a number such as 12,16 or 24 field. More...
 
int vectorType (int elementId)
 This function returns the vector type for the given element. For standard vector or Toon Boom bitmap drawing, the vector type will be TVG. More...
 
String pixmapFormat (int elementId)
 Returns the pixmap format for the provided element ID. More...
 
String folder (int elementId)
 Returns the actual element folder. This is normally the element name (unless it has been renamed and the project is not saved) but may include the ".<element id>" in the name if multiple elements share the same name. More...
 
String completeFolder (int elementId)
 Returns the complete element folder. This is normally the element name (unless it has been renamed and the project is not saved) but may include the ".<element id>" in the name if multiple elements share the same name. More...
 
String physicalName (int elementId)
 Returns the actual name of the drawings. This is different that the element name if this one has been renamed and the changes have not yet been saved. More...
 
Element Edition
bool modify (int elementId, String scanType, double fieldChart, String pixmapFormat, int vectorType)
 Changes the attributes of the folder of element elem. More...
 
int add (String name, String scanType, double fieldChart, String fileFormat, String vectorFormat)
 Creates a new element. Returns the element id of the newly added element if successful, otherwise it returns -1. More...
 
bool remove (int elementId, bool deleteDiskFile)
 Removes the given element. Optionally delete the disk files. This function returns true when successful. More...
 
bool renameById (int elementId, String name)
 Renames an existing element. The element ID must be provided. More...
 

Detailed Description

The element JavaScript global object. Add, remove, modify or get information about element nodes in the scene.

An element is a physical group of drawings that can be found in the scene's element folder. The element folder will be located in the temporary folder until the scene is saved. The element global object can add, remove or retrieve information about the elements of a scene. Each element has an index (0..nbElements-1) and an integer id (key of the element in the database) which is unique. Their name is not guaranteed to be unique.

function addElement()
{
var id = element.add("newDrawing", "BW", 12, "TVG", "SCAN");
}
// Rename an element
var nodePath = "Top/Drawing";
var elementId = node.getElementId(nodePath);
var elementName = element.getNameById(elementId);
var newElementName = elementName + "_Suffix";
element.renameById(elementId, newElementName);

Member Function Documentation

◆ add

int element::add ( String  name,
String  scanType,
double  fieldChart,
String  fileFormat,
String  vectorFormat 
)
slot

Creates a new element. Returns the element id of the newly added element if successful, otherwise it returns -1.

// Create a new element to hold TVGs
var elementId = element.add("MyElement", "COLOR", 12, "SCAN", "TVG");
// Create a new element node, create a new element to hold PNGs, link the element to a new drawing column
// and link the drawing column to the element node.
// Create a new element node.
var nodePath = node.add(elementNodeGroup(), elementNodeName(), "READ", 0, 0, 0);
// Create a new element of type standard PNG bitmap
// The provided extension needs to match the file extension of the file brought in.
var elementId = element.add("MyElement", "COLOR", 12, "PNG" , "None");
// Create a drawing column for an element node.
var drawingColumn = "MyDrawingColumn";
column.add(drawingColumn, "DRAWING");
// Link the drawing column to the new PNG element
column.setElementIdOfDrawing(drawingColumn, elementId);
// Link the element node to the new drawing column.
node.linkAttr(nodePath, "DRAWING.ELEMENT", drawingColumn);
Parameters
name: The name of the element.
scanType: "COLOR", "GRAY_SCALE" or "BW" (for black and white).
fieldChart: 12, 16 or 24.
fileFormat: Use "SCAN" when importing TVGs. "OPT" when importing optimized TVGs and "TGA", "PSD", "PNG", "JPEG", "BMP", "TIFF" or "OMF" when importing files of those formats.
vectorFormat: "TVG" for files of "SCAN" or "OPT" formats. "None" when importing file as is (ex: "TGA", "PNG", "JPEG", etc.). "PNT" is a deprecated option.
Returns
Returns the element id of the newly added element if successful, otherwise returns -1.

◆ completeFolder

String element::completeFolder ( int  elementId)
slot

Returns the complete element folder. This is normally the element name (unless it has been renamed and the project is not saved) but may include the ".<element id>" in the name if multiple elements share the same name.

Parameters
elementId: The unique id of the elements.
Returns
Returns the complete element folder.

◆ fieldChart

double element::fieldChart ( int  elementId)
slot

This function returns the field chart size for a given element. The element ID must be provided. The field chart is a number such as 12,16 or 24 field.

Parameters
elementId: The unique id of the element.
Returns
Returns the field chart size for a given element.

◆ folder

String element::folder ( int  elementId)
slot

Returns the actual element folder. This is normally the element name (unless it has been renamed and the project is not saved) but may include the ".<element id>" in the name if multiple elements share the same name.

Parameters
elementId: The unique id of the element.
Returns
Returns the actual element folder.

◆ getNameById

String element::getNameById ( int  elementId)
slot

Returns the current element name.

Parameters
elementId: The unique id of the element.
Returns
Returns the current element name.

◆ id

int element::id ( int  elementIndex)
slot

Returns the id (key) of the element.

Parameters
elementIndex: An integer from 0 to the value returned by the function element.numberOf, representing the index number of the element. The id and the index are not always the same value.
Returns
Returns the id (key) of the element.

◆ modify

bool element::modify ( int  elementId,
String  scanType,
double  fieldChart,
String  pixmapFormat,
int  vectorType 
)
slot

Changes the attributes of the folder of element elem.

Parameters
elementId: The unique id of the element.
scanType: "COLOR", "GRAY_SCALE" or "BW" (for black and white).
fieldChart: 12, 16 or 24.
pixmapFormat: 1 for OPT, 3 for SCAN, 4 for SGI, 5 for TGA, 7 for YUV, 9 for OMF or 10 for PSD, 11 for PNG, 12 for JPEG, 13 for BMP, 15 for TIFF.
vectorType: 0 (None), 1 (PNT) or 2 (TVG).
Returns
Returns true if successful.

◆ numberOf

int element::numberOf ( )
slot

Returns the number of elements in the scene.

Returns
Returns the number of elements in the scene.

◆ physicalName

String element::physicalName ( int  elementId)
slot

Returns the actual name of the drawings. This is different that the element name if this one has been renamed and the changes have not yet been saved.

Parameters
elementId: The unique id of the element.
Returns
Returns the actual name of the drawings.

◆ pixmapFormat

String element::pixmapFormat ( int  elementId)
slot

Returns the pixmap format for the provided element ID.

Parameters
elementId: The unique id of the element.
Returns
Returns the pixmap format for the provided element ID.

◆ remove

bool element::remove ( int  elementId,
bool  deleteDiskFile 
)
slot

Removes the given element. Optionally delete the disk files. This function returns true when successful.

Parameters
elementId: The unique id of the element.
deleteDiskFile: Optionally, delete the element from the disk.
Returns
Returns true if successful.

◆ renameById

bool element::renameById ( int  elementId,
String  name 
)
slot

Renames an existing element. The element ID must be provided.

Rename the physical element (and its folder) of the given id in the scene's folder (i.e. the element folder found in specialFolder.currentProjectPath() + "/elements/" + element.folder(elementId);). The folder will see its name changed the next time the scene will be saved.

var nodePath = "Top/Drawing";
var elementId = node.getElementId(nodePath);
var newElementName = "MyNewElementName";
element.renameById(elementId, newElementName);
Parameters
elementId: The unique id of the element.
name: The new name of the element. This name must be unique. This operation will physically rename all the files associated to this element.
Returns
Returns true if successful.

◆ scanType

String element::scanType ( int  elementId)
slot

Returns a string that is the scan type of the element. The scan type is either: COLOR, GRAY_SCALE or BW.

Parameters
elementId: The unique id of the element.
Returns
Returns a string that is the scan type of the element.

◆ vectorType

int element::vectorType ( int  elementId)
slot

This function returns the vector type for the given element. For standard vector or Toon Boom bitmap drawing, the vector type will be TVG.

The value 0: indicates that the element is NOT a vector drawing (It is an IMAGE type, ex: PNG, TGA, PSD images). The value 1: indicates that the element is a PNT (obsolete) vector drawing. The value 2: indicates that the element is a TVG vector drawing.

Parameters
elementId: The unique id of the element.
Returns
Returns the vector type for the given element.