Author Topic: [XDRX-Function(6)] Programming by Dragging Grips (1)  (Read 576 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Bull Frog
  • Posts: 424
[XDRX-Function(6)] Programming by Dragging Grips (1)
« on: December 04, 2023, 10:53:52 AM »
AutoCAD's grip editing is very convenient. Many times users complete work by dragging grips. Can LISP be simulated?
Through pinch programming, I don’t need to consider the data modification of so many entities. I can just follow the thinking of ordinary users and drag the points I want to where I want to achieve the goal.

The following animation demonstrates the process of user operation to extend a polyline to the target:



We simulate it by writing code...

Code - C++: [Select]
  1. ARX provides a method:
  2. AcDbEntity::moveStretchPointsAt
  3. Acad::ErrorStatus moveStretchPointsAt(
  4.      const AcDbIntArray & indices,
  5.      const AcGeVector3d& offset
  6. );
  7. Description
  8. Function usage
  9. This function is intended to be called by AutoCAD during execution of a stretch command in which the entity has been selected. However, it is certainly possible for ObjectARX applications to call this function.
  10.  
================

The function corresponding to XDRX API is: xdrx-entity-movestretchpoint,

We use it to get work done

The following is the demo code, which simulates the user operation process
1. Pick the target curve
2. Pick the polyline extension segment,
      The point picked by the mouse determines the vertex index of the beginning of the current segment (grip 1)
      Through the vertex index, find the index of the next vertex and the index of the previous vertex,
      Find the two endpoints of two extended straight lines,
      Find the intersection point with the target curve respectively, which is the target point we want to drag to.
3. Use xdrx-entity-movestretchpoint to drag the two vertices to the required place to complete the "extension" of the local segment of the polyline.

The following animation demonstrates the process of code execution to simulate user operations.



Code - Auto/Visual Lisp: [Select]
  1. (xdrx_entity_movestretchpoint <ent> <displacement> <grip-point no>)
  2. (xdrx_entity_movestretchpoint e (mapcar '- p2 p1) 0)
  3. Move the 0th grip point of the entity to the vector distance,
  4. vector (including direction, length)
  5.  

Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.   (if
  3.     (and
  4.       (setq dest (car (xdrx-entsel "\nPick Dest Curve<Exit>:" '((0 . "*line")))))
  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.       )
  21.       (setq int1 (xdrx-entity-intersectwith (list p0 p1) dest 3))
  22.       (setq int2 (xdrx-entity-intersectwith (list p2 p3) dest 3))
  23.     )
  24.      (progn
  25.        (xdrx-entity-movestretchpoint src (mapcar '- (car int1) p1) inx)
  26.        (xdrx-entity-movestretchpoint src (mapcar '- (car int2) p2) nextInx)
  27.      )
  28.   )
  29.   (princ)
  30. )

Many times, by operating GRIP points, simple codes can complete many complex tasks, which is achieved by simulating user operations.
« Last Edit: December 04, 2023, 01:30:17 PM by xdcad »
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
[XDrx-Sub Forum]
https://www.theswamp.org/index.php?board=78.0
https://github.com/xdcad/XDrx-API
http://bbs.xdcad.net