QCAD
Open Source 2D CAD
QCAD Simple API

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: 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, void color, void linetype, void lineweight)
 Adds the given RShape to the drawing as a new entity using current layer and attributes. More...
 
void addShapes (void shapes)
 Adds the given RShapes to the drawing as new entities 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 addXLine (void startPoint, void directionVector)
 Adds an infinite line to the drawing. More...
 
void autoZoom ()
 Auto zoom. More...
 
void createDocument ()
 Creates an (off-screen) document. More...
 
void createDocumentInterface ()
 Creates an (off-screen) document with a document interface that can be used to import / export to / from files or graphics scenes and views. More...
 
void deleteObject (void obj)
 Deletes the given RObject from the drawing. More...
 
void disableInput ()
 Disables the main application window to prevent user input. More...
 
void enableInput ()
 Enables the main application window to allow 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 getDouble (void title, void prompt, void value, void prec, void lower, void upper)
 Display an input dialog box and return a double. More...
 
void getGraphicsView ()
 Returns the current or last active RGraphicsView. More...
 
void getInt (void title, void prompt, void value, void step, void lower, void upper)
 Display an input dialog box and return an integer. More...
 
void getIntersectionPoints (void e1, void e2, void limited)
 Returns intersection points between the two given entities or shapes. More...
 
void getItem (void title, void prompt, void items, void idx, void splitStr)
 Display a combo drop down box and return item. 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 getText (void title, void prompt, void txt)
 Display an input dialog box and return string. More...
 
void getTransactionDocument ()
 Returns the RDocument the current transaction applies to or the current document or undefined. More...
 
void getTransactionDocumentInterface ()
 Returns the RDocumentInterface the current transaction applies to or the current document interface or undefined. More...
 
void hasLayer (void name)
 Checks if the given layer exists. 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 setCurrentColor (void color)
 Sets the current color for newly added entities. More...
 
void setCurrentLayer (void layerName)
 Sets the current layer to the given layer. 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

◆ addArc()

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

Adds an arc to the drawing.

addArc(cx,cy, radius, startAngle, endAngle, reversed)
addArc([cx,cy], radius, startAngle, endAngle, reversed)
addArc(new RVector(cx,cy), radius, startAngle, endAngle, reversed)

◆ addCircle()

void addCircle ( void  center,
void  radius 
)

Adds a circle to the drawing.

addCircle(cx,cy, radius)
addCircle([cx,cy], radius)
addCircle(new RVector(cx,cy), radius)

◆ addEntity()

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.

◆ addLayer()

void addLayer ( void  name,
void  colorName,
void  linetypeName,
void  lineWeight 
)

Adds a layer to the drawing.

addLayer("MyLayer1")
addLayer("MyLayer2", "white", "CONTINUOUS", RLineweight.Weight025)

◆ addLine()

void addLine ( void  startPoint,
void  endPoint 
)

Adds a line to the drawing.

addLine(x1,y1, x2,y2)
addLine([x1,y1], [x2,y2])
addLine(new RVector(x1,y1), new RVector(x2,y2))

◆ addObject()

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.

◆ addPoint()

void addPoint ( void  position)

Adds a point to the drawing.

addPoint([x,y])
addPoint(new RVector(x,y))

◆ addPolyline()

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 implicitly closed polyline. Default is false.
relativeTrue to treat all coordinates as relative. The first coordinate is always absolute. Default is false.
addPolyline([[x1,y1],[x2,y2],[x3,y3]], false)
addPolyline([ [ 100 , 0 ], [ 20 , -10 , 1 ], [ 0 , 40 , 0 , true ], [ -20 , -10 , 1 , true ] ])
addPolyline([new RVector(x1,y1),new RVector(x2,y2),new RVector(x3,y3)], closed, relative)
addPolyline([[new RVector(x1,y1),bulge1,rel1],[new RVector(x2,y2),bulge2,rel2],[new RVector(x3,y3),bulge3,rel3]], closed, relative)

◆ addShape()

void addShape ( void  shape,
void  color,
void  linetype,
void  lineweight 
)

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.
addShape(shape)
addShape(shape, new RColor(255,0,0), "CONTINUOUS", 0.05)

◆ addShapes()

void addShapes ( void  shapes)

Adds the given RShapes to the drawing as new entities using current layer and attributes.

Returns
The added entities. The entities do not yet have valid IDs if they were added within a transaction.

◆ addSimpleText()

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)
addSimpleText(text, x, y, height, angle, font, vAlign, hAlign, bold, italic)
addSimpleText(text, [x, y], height, angle, font, vAlign, hAlign, bold, italic)
addSimpleText(text, new RVector(x, y), height, angle, font, vAlign, hAlign, bold, italic)

◆ addSpline()

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.
addSpline([[x1,y1],[x2,y2],[x3,y3]], false)
addSpline([new RVector(x1,y1),new RVector(x2,y2),new RVector(x3,y3)], false)

◆ addXLine()

void addXLine ( void  startPoint,
void  directionVector 
)

Adds an infinite line to the drawing.

The two vectors are the base point and the direction vector (point relative to base point)

addXLine(x1,y1, dx,dy)
addXLine([x1,y1], [dx,dy])
addXLine(new RVector(x1,y1), new RVector(dx,dy))

◆ autoZoom()

void autoZoom ( )

Auto zoom.

◆ createDocument()

void createDocument ( )

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

◆ createDocumentInterface()

void createDocumentInterface ( )

Creates an (off-screen) document with a document interface that can be used to import / export to / from files or graphics scenes and views.

Returns
new empty RDocumentInterface with default settings

◆ deleteObject()

void deleteObject ( void  obj)

Deletes the given RObject from the drawing.

Returns
The added object. The object does not yet have a valid ID if it was added within a transaction.

◆ disableInput()

void disableInput ( )

Disables the main application window to prevent user input.

◆ enableInput()

void enableInput ( )

Enables the main application window to allow user input.

◆ endTransaction()

void endTransaction ( )

Ends a transaction.

See also
startTransaction
Returns
RTransaction object containing information about the transaction.

◆ getDocument()

void getDocument ( )

Returns the current RDocument or undefined.

◆ getDocumentInterface()

void getDocumentInterface ( )

Returns the current RDocumentInterface or undefined.

◆ getDouble()

void getDouble ( void  title,
void  prompt,
void  value,
void  prec,
void  lower,
void  upper 
)

Display an input dialog box and return a double.

Parameters
title- Title of dialog box
prompt- Prompt to display.
value- Value to display in the input box (Default = 0.0).
prec- Spin button precision (Default = 1).
lower- minimum value (Default = -2147483647)
upper- maximum value (Default = 2147483647)

◆ getGraphicsView()

void getGraphicsView ( )

Returns the current or last active RGraphicsView.

◆ getInt()

void getInt ( void  title,
void  prompt,
void  value,
void  step,
void  lower,
void  upper 
)

Display an input dialog box and return an integer.

Parameters
title- Title of dialog box
prompt- Prompt to display.
value- Value to display in the input box (Default = 0).
step- Spin box step value (Default = 1).
lower- minimum value (Default = -2147483647)
upper- maximum value (Default = 2147483647)

◆ getIntersectionPoints()

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).

◆ getItem()

void getItem ( void  title,
void  prompt,
void  items,
void  idx,
void  splitStr 
)

Display a combo drop down box and return item.

Parameters
title- Title of dialog box
prompt- Prompt to display.
items- List of items to display in the combo box.
idx- index of item to display (Default = 0)
splitStr- Character or string to split the items (Default = ",")

◆ getMainWindow()

void getMainWindow ( )

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

◆ getOperation()

void getOperation ( )

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

◆ getText()

void getText ( void  title,
void  prompt,
void  txt 
)

Display an input dialog box and return string.

Parameters
title- Title of dialog box
prompt- Prompt to display.
txt- Text to display in the input box.

◆ getTransactionDocument()

void getTransactionDocument ( )

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

◆ getTransactionDocumentInterface()

void getTransactionDocumentInterface ( )

Returns the RDocumentInterface the current transaction applies to or the current document interface or undefined.

◆ hasLayer()

void hasLayer ( void  name)

Checks if the given layer exists.

hasLayer("MyLayer1")

◆ isInputEnabled()

void isInputEnabled ( )

Returns true if user input is enabled.

◆ lengthen()

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

◆ mirror()

void mirror ( void  e,
void  axis 
)

Mirrors the given entity or shape at the given axis.

Parameters
eEntity, entity ID or shape.
mirror(entity, x1,y1, x2,y2)
mirror(entity, [x1,y1], [x2,y2])
mirror(entity, new RVector(x1,y1), new RVector(x2,y2))
mirror(entity, new RLine(x1,y1, x2, y2))
mirror(entity, [new RVector(x1,y1), new RVector(x2,y2)])
mirror(entity, [[x1,y1], [x2,y2]])

◆ move()

void move ( void  e,
void  offset 
)

Moves the given entity or shape by the given offset.

Parameters
eEntity, entity ID or shape.
move(entity, x,y)
move(entity, [x,y])
move(entity, new RVector(x,y))

◆ paste()

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

◆ rotate()

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.
rotate(entity, angle, cx,cy)
rotate(entity, angle, [cx,cy])
rotate(entity, angle, new RVector(cx,cy))

◆ scale()

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.
scale(entity, factor, cx,cy)
scale(entity, factor, [cx,cy])
scale(entity, factor, new RVector(cx,cy))

◆ setCurrentColor()

void setCurrentColor ( void  color)

Sets the current color for newly added entities.

setCurrentColor(new RColor(255, 255, 255))
setCurrentColor(new RColor("white"))
setCurrentColor(255, 255, 255)

◆ setCurrentLayer()

void setCurrentLayer ( void  layerName)

Sets the current layer to the given layer.

Parameters
layerNameLayer name or ID.

◆ sleep()

void sleep ( void  d)

Sleeps for the indicated time in milliseconds.

◆ startTransaction()

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).
for (...) {
addLine(...);
}

◆ trim()

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.
trim(trimEntity, x1,y1, limitingEntity, x2,y2, trimBoth)
trim(trimEntity, [x1,y1], limitingEntity, [x2,y2], trimBoth)
trim(trimEntity, new RVector(x1,y1), limitingEntity, new RVector(x2,y2), trimBoth)

◆ update()

void update ( )

Keeps the user interface up to date during long operations.

Deprecated:

User input must be disabled using disableInput before calling update.

◆ warning()

void warning ( void  msg)

Prints a warning to stdout.

◆ zoomTo()

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.

zoomTo(entity)
zoomTo(entity, margin)
zoomTo(entityId)
zoomTo(entityId, margin)
zoomTo(shape)
zoomTo(shape, margin)
zoomTo([x1,y1], [x2,y2])
zoomTo([x1,y1], [x2,y2], margin)
zoomTo(new RBox(x1,y1, x2,y2))
zoomTo(new RBox(x1,y1, x2,y2), margin)
addPoint
void addPoint(void position)
Adds a point to the drawing.
Definition: simple_create.js:78
addPolyline
void addPolyline(void points, void closed, void relative)
Adds a polyline to the drawing.
Definition: simple_create.js:107
setCurrentColor
void setCurrentColor(void color)
Sets the current color for newly added entities.
Definition: simple_create.js:190
zoomTo
void zoomTo(void p1, void p2, void p3, void p4, void p5)
Zooms to the given entity.
Definition: simple_view.js:27
rotate
void rotate(void e, void angle, void center)
Rotates the given entity or shape by the given angle around the given center.
Definition: simple_modify.js:109
RVector
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
addShape
void addShape(void shape, void color, void linetype, void lineweight)
Adds the given RShape to the drawing as a new entity using current layer and attributes.
Definition: simple_create.js:155
endTransaction
void endTransaction()
Ends a transaction.
Definition: simple_transaction.js:40
trim
void trim(void trimEntity, void trimClickPos, void limitingEntity, void limitingClickPos, void trimBoth)
Trims the given entity / entities or shape(s).
Definition: simple_modify.js:62
addCircle
void addCircle(void center, void radius)
Adds a circle to the drawing.
Definition: simple_create.js:48
addArc
void addArc(void center, void radius, void startAngle, void endAngle, void reversed)
Adds an arc to the drawing.
Definition: simple_create.js:141
addLine
void addLine(void startPoint, void endPoint)
Adds a line to the drawing.
Definition: simple_create.js:27
RLine
Low-level mathematical representation of a line.
Definition: RLine.h:41
addLayer
void addLayer(void name, void colorName, void linetypeName, void lineWeight)
Adds a layer to the drawing.
Definition: simple_create.js:219
addSpline
void addSpline(void points, void closed)
Adds a spline to the drawing.
Definition: simple_create.js:169
mirror
void mirror(void e, void axis)
Mirrors the given entity or shape at the given axis.
Definition: simple_modify.js:42
addSimpleText
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.
Definition: simple_create.js:129
RLineweight
Definition: RLineweight.h:41
hasLayer
void hasLayer(void name)
Checks if the given layer exists.
Definition: simple_create.js:66
addXLine
void addXLine(void startPoint, void directionVector)
Adds an infinite line to the drawing.
Definition: simple_create.js:15
RBox
Represents a box e.g.
Definition: RBox.h:43
move
void move(void e, void offset)
Moves the given entity or shape by the given offset.
Definition: simple_modify.js:25
scale
void scale(void e, void factor, void focusPoint)
Scales the given entity or shape by the given factor with the given focus point.
Definition: simple_modify.js:76
startTransaction
void startTransaction(void d)
Starts a transaction.
Definition: simple_transaction.js:31
RColor
Color.
Definition: RColor.h:44