Author Topic: [XDrX-Text]Dynamically Cut out some text (text in blocks , attributes, text)  (Read 1466 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Swamp Rat
  • Posts: 527


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:

Code - Auto/Visual Lisp: [Select]
  1. (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

Code - Auto/Visual Lisp: [Select]
  1. ;|
  2. Function name: XD::Text:IndexAtPoint
  3. Calling format: (XD::Text:IndexAtPoint e pt)
  4. 1.Parameter description: e ------ text entity name (inside block, attribute text, ordinary text)
  5.   pt ----- point (WCS)
  6. 2.Return value: (Text content, index value, single-character bounding box point table)
  7.  
  8. Function introduction: Get the index position value of the text (in block, attribute, ordinary text) under the mouse click
  9. Function source: original
  10. Function author: Lipboy
  11. Applicable versions: XDRX API
  12. Last updated: 2016-06-26
  13. Note: Index values start from 0
  14. |;
  15. (defun XD::Text:IndexAtPoint (e pt / base box ed i len p2 pos prev tf txt typ v xdir)
  16.    (if (setq txt (xdrx-getpropertyvalue e "textstring"))
  17.      (progn (setq ed (entget e))
  18.             (setq len (xdrx-string-length txt))
  19.             (setq tf t
  20.                   i 0
  21.             )
  22.             (setq box (xdrx-text-box e)
  23.                   base (car box)
  24.                   ydir (mapcar '- (nth 2 box) (nth 1 box))
  25.                   lastpt base
  26.                   xdir (xd::entity:xdir e)
  27.             )
  28.             (while (and tf (< i len))
  29.               (setq prev (xdrx-string-mid txt 0 (1+ i)))
  30.               (setq ed (subst (cons 1 prev) (assoc 1 ed) ed))
  31.               (setq box (textbox ed)
  32.                     v (mapcar '- (cadr box) (car box))
  33.                     p2 (mapcar '+ base (xdrx-vector-product xdir (car v)));vector cross product
  34.               )
  35.               (if (xd::pnt:isbetween pt base p2);Test whether point pt is between two points
  36.                 (setq pos (list txt
  37.                                 i
  38.                                 (list lastpt p2 (mapcar '+ p2 ydir) (mapcar '+ lastpt ydir))
  39.                           )
  40.                       tf nil
  41.                 )
  42.               )
  43.               (setq lastpt p2
  44.                     i (1+i)
  45.               )
  46.             )
  47.      )
  48.    )
  49.    pos
  50. )

==========

Implementation code:


Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.   (defun -callback (dynpt)              ;Point Monitor callback function to draw a text box based on the mouse point
  3.     (redraw)
  4.     (setq
  5.       inx (XD::Text:IndexAtPoint e (xdrx-point-transform dynpt mat))
  6.     )
  7.     (if inx
  8.       (progn
  9.         (setq pts (xd::text:pointatindex e (nth 1 inx))
  10.               pts (append
  11.                     fpts
  12.                     pts
  13.                   )
  14.               pts (xd::pnts:close (xdrx-points-box pts xdir))
  15.               pts (xd::pnts:close
  16.                     (xdrx-points-transform
  17.                       pts
  18.                       (xdrx-matrix-inverse mat)
  19.                     )
  20.                   )
  21.         )
  22.       )
  23.     )
  24.     (xdrx-grdraw 1 0 pts)
  25.   )
  26.   (if (and
  27.         (setq e (nentsel "\nClick to get the starting character <exit>:"))
  28.         (setq p (trans (cadr e) 1 0))
  29.       )
  30.     (progn
  31.       (xdrx-begin)
  32.       (xdrx-sysvar-push '("osmode" 0))  ;Set new values after system variables are pushed onto the stack
  33.       (if (> (length e) 2)              ;Determine whether to select a INSERT
  34.         (progn
  35.           (setq blk (car (last e))      ;nentsel's main entity (block or text)
  36.                 mat (xdrx-matrix-inverse (xdrx-matrix-block2wcs blk));Model space to block transformation matrix
  37.                                        
  38.                 e   (car e)             ;nentsel main entity (text object)
  39.                 p   (xdrx-point-transform p mat)
  40.                                         ;Through the transformation matrix, the picked points are converted to BLOCK internal points
  41.           )
  42.         )
  43.         (progn
  44.           (setq mat (xdrx-matrix-identity 3)
  45.                                         ;;3D identity matrix
  46.                 e   (car e)             ; Ordinary text object
  47.           )
  48.         )
  49.       )
  50.       (setq xdir (xd::entity:xdir e)    ;Text object X direction unit vector
  51.             box  (xdrx-text-box e)      ;Bounding box for text (point list WCS)
  52.             ydir (mapcar
  53.                    '-
  54.                    (nth 2 box)
  55.                    (nth 1 box)
  56.                  )                      ;Calculate the Y direction unit vector
  57.             h    (xdrx-getpropertyvalue e "height") ;Text Height
  58.       )
  59.       ;|
  60.            XD::Text:IndexAtPoint
  61.              Calculate the index table of the text where the starting point is located,
  62.              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)))
  63.       |;
  64.       (setq first (XD::Text:IndexAtPoint e p) ;
  65.             fPts  (nth 2 first)
  66.       )
  67.       ;|
  68.           The Point Monitoring Callback function is enabled to dynamically monitor mouse point behavior.
  69.        |;
  70.       (xdrx-pointmonitor "-callback")
  71.       (getpoint "\nEnd Character <exit>:")
  72.       (xdrx-pointmonitor)               ;Point Monitoring end
  73.       (redraw)
  74.       (setq txt    (nth 0 first)
  75.             first  (nth 1 first)
  76.             second (nth 1 inx)
  77.             ln (xdge::constructor "kLineSeg3d" (nth 0 pts)(nth 2 pts))
  78.             inspnt (xdge::getpropertyvalue ln "midpoint")
  79.       )
  80.       (mapcar 'set
  81.               '(first second)
  82.               (vl-sort (list first second) '<)
  83.       )                                 ;Taking into account the possibility of dragging left and right, the text position index of the starting point of sorting
  84.  
  85.       (setq etxt (xdrx-text-make))      ;Create text memory empty entity
  86.  
  87.       (xdrx-entity-matchprop e etxt)    ;Attributes (color, font height...) match the original text entity
  88.  
  89.       (xdrx-setpropertyvalue
  90.         etxt
  91.         "textstring"
  92.         (substr txt (1+ first) (1+ (- second first)))
  93.         "rotation"
  94.         (angle (car pts) (cadr pts))
  95.       )                                 ;Set the content and angle of the deducted text (consider changes in the text in the block to UCS)
  96.  
  97.       (xd::drag:simplemove
  98.         (xdrx-entity-make etxt)
  99.         "\nInsertion point:"
  100.         5
  101.         t
  102.       )                                 ;Drag the center point (5) of the 9 points of the entity bounding box to the deducted text entity.
  103.  
  104.       (xdrx-sysvar-pop)                 ;Restore system variable values before Run
  105.       (xdrx-end)
  106.     )
  107.   )
  108.   (princ)
  109. )

=============

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
« Last Edit: November 19, 2023, 03:34:14 PM by xdcad »
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8927
  • AKA Daniel
That’s cool stuff

domenicomaria

  • Swamp Rat
  • Posts: 743
xdrx-pointmonitor is a function that
calls another function not in the "normal" way (func-01 arg1 arg2 . . .  ) or (c:func-02)
but needs a string  !

And this without passing the required argument (dynpt) !

(xdrx-pointmonitor "-callback")

Help me to understand !

Is it a kind of reactor ?

xdcad

  • Swamp Rat
  • Posts: 527
xdrx-pointmonitor is a function that
calls another function not in the "normal" way (func-01 arg1 arg2 . . .  ) or (c:func-02)
but needs a string  !

And this without passing the required argument (dynpt) !

(xdrx-pointmonitor "-callback")

Help me to understand !

Is it a kind of reactor ?

ObjectARX:

AcEdInputPointMonitorClass Hierarchy
AcRxObject
    AcEdInputPointMonitor
C++
class AcEdInputPointMonitor : public AcRxObject;
File
acedinpt.h

Description
This class provides a callback protocol that defines an "Input Point Notification" mechanism. It is intended to only monitor points after built-in AutoCAD point filters have computed their effect. This also satisfies a more general desire for "cursor event notification." If you intend to make changes to points, see AcEdInputPointFilter instead.

Unlike AcEdInputPointFilter, this class cannot affect the point or influence the prompting, and therefore has none of the Output Value parameters of AcEdInputPointFilter. However, see graphics output, which is the same for monitors as for filters.

=====================

simple say

It allows you to process what you want to do through the callback function while the mouse is moving.
AUTOCAD itself, such as mouse movement prompts TOOLTIP, etc., are all implemented through this class.

Dynamically drag, and then give you methods to monitor, and then achieve what you want to do during the dragging process
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net

xdcad

  • Swamp Rat
  • Posts: 527
xdrx-pointmonitor is a function that
calls another function not in the "normal" way (func-01 arg1 arg2 . . .  ) or (c:func-02)
but needs a string  !

And this without passing the required argument (dynpt) !

(xdrx-pointmonitor "-callback")

Help me to understand !

Is it a kind of reactor ?

Code: [Select]
And this without passing the required argument (dynpt) !

The only parameter in the callback function is dynpt (WCS point coordinates)
It is the coordinates of the current point during mouse movement.
You can print it in the callback function, take a look
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net

xdcad

  • Swamp Rat
  • Posts: 527
xdrx-pointmonitor is a function that
calls another function not in the "normal" way (func-01 arg1 arg2 . . .  ) or (c:func-02)
but needs a string  !

And this without passing the required argument (dynpt) !

(xdrx-pointmonitor "-callback")

Help me to understand !

Is it a kind of reactor ?

In the XDRX API, through the LISP function
(getpoint....)
To activate it, the typical structure:

Code - Auto/Visual Lisp: [Select]
  1. (xdrx-pointmonitor "_callback") ;;Define callback function name "_callback"
  2. (getpoint ....);;Wait for the mouse to move
  3. (xdrx-pointmonitor);;End point monitor

=============

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
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net

xdcad

  • Swamp Rat
  • Posts: 527
xdrx-pointmonitor is a function that
calls another function not in the "normal" way (func-01 arg1 arg2 . . .  ) or (c:func-02)
but needs a string  !

And this without passing the required argument (dynpt) !

(xdrx-pointmonitor "-callback")

Help me to understand !

Is it a kind of reactor ?


https://www.theswamp.org/index.php?topic=58759.0
https://www.theswamp.org/index.php?topic=58758.0
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net