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...
ARX provides a method:
AcDbEntity::moveStretchPointsAt
Acad::ErrorStatus moveStretchPointsAt(
const AcDbIntArray & indices,
const AcGeVector3d& offset
);
Description
Function usage
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.
================
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.
(xdrx_entity_movestretchpoint <ent> <displacement> <grip-point no>)
(xdrx_entity_movestretchpoint e
(mapcar '
- p2 p1
) 0) Move the 0th grip point of the entity to the vector
distance,
vector
(including direction,
length)
(setq dest
(car (xdrx
-entsel "\nPick Dest Curve<Exit>:" '
((0 .
"*line"))))) (setq src
(xdrx
-entsel "\nPick Extend PolySeg<Exit>:" '
((0 .
"*polyline")))) )
(setq seg
(xdrx
-getpropertyvalue src
"onsegat" pt
)) (setq nextInx
(xdrx
-getpropertyvalue src
"-index+" inx
)) )
(setq p0
(xdrx
-getpropertyvalue src
"pointat" previnx
) p1 (xdrx-getpropertyvalue src "pointat" inx)
p2 (xdrx-getpropertyvalue src "pointat" nextInx)
p3 (xdrx-getpropertyvalue src "pointat" nextinx+)
)
(setq int1
(xdrx
-entity
-intersectwith
(list p0 p1
) dest
3)) (setq int2
(xdrx
-entity
-intersectwith
(list p2 p3
) dest
3)) )
(xdrx
-entity
-movestretchpoint src
(mapcar '
- (car int1
) p1
) inx
) (xdrx
-entity
-movestretchpoint src
(mapcar '
- (car int2
) p2
) nextInx
) )
)
)
Many times, by operating GRIP points, simple codes can complete many complex tasks, which is achieved by simulating user operations.