声明:这段源码来自明经,最初的作者已无从考证,应该是个台湾同胞吧,若见此帖,先谢过!
作图时,经常会使用到很多不同长度的非连续线,比如center hidden。而LTS线型比例是固定的,因为长短的不同,照顾不了所有的线段都能如实显示(很多短线因此显示为连续线)
问题来了,如何实现框选所有需要改变线型比例的线段,使之根据自身长短,自动调整到合适的比例呢?
下面便是本文字首的源码:目前只能实现所有线段变为合适比例的hidden线,不能同时针对多线型。且目前看来,自动调整的效果还待完善。开此贴,看需要的人多不多,若多,希望高手改善之,希望在将来,此帖还能帮助更多的人。
(defun c:df () ;自動變換成適當比例的虛線
(ltchange "dashed" 3 "bylayer")
(princ)
)
(defun ltchange (type1 scale color / oce lin n nam tab
pt1 pt2 x1 x2 y1 y2 len leg sca
otyp ocol osca col typ lts rad
) ;自動變換成適當比例的中心線
(setq oce (getvar "cmdecho")
lts (getvar "ltscale")
) ;_ end of setq
(setvar "cmdecho" 0)
(setq n 0)
(strcat "Select object change to " type1 ":")
) ;_ end of print
(setq lin (ssget '((-4 . "
(0 . "LINE")
(0 . "CIRCLE")
(0 . "ELLIPSE")
(0 . "ARC")
(0 . "polyline")
(-4 . "OR>")
)
) ;_ end of ssget
) ;end setq
(if (not lin)
(progn
(alert "\nNo selection!")
(exit)
) ;_ end of progn
) ;end if
(repeat (sslength lin)
(setq nam (ssname lin n))
(setq tab (entget nam))
;;;;;;;;;;circle
(if (= (cdr (assoc 0 tab)) "CIRCLE")
(progn
(setq rad (cdr (assoc 40 tab)))
(setq len (* 2 (* 3.14 rad)))
) ;如是圓實體取周長為"len"
;;;;;;;;;;ARC
(if (= (cdr (assoc 0 tab)) "ARC")
(progn
(setq rad (cdr (assoc 40 tab)))
(setq len (* 3.14 rad))
) ;end progn;如是圓弧取其圓周長半
;;;;;;;;;;ellipse
(if (= (cdr (assoc 0 tab)) "ellipse")
(progn
(setq rad (cdr (assoc 40 tab)))
(setq len (* 2 (* 3.14 rad)))
)
;;;;;;;;;LINE
(progn
(setq pt1 (cdr (assoc 10 tab))
pt2 (cdr (assoc 11 tab))
len (distance pt1 pt2)
) ;end setq
) ;end progn
) ;end if
)
);end if
(cond ((and (> len 0) (<= len 2))
(setq leg 2)
)
((and (> len 2) (<= len 5))
(setq leg 6)
)
((and (> len 5) (<= len 30))
(setq leg 20)
)
((and (> len 30) (<= len 50))
(setq leg 40)
)
((and (> len 50) (<= len 100))
(setq leg 75)
)
((> len 100)
(setq leg 100)
)
) ;end cond
(setq sca (/ leg scale lts 2))
(command "-linetype" "l" type1 "acad.lin" "" "")
(command "change" nam "" "p" "c" color "lt" type1 "s" SCA "") ;_ end of command
;_ end of command
;_ end of command
(setq n (+ n 1))
) ;end repeat
(setvar "cmdecho" oce)
(princ)
) ;_ end of defun