OMC::DrawingAccess Class Reference

Detailed Description

Provides access to modifying Toon Boom drawings.

The OMC::DrawingAccess* provides enclosed access to a given OMC::DrawingVectorArtLayer* – once the access has been started, all modifications made to the drawing will be done at once and will be enclosed in the same operation. This allows for a drawing to be modified with a series of changes – and all changes to occur at the same time.

All drawing changes done on the Vector object directly, and not through the drawing access, are done implictly and will skip the drawing access. This can result in multiple changes being done in different operations. In order to avoid this, wrap the modifications done to a drawing with a single OMC::DrawingAccess begin and end.


Flatten a Deformation with Drawing Access [Ignoring Line Weight]

import math
import traceback
from ToonBoom import harmony
sess = harmony.session()
proj = sess.project
scene = proj.scene
#Drawing Node to modify.
drawing_node = scene.nodes["Top/Drawing"]
at_frame = 1
vector_drawing = False
#Using the drawing attribute to get the current vector drawing.
try:
drawing_attr = drawing_node.attributes["DRAWING"]
element = drawing_attr.element
element_drawing = element.drawings[ drawing_attr.drawing.value(at_frame) ]
vector_drawing = element_drawing.drawing
parent_transform = drawing_node.ports_in[0].source.transformation( at_frame )
parent_deformation = parent_transform.deformation
except:
traceback.print_exc()
if parent_deformation:
if vector_drawing:
drawingAccess = harmony.DrawingAccess()
proj.history.begin("Modifying lines")
for art_layer in vector_drawing:
drawingAccess.vector_begin_operations( art_layer )
for layer in art_layer:
if layer.type == "Vector":
for stroke in layer.strokes:
bezpath = stroke.bezier_path
bezptlist = bezpath.list()
pts = parent_deformation.transform( bezptlist, True )
for n in range( len(bezpath) ):
bezpath[n] = pts[n]
drawingAccess.stroke_set_path( stroke, bezpath )
#Equivalent to stroke.bezier_path = bezPath
drawingAccess.vector_end_operations()
#Detach the deformation.
drawing_node.ports_in[0].unlink()
proj.history.end()
else:
print( "No deformation is attached." )



Create a new Drawing Node and Draw Some Ripples

from ToonBoom import harmony
import math
def buildRipples():
session = harmony.session()
proj = session.project
scene = proj.scene
sel = scene.selection
nodes = scene.nodes
elems = proj.elements
columns = scene.columns
proj.history.begin("Ripples")
new_column = columns.create( "DRAWING", "NEW_DRAWING_COLUMN4", { "scanType" : "COLOR", "fieldChart" : 12, "pixmapFormat" : "SCAN", "vectorType" : "TVG", "createNode" : False } ) #Create a drawing column
new_element = new_column.element #Get the element from the new column.
new_node = nodes.create("READ", "Top/Ripple") #Create a new drawing node.
drawing_attr = new_node.attributes["drawing"]
drawing_attr.column = new_column #Attach drawing column to the read node.
start_size_w = 1000
start_size_h = 200
end_size_w = start_size_w*2.25
end_size_h = start_size_h*2.25
offset_h = 12
speed_factor = 0.70
interior_circle_startSize = 0.70
from_frame = 1
to_frame = 22
#Use the same color for all drawings.
drawing_color = harmony.DrawingVectorColour.auto_colour()
for frm in range(from_frame, to_frame, 2): #Create drawings on twos
new_drawing = new_element.drawings.create( "RIPPLE_%03d"%frm, False, True ) #Create a drawing on the new element
drawing_attr.set_value(frm, new_drawing) #Set frame one to the new drawing.
drawing_attr.set_value(frm+1, new_drawing) #Set frame one to the new drawing.
new_drawing.initialize() #Initialize the drawing for modifications.
vector_drawing = new_drawing.drawing #New drawing is accessible
vector_line_art = vector_drawing["line"]
#Begin Drawing
drawingAccess = harmony.DrawingAccess()
drawingAccess.vector_begin_operations( vector_line_art )
perc_frame = math.pow( (float(frm)-float(from_frame)) / (float(to_frame)-float(from_frame)), speed_factor )
size_w = ((end_size_w-start_size_w)*perc_frame)+start_size_w
size_h = ((end_size_h-start_size_h)*perc_frame)+start_size_h
perc_interior = ((1.0-interior_circle_startSize)*perc_frame)+interior_circle_startSize
interior_size_w = size_w * perc_interior
interior_size_h = size_h * perc_interior
#Main Circle
new_layer = drawingAccess.vector_layer_create()
newStroke_circle = harmony.BezierPath.create_oval( 0, 0, size_w, size_h, 12 )
newStroke = drawingAccess.stroke_create( newStroke_circle, new_layer, None, "right", drawing_color )
#Eraser Circle
newStroke_circle = harmony.BezierPath.create_oval( 0, offset_h, interior_size_w, interior_size_h, 12 )
newStroke = drawingAccess.stroke_create( newStroke_circle, new_layer, None, "left", drawing_color )
#End Drawing
drawingAccess.vector_end_operations()
proj.history.end()
buildRipples()

Public Member Functions

void vector_begin_operations (OMC::DrawingVectorArtLayer *)
 Begins vector operations on the drawing provided. More...
 
void vector_end_operations ()
 Ends vector operations on the drawing currently being modified.
 
void art_layer_paste (const OMC::DrawingVectorArtLayer *toPaste, const OMC::Matrix *matrixOffset)
 Pastes the drawing object on top of the current drawing. More...
 
QList< OMC::DrawingVectorLayer * > vector_layers_create (const QVariant &genericDrawingDefinition)
 Creates layers with a generic layer definition object. More...
 
void vector_layer_copy (const OMC::DrawingVectorLayer *sourceLayer, const OMC::DrawingVectorLayer *targetLayer)
 Copies all the strokes from the source layer to the target layer. More...
 
void vector_layer_move (const OMC::DrawingVectorLayer *sourceLayer, const OMC::DrawingVectorLayer *targetLayer)
 Moves all the strokes from the source layer to the target layer. More...
 
void vector_layer_erase (const OMC::DrawingVectorLayer *layer)
 Erases all the strokes of the given layer. More...
 
void vector_layer_erase (const QList< OMC::DrawingVectorStroke *> layers)
 Erases all the provided strokes. More...
 
void vector_layer_erase_at (uint idx)
 Erase the node at the given position. More...
 
OMC::DrawingVectorLayervector_layers_merge ()
 Merge all layers in the OMC::DrawingVectorArtLayer. More...
 
OMC::DrawingVectorLayervector_layers_merge (QList< OMC::DrawingVectorLayer *> layers)
 Merge the given layers in the OMC::DrawingVectorArtLayer. More...
 
OMC::DrawingLayervector_layer_create (const QString &type)
 Create a layer at the top of the drawing. More...
 
OMC::DrawingLayervector_layer_create_at (uint idx, const QString &type)
 Create a layer at the given index, with the given type. More...
 
void vector_layer_paste_at (uint idx, OMC::DrawingLayer *layer)
 Copy i_node and all of its children in the current drawing at the given position. More...
 
OMC::DrawingLayervector_layer_create_above (OMC::DrawingLayer *layer, const QString &type)
 Create a layer of the given type above the destination layer. More...
 
OMC::DrawingLayervector_layer_create_under (OMC::DrawingLayer *layer, const QString &type)
 Create a layer of the given type under the destination layer. More...
 
OMC::DrawingVectorStrokestroke_create (QList< OMC::DrawingVectorStroke *> strokes, OMC::DrawingLayer *layer)
 Insert a bunch of new strokes into the layer. More...
 
OMC::DrawingVectorStrokestroke_create (QList< OMC::DrawingVectorStroke *> strokes, OMC::DrawingVectorStroke *stroke, OMC::DrawingVectorLineStyle *=nullptr, QString side=QString(), OMC::DrawingVectorColour *=nullptr)
 Insert a bunch of new strokes into the layer of the provided stroke. More...
 
QList< OMC::DrawingVectorStroke * > stroke_copy (QList< OMC::DrawingVectorStroke *> strokes, OMC::DrawingLayer *layer)
 Copies the given stroke and inserts the copy at the end of the given layer. More...
 
QList< OMC::DrawingVectorStroke * > stroke_copy (QList< OMC::DrawingVectorStroke *> strokes, OMC::DrawingVectorStroke *stroke)
 Copies the given stroke and inserts the copy before the given stroke. More...
 
void stroke_move (QList< OMC::DrawingVectorStroke *> strokes, OMC::DrawingLayer *layer)
 Moves the given stroke and inserts it at the end of the given layer. More...
 
void stroke_move (QList< OMC::DrawingVectorStroke *> strokes, OMC::DrawingVectorStroke *layer)
 Moves the given stroke and inserts it before the given stroke. More...
 
void stroke_erase (QList< OMC::DrawingVectorStroke *> strokes)
 Erases the given stroke from its containing layer. More...
 
void stroke_set_path (OMC::DrawingVectorStroke *targetStroke, OMC::BezierPath *path)
 Sets the stroke to the provided bezier path. More...
 
void stroke_set_line_style (OMC::DrawingVectorStroke *targetStroke, OMC::VectorLineStyle *style)
 Sets the line style for the provided stroke(s). More...
 
void stroke_set_thickness (OMC::DrawingVectorStroke *targetStroke, OMC::VectorThicknessPath *style)
 Sets the thickness path for the provided stroke(s). More...
 
void stroke_set_tip_type (OMC::DrawingVectorStroke *targetStroke, const QString &direction, const QString &type)
 Sets the stroke's tip type. More...
 
void stroke_set_tip_tangent (OMC::DrawingVectorStroke *targetStroke, const QString &side, const QString &direction, double tangent)
 Sets the stroke's tangent. More...
 
void stroke_set_color (OMC::DrawingVectorStroke *targetStroke, const OMC::DrawingVectorColour *colour, const QString &side)
 Sets the inside or outside colour of the given stroke. More...
 
void joint_set_outside_colour (OMC::DrawingVectorJoint *targetJoint, const OMC::DrawingVectorColour *colour)
 Sets the left colour of the given stroke. More...
 
void joint_set_inside_colour (OMC::DrawingVectorJoint *targetJoint, const OMC::DrawingVectorColour *colour)
 Sets the inside colour of the given stroke. More...
 
void contour_set_colour (OMC::DrawingVectorContour *targetStroke, const OMC::DrawingVectorColour *colour, bool children=false)
 Sets the inside colour of the given contour. More...
 

Public Attributes

bool colour_respect_sticky
 True if sticky colours should be respected. More...
 

Member Function Documentation

◆ art_layer_paste()

void OMC::DrawingAccess::art_layer_paste ( const OMC::DrawingVectorArtLayer toPaste,
const OMC::Matrix matrixOffset 
)

Pastes the drawing object on top of the current drawing.

◆ contour_set_colour()

void OMC::DrawingAccess::contour_set_colour ( OMC::DrawingVectorContour targetStroke,
const OMC::DrawingVectorColour colour,
bool  children = false 
)

Sets the inside colour of the given contour.

◆ joint_set_inside_colour()

void OMC::DrawingAccess::joint_set_inside_colour ( OMC::DrawingVectorJoint targetJoint,
const OMC::DrawingVectorColour colour 
)

Sets the inside colour of the given stroke.

◆ joint_set_outside_colour()

void OMC::DrawingAccess::joint_set_outside_colour ( OMC::DrawingVectorJoint targetJoint,
const OMC::DrawingVectorColour colour 
)

Sets the left colour of the given stroke.

◆ stroke_copy() [1/2]

QList<OMC::DrawingVectorStroke*> OMC::DrawingAccess::stroke_copy ( QList< OMC::DrawingVectorStroke *>  strokes,
OMC::DrawingLayer layer 
)

Copies the given stroke and inserts the copy at the end of the given layer.

Returns
Returns the new OMC::DrawingVectorStroke.

◆ stroke_copy() [2/2]

QList<OMC::DrawingVectorStroke*> OMC::DrawingAccess::stroke_copy ( QList< OMC::DrawingVectorStroke *>  strokes,
OMC::DrawingVectorStroke stroke 
)

Copies the given stroke and inserts the copy before the given stroke.

Returns
Returns the new OMC::DrawingVectorStroke.

◆ stroke_create() [1/2]

OMC::DrawingVectorStroke* OMC::DrawingAccess::stroke_create ( QList< OMC::DrawingVectorStroke *>  strokes,
OMC::DrawingLayer layer 
)

Insert a bunch of new strokes into the layer.

The provided strokes are defined by a OMC::BezierPath and added on the provided layer.

◆ stroke_create() [2/2]

OMC::DrawingVectorStroke* OMC::DrawingAccess::stroke_create ( QList< OMC::DrawingVectorStroke *>  strokes,
OMC::DrawingVectorStroke stroke,
OMC::DrawingVectorLineStyle = nullptr,
QString  side = QString(),
OMC::DrawingVectorColour = nullptr 
)

Insert a bunch of new strokes into the layer of the provided stroke.

The provided strokes are defined by a OMC::BezierPath and added before the provided stroke.

◆ stroke_erase()

void OMC::DrawingAccess::stroke_erase ( QList< OMC::DrawingVectorStroke *>  strokes)

Erases the given stroke from its containing layer.

◆ stroke_move() [1/2]

void OMC::DrawingAccess::stroke_move ( QList< OMC::DrawingVectorStroke *>  strokes,
OMC::DrawingLayer layer 
)

Moves the given stroke and inserts it at the end of the given layer.

Returns
Returns the new OMC::DrawingVectorStroke.

◆ stroke_move() [2/2]

void OMC::DrawingAccess::stroke_move ( QList< OMC::DrawingVectorStroke *>  strokes,
OMC::DrawingVectorStroke layer 
)

Moves the given stroke and inserts it before the given stroke.

Returns
Returns the new OMC::DrawingVectorStroke.

◆ stroke_set_color()

void OMC::DrawingAccess::stroke_set_color ( OMC::DrawingVectorStroke targetStroke,
const OMC::DrawingVectorColour colour,
const QString &  side 
)

Sets the inside or outside colour of the given stroke.

◆ stroke_set_line_style()

void OMC::DrawingAccess::stroke_set_line_style ( OMC::DrawingVectorStroke targetStroke,
OMC::VectorLineStyle *  style 
)

Sets the line style for the provided stroke(s).

◆ stroke_set_path()

void OMC::DrawingAccess::stroke_set_path ( OMC::DrawingVectorStroke targetStroke,
OMC::BezierPath path 
)

Sets the stroke to the provided bezier path.

◆ stroke_set_thickness()

void OMC::DrawingAccess::stroke_set_thickness ( OMC::DrawingVectorStroke targetStroke,
OMC::VectorThicknessPath *  style 
)

Sets the thickness path for the provided stroke(s).

◆ stroke_set_tip_tangent()

void OMC::DrawingAccess::stroke_set_tip_tangent ( OMC::DrawingVectorStroke targetStroke,
const QString &  side,
const QString &  direction,
double  tangent 
)

Sets the stroke's tangent.

Valid sides are : Right, Left
Valid directions are : From, To

◆ stroke_set_tip_type()

void OMC::DrawingAccess::stroke_set_tip_type ( OMC::DrawingVectorStroke targetStroke,
const QString &  direction,
const QString &  type 
)

Sets the stroke's tip type.

Valid directions are : From, To
Valid types are : RoundTip, FlatTip, BevelTip

◆ vector_begin_operations()

void OMC::DrawingAccess::vector_begin_operations ( OMC::DrawingVectorArtLayer )

Begins vector operations on the drawing provided.

Only one drawing can be modified at a time. Beginning operations on a drawing will wrap the changes in an undo scope and will accumulate all drawing changes into that one operation.

◆ vector_layer_copy()

void OMC::DrawingAccess::vector_layer_copy ( const OMC::DrawingVectorLayer sourceLayer,
const OMC::DrawingVectorLayer targetLayer 
)

Copies all the strokes from the source layer to the target layer.

◆ vector_layer_create()

OMC::DrawingLayer* OMC::DrawingAccess::vector_layer_create ( const QString &  type)

Create a layer at the top of the drawing.

◆ vector_layer_create_above()

OMC::DrawingLayer* OMC::DrawingAccess::vector_layer_create_above ( OMC::DrawingLayer layer,
const QString &  type 
)

Create a layer of the given type above the destination layer.

Available layer types include the following: UNDEFINED_LAYER = 0,

PAINT_LAYER BRUSH_LAYER PEN_LAYER RECTANGLE_LAYER ELLIPSE_LAYER POLYLINE_LAYER STROKE_LAYER CLOSE_GAP_LAYER CENTERLINE_EXTRACTOR_LAYER

// import FLASH_LAYER ILLUSTRATOR_LAYER BITMAP_LAYER US_LINEART_LAYER US_COLORART_LAYER

◆ vector_layer_create_at()

OMC::DrawingLayer* OMC::DrawingAccess::vector_layer_create_at ( uint  idx,
const QString &  type 
)

Create a layer at the given index, with the given type.

◆ vector_layer_create_under()

OMC::DrawingLayer* OMC::DrawingAccess::vector_layer_create_under ( OMC::DrawingLayer layer,
const QString &  type 
)

Create a layer of the given type under the destination layer.

Available layer types include the following: UNDEFINED_LAYER

PAINT_LAYER
BRUSH_LAYER
PEN_LAYER
RECTANGLE_LAYER
ELLIPSE_LAYER
POLYLINE_LAYER
STROKE_LAYER
CLOSE_GAP_LAYER
CENTERLINE_EXTRACTOR_LAYER

FLASH_LAYER
ILLUSTRATOR_LAYER
BITMAP_LAYER
US_LINEART_LAYER
US_COLORART_LAYER

◆ vector_layer_erase() [1/2]

void OMC::DrawingAccess::vector_layer_erase ( const OMC::DrawingVectorLayer layer)

Erases all the strokes of the given layer.

◆ vector_layer_erase() [2/2]

void OMC::DrawingAccess::vector_layer_erase ( const QList< OMC::DrawingVectorStroke *>  layers)

Erases all the provided strokes.

◆ vector_layer_erase_at()

void OMC::DrawingAccess::vector_layer_erase_at ( uint  idx)

Erase the node at the given position.

◆ vector_layer_move()

void OMC::DrawingAccess::vector_layer_move ( const OMC::DrawingVectorLayer sourceLayer,
const OMC::DrawingVectorLayer targetLayer 
)

Moves all the strokes from the source layer to the target layer.

◆ vector_layer_paste_at()

void OMC::DrawingAccess::vector_layer_paste_at ( uint  idx,
OMC::DrawingLayer layer 
)

Copy i_node and all of its children in the current drawing at the given position.

◆ vector_layers_create()

QList<OMC::DrawingVectorLayer*> OMC::DrawingAccess::vector_layers_create ( const QVariant &  genericDrawingDefinition)

Creates layers with a generic layer definition object.

Generic layer creation in the style of javascripts "createLayers" function.

The generic description of the vector layers are in the form:

[
{ "under" : True/False, #Is the new layer(s) generated above or below the reference_layer
"reference_layer" : OMC::DrawingVectorLayer(), #The reference layer, where in relation the new layers are generated.
"strokes" : [ #List of strokes to create
{
"line_style" : OMC::DrawingVectorLineStyle(), #The linestyle used for the stroke, can be None or omitted altogether.
"path" : OMC::BezierPath() #The bezier path to be used for the generated strokes.
"colour_right" : OMC::DrawingVectorColour(), #The colour object used when painting on the right side of the stroke.
"colour_left" : OMC::DrawingVectorColour() #The colour object used when painting on the left side of the stroke.
}
],
"masks" : [
{
"path" : OMC::BezierPath(), #The closed bezier path to be used for the a mask on the generated strokes above.
"holes" : [
OMC::BezierPath(),
]
}
]
}
]
from ToonBoom import harmony
sess = harmony.session()
proj = sess.project
elem = proj.elements[2] #Getting an element by ID
elem_drawing = elem.drawings[0] #Get the first available drawing
vector_drawing = elem_drawing.drawing #Get the associated vector drawing from the element.
vector_lineart = drawing[2]
strk = lineart[0].strokes[0]
line_style = strk.line_style #Copy the line style of this stroke.
fill_colour = strk.colour_right #Copy the fill of this stroke.
access = harmony.DrawingAccess()
access.vector_begin_operations( lineart )
access.vector_layers_create(
[
{ "under" : False,
"reference_layer" : lineart[0],
"strokes" : [
{
"line_style" : line_style,
"path" : harmony.BezierPath.create_circle( 0, 0, 100 + (0.25*1000), 10 )
},
{
"line_style" : line_style,
"colour_right" : fill_colour,
"path" : harmony.BezierPath.create_circle( 0, 0, 100 + (0.5*1000), 10 )
},
],
"masks" :
[
{ "path" : harmony.BezierPath.create_circle( 0, 0, 100 + (0.25*1000), 10 )
}
]
},
{ "under" : False,
"reference_layer" : lineart[0],
"strokes" : [
{
"line_style" : line_style,
"path" : harmony.BezierPath.create_circle( 0, 0, 100 + (0.75*1000), 10 )
},
{
"line_style" : line_style,
"colour_right" : fill_colour,
"path" : harmony.BezierPath.create_circle( 0, 0, 100 + (1.0*1000), 10 )
},
],
"masks" :
[
{ "path" : harmony.BezierPath.create_circle( 0, 0, 100 + (0.75*1000), 10 )
}
]
}
]
)
access.vector_end_operations()

◆ vector_layers_merge() [1/2]

OMC::DrawingVectorLayer* OMC::DrawingAccess::vector_layers_merge ( )

Merge all layers in the OMC::DrawingVectorArtLayer.

◆ vector_layers_merge() [2/2]

OMC::DrawingVectorLayer* OMC::DrawingAccess::vector_layers_merge ( QList< OMC::DrawingVectorLayer *>  layers)

Merge the given layers in the OMC::DrawingVectorArtLayer.

Member Data Documentation

◆ colour_respect_sticky

bool OMC::DrawingAccess::colour_respect_sticky
readwrite

True if sticky colours should be respected.

Identifies whether colour opertaions will respect the sticky colours.

Inheritance diagram for OMC::DrawingAccess:
Collaboration diagram for OMC::DrawingAccess: