QCAD
Open Source 2D CAD
QCAD Simple API

This module defines the QCAD Simple API in ECMAScript. More...

Functions

void addArc (void center, void radius, void startAngle, void endAngle, void reversed)
 Adds an arc to the drawing. More...
 
void addCircle (void center, void radius)
 Adds a circle to the drawing. More...
 
void addEntity (void entity)
 Adds the given REntity to the drawing using layer and attributes as set by the entity. More...
 
void addLayer (void name, void colorName, void linetypeName, void lineWeight)
 Adds a layer to the drawing. More...
 
void addLine (void startPoint, void endPoint)
 Adds a line to the drawing. More...
 
void addObject (void obj)
 Adds the given RObject to the drawing. More...
 
void addPoint (void position)
 Adds a point to the drawing. More...
 
void addPolyline (void points, void closed, void relative)
 Adds a polyline to the drawing. More...
 
void addShape (void shape)
 Adds the given RShape to the drawing as a new entity using current layer and attributes. More...
 
void addSimpleText (void text, void position, void height, void angle, void font, void vAlign, void hAlign, void bold, void italic)
 Adds a simple text to the drawing. More...
 
void addSpline (void points, void closed)
 Adds a spline to the drawing. More...
 
void autoZoom ()
 Auto zoom. More...
 
void createOffScreenDocument ()
 Creates an off-screen document. More...
 
void disableInput ()
 Disables the main application window to prevent user input. More...
 
void enableInput ()
 Enables the main application window to prevent user input. More...
 
void endTransaction ()
 Ends a transaction. More...
 
void getDocument ()
 Returns the current RDocument or undefined. More...
 
void getDocumentInterface ()
 Returns the current RDocumentInterface or undefined. More...
 
void getGraphicsView ()
 Returns the current or last active RGraphicsView. More...
 
void getIntersectionPoints (void e1, void e2, void limited)
 Returns intersection points between the two given entities or shapes. More...
 
void getMainWindow ()
 Returns a pointer to the main application window (RMainWindowQt). More...
 
void getOperation ()
 Returns the current operation if we are in a transaction or a new operation. More...
 
void getTransactionDocument ()
 Returns the RDocument the current transaction applies to or the current document or undefined. More...
 
void isInputEnabled ()
 Returns true if user input is enabled. More...
 
void lengthen (void entity, void start, void amount)
 Lengthens of shortens the given entity or shape. More...
 
void mirror (void e, void axis)
 Mirrors the given entity or shape at the given axis. More...
 
void move (void e, void offset)
 Moves the given entity or shape by the given offset. More...
 
void paste (void docSource, void diDestination, void offset, void scale, void rotation, void flipHorizontal, void flipVertical, void toCurrentLayer, void overwriteLayers, void overwriteBlocks)
 Pastes the given document into the current document or into the second given document. More...
 
void rotate (void e, void angle, void center)
 Rotates the given entity or shape by the given angle around the given center. More...
 
void scale (void e, void factor, void focusPoint)
 Scales the given entity or shape by the given factor with the given focus point. More...
 
void sleep (void d)
 Sleeps for the indicated time in milliseconds. More...
 
void startTransaction (void d)
 Starts a transaction. More...
 
void trim (void trimEntity, void trimClickPos, void limitingEntity, void limitingClickPos, void trimBoth)
 Trims the given entity / entities or shape(s). More...
 
void update ()
 Keeps the user interface up to date during long operations. More...
 
void warning (void msg)
 Prints a warning to stdout. More...
 
void zoomTo (void p1, void p2, void p3, void p4, void p5)
 Zooms to the given entity. More...
 

Detailed Description

This module defines the QCAD Simple API in ECMAScript.

The QCAD Simple API is meant to simplify common tasks such as adding entities. To use the QCAD Simple API in your scripts, include the file simple.js in your script:

include("simple.js");

Function Documentation

void addArc ( void  center,
void  radius,
void  startAngle,
void  endAngle,
void  reversed 
)

Adds an arc to the drawing.

1 addArc(cx,cy, radius, startAngle, endAngle, reversed)
2 addArc([cx,cy], radius, startAngle, endAngle, reversed)
3 addArc(new RVector(cx,cy), radius, startAngle, endAngle, reversed)
void addCircle ( void  center,
void  radius 
)

Adds a circle to the drawing.

1 addCircle(cx,cy, radius)
2 addCircle([cx,cy], radius)
3 addCircle(new RVector(cx,cy), radius)
void addEntity ( void  entity)

Adds the given REntity to the drawing using layer and attributes as set by the entity.

Returns
The added entity. The entity does not yet have a valid ID if it was added within a transaction.
void addLayer ( void  name,
void  colorName,
void  linetypeName,
void  lineWeight 
)

Adds a layer to the drawing.

1 addLayer("MyLayer1")
2 addLayer("MyLayer2", "white", "CONTINUOUS", RLineweight.Weight025)
void addLine ( void  startPoint,
void  endPoint 
)

Adds a line to the drawing.

1 addLine(x1,y1, x2,y2)
2 addLine([x1,y1], [x2,y2])
3 addLine(new RVector(x1,y1), new RVector(x2,y2))
void addObject ( void  obj)

Adds the given RObject to the drawing.

Returns
The added object. The object does not yet have a valid ID if it was added within a transaction.
void addPoint ( void  position)

Adds a point to the drawing.

1 addPoint(x,y)
2 addPoint([x,y])
3 addPoint(new RVector(x,y))
void addPolyline ( void  points,
void  closed,
void  relative 
)

Adds a polyline to the drawing.

Author
Andrew Mustun
tukuyomi
Parameters
pArray of type [ [ x, y, bulge, relative ], ..., [ ... ] ] or [ [ vector, bulge, relative ], ..., [ ... ] ] Where: x: X coordinate y: Y coordinate vector: RVector with position of vertex bulge: Bulge for next segment after vertex, defaults to 0.0. relative: True if this vector's coordinates are relative to the previous coordinates, defaults to false.
closedTrue for an implicitely closed polyline. Default is false.
relativeTrue to treat all coordinates as relative. The first coordinate is always absolute. Default is false.
1 addPolyline([[x1,y1],[x2,y2],[x3,y3]], false)
2 addPolyline([ [ 100 , 0 ], [ 20 , -10 , 1 ], [ 0 , 40 , 0 , true ], [ -20 , -10 , 1 , true ] ])
3 addPolyline([new RVector(x1,y1)],new RVector(x2,y2),new RVector(x3,y3)], closed, relative)
4 addPolyline([new RVector(x1,y1),bulge1,rel1],[new RVector(x2,y2),bulge2,rel2],[new RVector(x3,y3),bulge3,rel3]], closed, relative)
void addShape ( void  shape)

Adds the given RShape to the drawing as a new entity using current layer and attributes.

Returns
The added entity. The entity does not yet have a valid ID if it was added within a transaction.
void addSimpleText ( void  text,
void  position,
void  height,
void  angle,
void  font,
void  vAlign,
void  hAlign,
void  bold,
void  italic 
)

Adds a simple text to the drawing.

Parameters
textText string.
positionposition
heightText height (defaults to 1)
angleText angle (defaults to 0)
fontFont (defaults to "standard")
vAlignVertical alignment (defaults to RS.VAlignTop)
hAlignHorizontal alignment (defaults to RS.HAlignLeft)
boldTrue for bold text (TTF fonts only)
italicTrue for italic text (TTF fonts only)
1 addSimpleText(text, x, y, height, angle, font, vAlign, hAlign, bold, italic)
2 addSimpleText(text, [x, y], height, angle, font, vAlign, hAlign, bold, italic)
3 addSimpleText(text, new RVector(x, y), height, angle, font, vAlign, hAlign, bold, italic)
void addSpline ( void  points,
void  closed 
)

Adds a spline to the drawing.

Parameters
fitPointsArray of RVector or [x,y] tuples.
closedTrue for a closed, periodic spline.
1 addSpline([[x1,y1],[x2,y2],[x3,y3]], false)
2 addSpline([new RVector(x1,y1)],new RVector(x2,y2),new RVector(x3,y3)], false)
void autoZoom ( )

Auto zoom.

void createOffScreenDocument ( )

Creates an off-screen document.

Such a document can be filled with objects and saved to disk, pasted into the current document, etc.

Returns
new empty RDocument with default settings
void disableInput ( )

Disables the main application window to prevent user input.

void enableInput ( )

Enables the main application window to prevent user input.

void endTransaction ( )

Ends a transaction.

See also
startTransaction
Returns
RTransaction object containing information about the transaction.
void getDocument ( )

Returns the current RDocument or undefined.

void getDocumentInterface ( )

Returns the current RDocumentInterface or undefined.

void getGraphicsView ( )

Returns the current or last active RGraphicsView.

void getIntersectionPoints ( void  e1,
void  e2,
void  limited 
)

Returns intersection points between the two given entities or shapes.

Parameters
e1First entity, entity ID or shape.
e2Second entity, entity ID or shape.
limitedTrue to only return intersection points that lay on the given entities or shapes (visible intersections).
void getMainWindow ( )

Returns a pointer to the main application window (RMainWindowQt).

void getOperation ( )

Returns the current operation if we are in a transaction or a new operation.

void getTransactionDocument ( )

Returns the RDocument the current transaction applies to or the current document or undefined.

void isInputEnabled ( )

Returns true if user input is enabled.

void lengthen ( void  entity,
void  start,
void  amount 
)

Lengthens of shortens the given entity or shape.

Parameters
entityEntity, entity ID or shape to lengthen
startTrue to extend at start point, false for end point
amountAmount to lengthen or negative value to shorten
void mirror ( void  e,
void  axis 
)

Mirrors the given entity or shape at the given axis.

Parameters
eEntity, entity ID or shape.
1 mirror(entity, x1,y1, x2,y2)
2 mirror(entity, [x1,y1], [x2,y2])
3 mirror(entity, new RVector(x1,y1), new RVector(x2,y2))
4 mirror(entity, new RLine(x1,y1, x2, y2))
5 mirror(entity, [new RVector(x1,y1), new RVector(x2,y2)])
6 mirror(entity, [[x1,y1], [x2,y2]])
void move ( void  e,
void  offset 
)

Moves the given entity or shape by the given offset.

Parameters
eEntity, entity ID or shape.
1 move(entity, x,y)
2 move(entity, [x,y])
3 move(entity, new RVector(x,y))
void paste ( void  docSource,
void  diDestination,
void  offset,
void  scale,
void  rotation,
void  flipHorizontal,
void  flipVertical,
void  toCurrentLayer,
void  overwriteLayers,
void  overwriteBlocks 
)

Pastes the given document into the current document or into the second given document.

Parameters
docSourceRDocument to paste
docDestinationRDocument to paste into (or undefined for current document)
offsetOffset RVector or [x,y] array
scaleScale factor
rotationRotation angle in degrees
flipHorizontalTrue to flip horizontally
flipVertialTrue to flip vertically
toCurrentLayerPaste all entities to the current layer of the target document
overwriteLayersOverwrite existing layers in the target document with layers from the source document
overwriteBlocksOverwrite existing blocks in the target document with blocks from the source document
void rotate ( void  e,
void  angle,
void  center 
)

Rotates the given entity or shape by the given angle around the given center.

Parameters
eEntity, entity ID or shape.
1 rotate(entity, angle, cx,cy)
2 rotate(entity, angle, [cx,cy])
3 rotate(entity, angle, new RVector(cx,cy))
void scale ( void  e,
void  factor,
void  focusPoint 
)

Scales the given entity or shape by the given factor with the given focus point.

Parameters
eEntity, entity ID or shape.
1 scale(entity, factor, cx,cy)
2 scale(entity, factor, [cx,cy])
3 scale(entity, factor, new RVector(cx,cy))
void sleep ( void  d)

Sleeps for the indicated time in milliseconds.

void startTransaction ( void  d)

Starts a transaction.

This can increase performance when adding multiple entities. Entities are added in one transaction when endTransaction is called.

Parameters
dRDocument or RDocumentInterface to apply the transaction to (defaults to current document).
1 startTransaction();
2 for (...) {
3  addLine(...);
4 }
5 endTransaction();
void trim ( void  trimEntity,
void  trimClickPos,
void  limitingEntity,
void  limitingClickPos,
void  trimBoth 
)

Trims the given entity / entities or shape(s).

Parameters
trimEntityEntity, entity ID or shape to trim
trimClickPosPosition clicked when choosing trim entity.
limitingEntityEntity, entity ID or shape that limits the trimming.
limitingClickPosPosition clicked when choosing limiting entity.
trimBothTrue to trim both entities.
Returns
RTransaction created by operation if no operation is given. If op is given, undefined is returned.
1 trim(trimEntity, x1,y1, limitingEntity, x2,y2, trimBoth)
2 trim(trimEntity, [x1,y1], limitingEntity, [x2,y2], trimBoth)
3 trim(trimEntity, new RVector(x1,y1), limitingEntity, new RVector(x2,y2), trimBoth)
void update ( )

Keeps the user interface up to date during long operations.

User input must be disabled using disableInput before calling update.

void warning ( void  msg)

Prints a warning to stdout.

void zoomTo ( void  p1,
void  p2,
void  p3,
void  p4,
void  p5 
)

Zooms to the given entity.

Returns the bounding box of the given entity or undefined.

1 zoomTo(entity)
2 zoomTo(entity, margin)
3 zoomTo(entityId)
4 zoomTo(entityId, margin)
5 zoomTo(shape)
6 zoomTo(shape, margin)
7 zoomTo([x1,y1], [x2,y2])
8 zoomTo([x1,y1], [x2,y2], margin)
9 zoomTo(new RBox(x1,y1, x2,y2))
10 zoomTo(new RBox(x1,y1, x2,y2), margin)