Author Topic: [XDrX-PlugIn(86)] Polyline fixed distance, equally divided vertex insertion  (Read 241 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Swamp Rat
  • Posts: 503
1. Insert multiple vertices at fixed distance intervals
2. Globally insert vertices based on equal fractions
3. According to equal fractions, insert vertices into each segment equally.

Code: [Select]
;|
1. Insert multiple vertices at fixed distance intervals
2. Globally insert vertices based on equal fractions
3. According to equal fractions, insert vertices into each segment equally.
|;
(defun c:XDTB_PLBatInsPnt (/ e mode dis pts div)
  (if (not #xd-var-global-poly-inspnt-mode)
    (setq #xd-var-global-poly-inspnt-mode "A")
  )
  (xdrx-begin)
  (if
    (and (setq
   e (car
       (xdrx-entsel
(xdrx-string-multilanguage
   "\n拾取多段线<退出>:"
   "\nPick a Polyline<Exit>:"
)
'((0 . "*polyline"))
       )
     )
)
(xdrx-entity-redraw e 1)
(xdrx-initget "A F")
(or (and (setq mode
(getkword
   (xdrx-string-formatex
     (xdrx-string-multilanguage
       "\n模式[定距(A)/等分(F)]<%s>:"
       "\nMode [Fixed distance (A)/Equal division (F)]<%s>:"
     )
     #xd-var-global-poly-inspnt-mode
   )
)
  )
  (xdrx-initget)
  (setq #xd-var-global-poly-inspnt-mode mode)
     )
     t
)
    )
     (progn
       (cond
((= #xd-var-global-poly-inspnt-mode "A")
  (and (setq dis
      (getreal
(xdrx-string-multilanguage "\n间距<退出>:" "Gap<Exit>:")
      )
       )
       (setq pts (xdrx-curve-getpointsatdist e dis))
  )
)
(t
  (if (setq div (getint (xdrx-string-multilanguage
  "\n等分数<退出>:"
  "\nDivide Nums<Exit>:"
)
)
      )
    (progn
      (if (and (xdrx-initget "Y N")
       (= 1
  (xdrx-yesorno
    (xdrx-string-multilanguage
      "\n全局等分"
      "\nGlobal Divide"
    )
    1
  )
       )
       (xdrx-initget)
  )
(progn
  (setq pts (xdrx-curve-getsamplepoints e div))
)
(progn
  (setq allsegs (xdrx-getpropertyvalue e "allsegs")
pts (mapcar '(lambda (x)
   (xdrx-curve-getsamplepoints x div)
)
allsegs
)
pts (xdrx-points-removedup (apply 'append pts))
  )
)
      )
    )
  )
)
       )
       (if pts
(progn
   (mapcar '(lambda (x)
      (and (setq inx (xdrx-getpropertyvalue e "onseg" x))
   (xdrx-polyline-addvertexat e (1+ inx) x)
      )
    )
   (cdr pts)
   )
   (xdrx-prompt
     (xdrx-string-formatex
       (xdrx-string-multilanguage
"\n插入了 %d 个顶点."
"\n%d vertices inserted."
       )
       (length (cdr pts))
     )
   )
)
(xdrx-prompt
   (xdrx-string-multilanguage
     "\n给定条件下没有获取到插入点,重试."
     "\nThe insertion point was not obtained under the given conditions, try again."
   )
)
       )
     )
  )
;(xdrx-entity-redraw e)
  (xdrx-end)
  (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