试试这段代码,我为你的情况编写了这段代码,你必须选择要修剪的线的端点,并指定
要修剪所选直线以添加具有角度45指定长度的新线的距离长度。
- (defun c:test (/ *error* acdoc e d len p1 ent p2 lst clse first second ang)
- ;; Tharwat 05. 08. 2011
- (vl-load-com)
- (defun *error* ( msg )
- (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
- (princ (strcat "\n** Error: " msg " **")))
- (princ)
- )
- (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object)))
- (if
- (and
- (setq e (entsel "\n Select line :"))
- (eq (cdr (assoc 0 (setq ent (entget (car e))))) "LINE")
- (setq d (getdist "\n Specify the distance :"))
- )
- (progn
- (vla-StartUndoMark acdoc)
- (setq len (sqrt (+ (* d d) (* d d))))
- (setq p1 (cdr (assoc 10 ent )))
- (setq p2 (cdr (assoc 11 ent)))
- (setq lst (vl-remove-if-not
- (function (lambda (x)
- (member (car x) '(0 67 410 8 62 210))
- )
- )
- ent
- )
- )
- (setq clse
- (vlax-curve-getclosestpointto (car e) (trans (cadr e) 1 0))
- )
- (if (< (distance p1 clse) (distance p2 clse))
- (progn
- (setq first p2)
- (setq second (polar first
- (setq ang (angle p2 p1))
- (- (distance p2 p1) d)
- )
- )
- )
- (progn
- (setq first p1)
- (setq second (polar first
- (setq ang (angle p1 p2))
- (- (distance p1 p2) d)
- )
- )
- )
- )
- (entmakex
- (append lst
- (list (cons 10 (trans first 1 0))
- (cons 11 (setq x (trans second 1 0)))
- )
- )
- )
- (entmakex
- (append
- lst
- (list (cons 10 x) (cons 11 (polar x (+ ang 0.785398) len)))
- )
- )
- (entdel (car e))
- )
- (princ "\n Select a line only !! ")
- )
- (vla-EndUndoMark acdoc)
- (princ)
- )
Tharwat |