How to offset polyline entity use ECMAScript ?

Use this forum to ask questions about how to do things in QCAD.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
vn38minhtran
Registered Member
Posts: 1
Joined: Thu Jun 25, 2015 9:48 am

How to offset polyline entity use ECMAScript ?

Post by vn38minhtran » Thu Jun 25, 2015 10:11 am

Code: Select all

  var entity = [any entity];
  var pos = [any pos];
  var shape = entity.getClosestSimpleShape(pos);
  if(!isLineBasedShape(shape) && !isArcShape(shape) && !isCircleShape(shape) && !isEllipseShape(shape)){
    print('Shape don\'t support.');
  }
  var offsetShapes = ShapeAlgorithms.getOffsetShapes(shape, distance, 1, pos);
  for (var i=0; i<offsetShapes.length; ++i) {
    var offsetShapeEntity;
    if(isLineBasedShape(offsetShapes[i])){
      offsetShapeEntity = new RLineEntity(document, new RLineData(offsetShapes[i].getStartPoint(), offsetShapes[i].getEndPoint()));
    }else{
      offsetShapeEntity = shapeToEntity(document, offsetShapes[i]);
    }
    if (!isNull(offsetShapeEntity)) {
      op.addObject(offsetShapeEntity);
    }
  }
  op.apply(document);
With code above polyline entity don't offset correct.

User avatar
andrew
Site Admin
Posts: 9063
Joined: Fri Mar 30, 2007 6:07 am

Re: How to offset polyline entity use ECMAScript ?

Post by andrew » Fri Jun 26, 2015 9:03 am

ShapeAlgorithms.getOffsetShapes only supports lines, arcs and ellipses.

If you are using QCAD Professional, you can use the OffsetProWorker API to offset polylines (the QCAD Community Edition does not support polyline offsets):
include("scripts/Pro/Modify/OffsetPro/OffsetProWorker.js");

...

/**
 * \param oriShape Original polyline shape
 * \param oriSegment Segment of the original polyline that was clicked by the user (used to determine offset direction)
 * \param distance Distance to offset
 * \param number Number of offset polylines to create, each with a distance of distance * n
 * \param pos Position that was clicked by the user (used to determine offset direction)
 * \param forceInside Force offset direction for closed polylines: true: inside, false: outside, undefined: determined by pos
 * \param joinType RS.JoinBevel, RS.JoinRound, RS.JoinMiter
 * \param endType RS.EndClosedPolygon, RS.EndClosedLine, RS.EndOpenButt, RS.EndOpenSquare, RS.EndOpenRound, RS.EndOpenSingle
 * \param interpolateArcs True to interpolate arcs with line segments (more reliable offset result, but more segments)
 * \param verify True to verify result, print errors through EAction.handleUserWarning
 * \param preview True to return preview for offset.
 */
var worker = new OffsetProWorker(oriShape, oriSegment, distance, number, pos, forceInside, joinType, endType, interpolateArcs, verify, preview);
var polylines = worker.getOffsetShapes();

CVH
Premier Member
Posts: 3478
Joined: Wed Sep 27, 2017 4:17 pm

Re: How to offset polyline entity use ECMAScript ?

Post by CVH » Thu Dec 07, 2023 6:38 am


Post Reply

Return to “QCAD 'How Do I' Questions”