
Use the point monitor to draw and cut out the range frame based on mouse selection, cut out local text, support blocks, attributes, normal text entities, and support UCS.
Add comments to the program code.
================
The program demonstrates:
1. Use of point monitor (dynamic drag).
2. Use of transformation matrix from model space to tile
3.AcGe geometry library method to calculate the midpoint of two points
. . . . . .
================
How to use the XD::Text:IndexAtPoint function:
(XD::Text:IndexAtPoint e p)
parameter:
1.e --- Text entity name (text within the block, attribute entity name)
2.p --- Pick Point (WCS)
Returns: text index information table at the specified point position
For example:
("normal text" 3 ((2311.85 1098.12 0.0) (2449.52 1151.44 0.0) (2398.14 1284.13 0.0) (2260.46 1230.81 0.0)))
1)Text content
2) Pick point text position index (starting from 0)
3) Text bounding box point table (WCS) of the first character after the index position
;|
Function name: XD::Text:IndexAtPoint
Calling format: (XD::Text:IndexAtPoint e pt)
1.Parameter description: e ------ text entity name (inside block, attribute text, ordinary text)
pt ----- point (WCS)
2.Return value: (Text content, index value, single-character bounding box point table)
Function introduction: Get the index position value of the text (in block, attribute, ordinary text) under the mouse click
Function source: original
Function author: Lipboy
Applicable versions: XDRX API
Last updated: 2016-06-26
Note: Index values start from 0
|;
(defun XD::Text:IndexAtPoint
(e pt
/ base box ed i len p2 pos prev tf txt typ v xdir
) (if (setq txt
(xdrx
-getpropertyvalue e
"textstring")) i 0
)
(setq box
(xdrx
-text
-box e
) lastpt base
xdir (xd::entity:xdir e)
)
(setq prev
(xdrx
-string
-mid txt
0 (1+ i
))) p2
(mapcar '
+ base
(xdrx
-vector
-product xdir
(car v
)));vector cross product )
(if (xd::pnt:isbetween pt base p2
);Test whether point pt is between two points i
)
tf nil
)
)
i (1+i)
)
)
)
)
pos
)
==========
Implementation code: (defun -callback
(dynpt
) ;Point Monitor callback function to draw a text box based on the mouse point inx (XD::Text:IndexAtPoint e (xdrx-point-transform dynpt mat))
)
(setq pts
(xd::text:pointatindex e
(nth 1 inx
)) fpts
pts
)
pts
(xd::pnts:
close (xdrx
-points
-box pts xdir
)) (xdrx-points-transform
pts
(xdrx-matrix-inverse mat)
)
)
)
)
)
)
(setq e
(nentsel "\nClick to get the starting character <exit>:")) )
(xdrx-begin)
(xdrx-sysvar-push '("osmode" 0)) ;Set new values after system variables are pushed onto the stack
(if (> (length e
) 2) ;Determine whether to select a INSERT (setq blk
(car (last e
)) ;nentsel's main entity (block or text) mat (xdrx-matrix-inverse (xdrx-matrix-block2wcs blk));Model space to block transformation matrix
e
(car e
) ;nentsel main entity (text object) p (xdrx-point-transform p mat)
;Through the transformation matrix, the picked points are converted to BLOCK internal points
)
)
(setq mat
(xdrx
-matrix
-identity
3) ;;3D identity matrix
e
(car e
) ; Ordinary text object )
)
)
(setq xdir
(xd::entity:xdir e
) ;Text object X direction unit vector box (xdrx-text-box e) ;Bounding box for text (point list WCS)
'-
) ;Calculate the Y direction unit vector
h (xdrx-getpropertyvalue e "height") ;Text Height
)
;|
XD::Text:IndexAtPoint
Calculate the index table of the text where the starting point is located,
exp: ("Attribute 123" 11 ((2516.7 1901.5 0.0) (2634.88 1947.26 0.0) (2586.15 2073.08 0.0) (2467.98 2027.31 0.0)))
|;
(setq first
(XD::Text:IndexAtPoint e p
) ; )
;|
The Point Monitoring Callback function is enabled to dynamically monitor mouse point behavior.
|;
(xdrx-pointmonitor "-callback")
(xdrx-pointmonitor) ;Point Monitoring end
ln
(xdge::constructor
"kLineSeg3d" (nth 0 pts
)(nth 2 pts
)) inspnt (xdge::getpropertyvalue ln "midpoint")
)
'(first second)
) ;Taking into account the possibility of dragging left and right, the text position index of the starting point of sorting
(setq etxt
(xdrx
-text
-make
)) ;Create text memory empty entity
(xdrx-entity-matchprop e etxt) ;Attributes (color, font height...) match the original text entity
(xdrx-setpropertyvalue
etxt
"textstring"
"rotation"
) ;Set the content and angle of the deducted text (consider changes in the text in the block to UCS)
(xd::drag:simplemove
(xdrx-entity-make etxt)
"\nInsertion point:"
5
t
) ;Drag the center point (5) of the 9 points of the entity bounding box to the deducted text entity.
(xdrx-sysvar-pop) ;Restore system variable values before Run
(xdrx-end)
)
)
)
=============
The above LISP code uses the XDRX-API, which can be downloaded from
https://github.com/xdcad/XDrx-API and is updated at any time.
The XDRX API encapsulates AcDb, AcEd, AcGe, AcBr... C++ library, using C++ methods to develop LISP programs.Thousands of Lisp functions are available.
Modify message