Author Topic: [XDrX-Function(7)] Programming by Dragging Grips (2)  (Read 744 times)

0 Members and 1 Guest are viewing this topic.


  • Swamp Rat
  • Posts: 527
[XDrX-Function(7)] Programming by Dragging Grips (2)
« on: December 04, 2023, 11:34:30 AM »
Programming by Dragging Grips (1)

Last time I talked about simulating user operations and editing pinch points to complete the operation. Please see the above post for the specific process.

Now we are simulating one more time, the simulation process of fitting the rectangular polyline and the circle boundary

The process that the user wants to do:

Drag the polyline clamp to the circle, and then use BPOLY, TRIM or other commands to complete the operation. In fact, it is to find the "Subtract" between the polyline and the circle topology after stretching. We will complete one more difference operation than last time.


If you don’t use simulation and just write code, you need:
1. Calculate the two nearest intersection points of the two straight segments of the polyline and the circle
2. The part of the circle between these two points is the final Overlap. Use the SetIterval of the geometry library to extract the overlapping arc.
3. Reconstruct the polyline using arcs and extended rectangles
It is more complicated than directly simulating the STRETCH, BPOLY, and TRIM commands.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.   (if
  3.     (and
  4.       (setq dest (car (xdrx-entsel "\nPick Dest Curve<Exit>:" '((0 . "circle")))))
  5.       (setq src (xdrx-entsel "\nPick Extend PolySeg<Exit>:" '((0 . "*polyline"))))
  6.       (setq pt  (cadr src)
  7.             src (car src)
  8.       )
  9.       (setq seg (xdrx-getpropertyvalue src "onsegat" pt))
  10.       (setq inx (car seg))
  11.       (setq nextInx (xdrx-getpropertyvalue src "-index+" inx))
  12.       (setq prevInx  (car nextInx)
  13.             nextInx  (cadr nextInx)
  14.             nextInx+ (1+ nextInx)
  15.       )
  16.       (setq p0 (xdrx-getpropertyvalue src "pointat" previnx)
  17.             p1 (xdrx-getpropertyvalue src "pointat" inx)
  18.             p2 (xdrx-getpropertyvalue src "pointat" nextInx)
  19.             p3 (xdrx-getpropertyvalue src "pointat" nextinx+)
  20.       )
  22.       (setq int1 (xdrx-entity-intersectwith (list p0 p1) dest 3))
  23.       (setq int2 (xdrx-entity-intersectwith (list p2 p3) dest 3))
  24.     )
  25.      (progn
  26.        (xdrx_entity_movestretchpoint src (mapcar '- (car int1) p1) inx)
  27.        (xdrx_entity_movestretchpoint src (mapcar '- (car int2) p2) nextInx)
  28.        (setq dest-copy (xdrx-object-clone dest))
  29.        (xdrx-get-subtract src dest-copy)
  30.      )
  31.   )
  32.   (princ)
  33. )
« Last Edit: December 04, 2023, 01:30:47 PM by xdcad »
The code I wrote uses XDRX-API,which can be downloaded from and is updated at any time.