Author Topic: [XDrX-PlugIn(109)] Text aligned at the specified distance to the nearest curve  (Read 606 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Bull Frog
  • Posts: 469
The text is aligned at the specified distance to the nearest curve



Code: [Select]
(defun c:xdtb_txtalncrv (/ _#nearpt tol dist ss x info ecs box nearpt vec v transmat pnt from to mat
ecs box ang_x ang_y qua xdir)
  (defun _#nearpt (e nearpt vec / )
    (setq vec (xdrx-vector-normalize vec))
    (if (< (car vec) 0.0)
      (setq vec (xdrx-vector-negate vec))
    )
    (setq ecs (cdr (xdrx-entity-getecs e))
  box (xdrx-entity-box e (car ecs))
  ang_x (abs
  (xd::geom:angleformat (xdrx-vector-angleto vec (car ecs)))
)
  ang_y (abs
  (xd::geom:angleformat (xdrx-vector-angleto vec (cadr ecs)))
)
  qua (XD::Pnt:Quadrant (xd::geom:get9pt box 5) nearpt vec)
    )
    (if (< ang_y ang_x)
      (list (if (or (= qua 6) (= qua 1) (= qua 2))
      (xdrx-points-nearpt nearpt
  (list (xd::geom:get9pt box 4) (xd::geom:get9pt box 6))
      )
      (xdrx-points-nearpt nearpt
  (list (xd::geom:get9pt box 4) (xd::geom:get9pt box 6))
      )
    )
    (setq xdir (if (xdrx-vector-iscodirectional (cadr ecs) vec (/ pi 2.0))
(cadr ecs)
(xdrx-vector-negate (cadr ecs))
       )
    )
    (xdrx-vector-crossproduct (last ecs) xdir)
    (last ecs)
      )
      (cons (if (or (= qua 6) (= qua 1) (= qua 2))
      (xd::geom:get9pt box 2)
      (xd::geom:get9pt box 8)
    )
    ecs
      )
    )
  )
  (setq tol (getreal
      (xdrx-string-multilanguage "\n请输入搜索范围容差距离<默认>:"
"nPlease enter the search range tolerance distance <Default>:"
      )
    )
  )
  (if (and (setq dist (getreal
(xdrx-string-multilanguage "\n请输入到最近曲线距离<退出>:"
   "\nPlease enter the distance to the nearest curve<Exit>:"
)
      )
   )
   (setq ss (xdrx-ssget (xdrx-string-multilanguage "\n选择调整的文字<退出>:"
   "\nSelect the adjusted text <Exit>:"
)
'((0 . "*text"))
    )
   )
      )
    (progn (xdrx-begin)
   (xdrx-document-safezoom ss)
   (mapcar '(lambda (x)
      (if (setq info (xd::entity:nearto x nil tol))
(progn (setq ecs    (xdrx-entity-getecs x)
     box    (xdrx-entity-box x (cadr ecs))
     nearpt (car info)
     vec    (last info)
     vec    (if (< (car vec) 0.0)
      (xdrx-vector-negate vec)
      vec
    )
     zdir   (last ecs)
       )
       (setq v       (xdrx-vector-normalize
(mapcar '- (xd::geom:get9pt box 5) nearpt)
      )
     transmat (xdrx-matrix-settranslation
(mapcar '- (mapcar '+ nearpt (xdrx-vector-* v dist)) nearpt)
      )
     pnt      (xdrx-point-transform nearpt transmat)
     from     (_#nearpt x nearpt vec)
     to       (list pnt vec (xdrx-vector-crossproduct zdir vec) zdir)
     mat      (xdrx-matrix-aligncoordsys from to)
       )
       (xdrx-entity-transform x mat)
)
      )
    )
   (xdrx-ss->ents ss)
   )
   (xdrx-end)
    )
  )
  (princ)
)
« Last Edit: February 06, 2024, 08:43:15 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: 430
get an error message