本帖最后由 夏生生 于 2021-12-14 11:47 编辑
试试
- (vl-load-com)
- (defun c:test (/ xty-get-dxf xty-tr-ss2lst
- xty-tr-value2list EN LST PARAM
- PT1 PT2 PT3 PT4 PTA
- PTB PTC SS TEMP
- )
- (defun xty-get-dxf (code en) (cdr (assoc code (entget en))))
- (defun xty-tr-ss2lst (ss form / n en lst)
- (repeat (setq n (sslength ss))
- (setq en (ssname ss (setq n (1- n))))
- (setq lst (cons en lst))
- )
- (setq lst (reverse lst))
- (if form
- lst
- (mapcar (function vlax-ename->vla-object) lst)
- )
- )
- (defun xty-tr-value2list (value)
- (setq value (vl-catch-all-apply
- (function vlax-safearray->list)
- (list (vlax-variant-value value))
- )
- )
- (if (= (type value) (function LIST))
- value
- nil
- )
- )
- (setq pt1 (getpoint "\n栏选起点:")
- pt2 (getpoint pt1 "\n栏选终点:")
- ss (ssget "f" (list pt1 pt2) '((0 . "lwpolyline")))
- lst (xty-tr-ss2lst ss nil)
- en (vlax-ename->vla-object
- (ssname (ssget ":e:s" '((0 . "*line"))) 0)
- )
- pt3 (if (= (vla-get-ObjectName en) "AcDbXline")
- (xty-tr-value2list(vla-get-basepoint en))
- (vlax-curve-getstartpoint en)
- )
- pt4 (if (= (vla-get-ObjectName en) "AcDbXline")
- (xty-tr-value2list(vla-get-secondpoint en))
- (vlax-curve-getendpoint en)
- )
- )
- (foreach n lst
- (setq temp (xty-tr-value2list (vla-explode n)))
- (foreach m temp
- (setq pta (xty-tr-value2list (vla-get-startpoint m))
- ptb (xty-tr-value2list (vla-get-endpoint m))
- )
- (if (inters pt1 pt2 pta ptb)
- (progn (setq ptc (inters pt3 pt4 pta ptb nil)
- pta (if (< (distance ptc pta) (distance ptc ptb))
- pta
- ptb
- )
- param (fix (vlax-curve-getparamatpoint n pta))
- )
- (vla-put-coordinate
- n
- param
- (vlax-safearray-fill
- (vlax-make-safearray vlax-vbDouble '(0 . 1))
- (list (car ptc) (cadr ptc))
- )
- )
- )
- )
- (vla-delete m)
- )
- )
- )
|