Author Topic: [XDrX-PlugIn(33)] Adjust attributes and text to display in the correct direction  (Read 676 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Bull Frog
  • Posts: 424
Code - Auto/Visual Lisp: [Select]
  1. (defun c:xdtb_txtadjust (/ ss i)
  2.   (if
  3.     (and
  4.       (xdrx-initssget
  5.         "\nSelect a single line of text for the self-correction angle <Exit>:"
  6.       )
  7.       (setq
  8.         ss (xdrx-ssget
  9.              '((-4 . "<or") (0 . "text,insert") (66 . 1) (-4 . "or>"))
  10.            )
  11.       )
  12.     )
  13.      (progn
  14.        (xdrx-begin)
  15.        (setq i (XD::Text:Adjust ss))
  16.        (xdrx-prompt "\nSelf-corrected " i " single-line text.")
  17.        (xdrx-end)
  18.      )
  19.   )
  20.   (princ)
  21. )

The required general functions for adjusting attributes and correct text display direction,
see XD::Text:Adjust below:

Code - Auto/Visual Lisp: [Select]
  1. (defun XD::Text:Adjust (ents   /
  2.                         9pt1   box    ecs          mat
  3.                         mat0   mat1   mat2   mirrInx       mirrIny
  4.                         p0     p0_1   p1     vx     vy     vz
  5.                         atts   txts   eblk   i      e ents1
  6.                        )
  7.   (defun _tMirr (e)
  8.     (setq mirrInx (xdrx_text_ismirroredInx e)
  9.           mirrIny (xdrx_text_ismirroredIny e)
  10.     )
  11.     (if mirrInx
  12.       (xdrx_text_setMirrorInx e nil)
  13.     )
  14.     (if mirrIny
  15.       (xdrx_text_setMirrorIny e nil)
  16.     )
  17.     (if (or mirrInx mirrIny)
  18.       (progn (setq box  (XD::Entity:BoxAtEcs e e)
  19.                    9pt1 (XD::Geom:BOX->9PT box)
  20.                    p0_1 (last 9pt1)
  21.              )
  22.              (xdrx_entity_transform
  23.                e
  24.                (xdrx_matrix_setTranslation mat0 (mapcar '- p0 p0_1))
  25.              )
  26.       )
  27.     )
  28.   )
  29.   (cond
  30.     ((= (type ents) 'PICKSET)
  31.      (setq ents (xdrx_pickset->ents ents))
  32.     )
  33.     ((= (type ents) 'ename) (setq ents (list ents)))
  34.   )
  35.   (setq ents1 nil
  36.         elks nil
  37.   )
  38.   (mapcar
  39.     '(lambda (x)
  40.        (cond
  41.          ((xdrx_object_iskindof X "INSERT")
  42.           (setq atts
  43.                  (xdrx_getpropertyvalue X "attributeentities")
  44.           )
  45.           (setq
  46.             txts (xdrx_block_getentities X '((0 . "TEXT")))
  47.           )
  48.           (setq txts (append txts atts))
  49.           (setq eblks (cons x elbks))
  50.           (setq ents1 (append txts ents1))
  51.          )
  52.          ((xdrx_object_iskindof x "ATT*,*TEXT")
  53.           (setq ents1 (cons x ents1))
  54.          )
  55.          ((xdrx-getpropertyvalue x "textstring")
  56.           (setq ents1 (cons x ents1))
  57.          )
  58.        )
  59.      )
  60.      ents
  61.   )
  62.  
  63.   (setq i 0)
  64.   (mapcar
  65.     '(lambda (e)
  66.        (if (and (xdrx-getpropertyvalue e "textstring")
  67.                 (/= #textstring ""))
  68.          (progn
  69.            (setq ecs  (xdrx_entity_getecs e)
  70.                  vx   (cadr ecs)
  71.                  vy   (caddr ecs)
  72.                  vz   (last ecs)
  73.                  box  (xdrx_entity_box e vx)
  74.                  9pt1 (XD::Geom:BOX->9PT box)
  75.                  p1   (car box)
  76.                  p0   (last 9pt1)
  77.                  mat0 (xdrx_matrix_identity 3)
  78.                  mat1 mat0
  79.                  mat2 mat0
  80.                  p1   (xdrx_getpropertyvalue e "9pt" 5)
  81.            )
  82.            (_tMirr e)
  83.            (if (or (equal vx '(0 -1 0)) (< (car vx) 0.0))
  84.              (progn (setq mat1 (xdrx_matrix_setrotation mat0 pi vy p0)))
  85.            )
  86.            (if (or (equal vy '(1 0 0)) (< (cadr vy) 0.0))
  87.              (progn (setq mat2 (xdrx_matrix_setrotation mat0 pi vx p0)))
  88.            )
  89.            (setq mat (xdrx_matrix_product mat2 mat1))
  90.            (if (or (not (equal mat mat0))
  91.                    (equal (angle '(0 0 0) vx) (* 3 (/ pi 4.0)) 1e-3))
  92.              (progn
  93.               (xdrx_entity_transform e mat)
  94.               (xdrx_entity_move e (xdrx_getpropertyvalue e "9pt" 5) p1)
  95.                (setq i (1+ i))
  96.              )
  97.            )
  98.          )
  99.        )
  100.      )
  101.     ents1
  102.   )
  103.   (xdrx_object_regen eblk)
  104.   i
  105. )
« Last Edit: December 04, 2023, 05:32:44 AM 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

Hugo

  • Bull Frog
  • Posts: 419
Now it works with multiple attributes too
Thank you 1000x

xdcad

  • Bull Frog
  • Posts: 424
Now it works with multiple attributes too
Thank you 1000x

you are welcome, please post if necessary
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