Author Topic: [XDrx-PlugIn(141)] Reset the starting point of the closed polyline and direction  (Read 143 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Bull Frog
  • Posts: 493
1. Reset the starting point of the closed polyline (lower left, upper left, upper right, lower right)

2. Reset the clockwise direction of a closed polyline

Code: [Select]
(defun c:xdtb_plreset (/ bb corner left-up pts ss val x)
  (if (not #xd_var_global_polyline_mode)
    (setq #xd_var_global_polyline_mode 1)
  )
  (xdrx_initget "0 1 2 3")
  (if (setq val (getint (xdrx-string-formatex
      (xdrx-string-multilanguage "\n多段线起点[左下(0)/左上(1)/右上(2)/右下(3)]<%d>:" "\nPolyline starting point [lower left (0)/upper left (1)/upper right (2)/lower right (3)]<%d>:")
      #xd_var_global_polyline_mode
)
)
      )
    (setq #xd_var_global_polyline_mode val)
  )
  (if (not #xd_var_global_polyline_clockwise)
    (setq #xd_var_global_polyline_clockwise 1)
  )
  (xdrx_initget "0 1")
  (if (setq val (getint (xdrx-string-formatex
      (xdrx-string-multilanguage "\n时针方向[逆时针(0)/顺时针(1)]<%d>:" "\nClockwise direction [counterclockwise (0)/clockwise (1)]<%d>:") #xd_var_global_polyline_clockwise
)
)
      )
    (setq #xd_var_global_polyline_clockwise val)
  )
  (if (setq ss (xdrx-ssget (xdrx-string-multilanguage "\n选择要处理的封闭多段线<退出>:" "\nSelect closed polylines to process <Exit>:")
   '((0 . "*polyline") (-4 . "&=")
    (70 . 1)
   )
       )
      )
    (progn
      (setq bb nil)
      (mapcar
'(lambda (x)
   (setq pts (xdrx-getpropertyvalue x "vertices")
corner (xdrx-points->4corner pts)
left-up (nth #xd_var_global_polyline_mode corner)
   )
   (setq bb (cons x bb))
   (xd::polyline:resetstartpoint x left-up)
   (cond
     ((and
(= #xd_var_global_polyline_clockwise 1)
(xdrx-curve-direction x)
      )
       (xdrx-curve-reverse x)
     )
     ((and
(= #xd_var_global_polyline_clockwise 0)
(not (xdrx-curve-direction x))
      )
       (xdrx-curve-reverse x)
     )
   )
)
(xdrx-ss->ents ss)
      )
      (xdrx-prompt (xdrx-string-formatex (xdrx-string-multilanguage "\n重设了%d个多段线起点和时针方向." "\nReset starting point and clockwise direction of %d polylines.")
(sslength ss)
   )
      )
    )
  )
  (princ)
)
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