Author Topic: [XDrX-PlugIn(161)] Label Rectangle  (Read 125 times)

0 Members and 2 Guests are viewing this topic.

xdcad

  • Swamp Rat
  • Posts: 505
[XDrX-PlugIn(161)] Label Rectangle
« on: May 03, 2024, 07:52:09 AM »
https://www.cadtutor.net/forum/topic/64709-label-rectangle/

1. Eliminate unnecessary vertices
2. Modify the starting point to the lower left point (X is the smallest and Y is the smallest), and the clockwise direction is counterclockwise.
3. Align the text on the long side, and mark the text on the horizontal side first.

Code: [Select]
(defun c:xdtb_reclabel (/ cen centroid label minpt pts ss txt x xdir)
  (xd::doc:getdouble (xdrx-string-multilanguage "\n文字高度" "\nText Height")
     "#xd-var-global-text-height" 3.5
  )
  (xd::doc:getint (xdrx-string-multilanguage "\n小数位数" "\ndecimal places")
  "#xd-var-global-num-bits" 1
  )
  (if (setq ss (xdrx-ssget (xdrx-string-multilanguage "\n选择矩形<退出>:" "\nSelect Rectangle<Exit>:")
   '((0 . "*polyline"))
       )
      )
    (progn
      (xdrx-begin)
      (mapcar
'(lambda (x)
   (if (xd::polyline:isrectang x)
     (progn
       (xdrx-polyline-compress x)
       (setq pts (xdrx-getpropertyvalue x "vertices")
     minpt (xd::pnts:minx->miny pts 1e-5)
     minpt (car minpt)
       )
       (xdrx-curve-setclosed x)
       (xdrx-polyline-resetstartpoint x minpt)
       (setq pts (xdrx-getpropertyvalue x "vertices")
     xdir (xdrx-vector-normalize (mapcar
   '-
   (nth 1 pts)
   (nth 0 pts)
)
  )
       )
       (if (< (distance (nth 1 pts) (nth 0 pts)) (distance
   (nth 1
pts
   )
   (nth 2
pts
   )
)
   )
(setq xdir (xdrx-vector-normalize (mapcar
     '-
     (nth 2 pts)
     (nth 1 pts)
   )
    )
)
       )
       (setq label (strcat (rtos (distance (car pts) (cadr pts)) 2
#xd-var-global-num-bits
   ) "x" (rtos (distance (cadr pts)
(caddr pts)
       ) 2 #xd-var-global-num-bits
)
   )
       )
       (setq centroid (xdrx-getpropertyvalue x "centroid"))
       (setq txt (xdrx-text-make centroid label
#xd-var-global-text-height
)
     cen (xdrx-getpropertyvalue txt "centroid")
       )
       (xdrx-entity-align txt cen '(1 0 0) centroid xdir)
       (xd::text:adjust txt)
       (xdrx-setpropertyvalue txt "horizontalmode" 1 "verticalmode"
      2 "alignmentpoint" centroid "color" 1
       )
     )
   )
)
(xdrx-ss->ents ss)
      )
      (xdrx-end)
    )
  )
  (princ)
)
« Last Edit: May 03, 2024, 07:55:37 AM 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