- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a lisp program I built that inserts a pipe size block on all lines of a certain layer, at the midpoint of each line and matching the angle (corrected to prevent upside down sizes). The code, while fairly messy, works just perfectly. The only problem is, when I select large amounts of lines, it takes a long time to insert every block. The situation that prompted me to ask is that I have 1654 lines, and it takes nearly 40 seconds to insert them all. Granted, that's not all that long. But I built this program because I use SprinkCAD (a fire sprinkler design extension for AutoCAD), and their built in function to insert sizes will insert on all 1654 lines in under 1 second. Before anyone asks, the reason I don't user their function and I built my own is because theirs inserts one size on both of the two types of pipe, while mine will insert one size on one type and another size on the other type. I would just like to make mine quicker if I can. My code is below.
(defun c:insmanysz (/ ss i sn e p1 p2 ang)
(defun RtD (r) (* 180.0 (/ r pi)))
(defun GetStr (/ rtn)
(while
(not
(and
(setq rtn (strcase (getstring) T))
(< (strlen rtn) 3)
); and
); not
(alert "\n2 characters maximum.")
); while
rtn
)
(command "undo" "begin")
(setq oReq (getvar "ATTREQ") oDia (getvar "ATTDIA") oLay (getvar "CLAYER") oOsmode (getvar "OSMODE"))
(setvar "ATTREQ" 1)(setvar "ATTDIA" 0)(setvar "CLAYER" "PIPESPC")(setvar "OSMODE" 0)
(if (= sz1 nil)(setq sz1 "4"))
(if (= ty1 nil)(setq ty1 "10"))
(if (= sz2 nil)(setq sz2 "1"))
(if (= ty2 nil)(setq ty2 "40"))
(write-line (strcat "\nMain size: " sz1 ", type: " ty1 ". Branch line size: " sz2 ", and type: " ty2 "."))
(if (and
(setq getSet (strcase (getstring "\nType S to change, or enter to start picking.")))
(= getSet "S"))
(progn
(princ (strcat "\nMain pipe size <" sz1 "> : "))
(setq sz1a (GetStr))
(if (= sz1a "")(setq sz1a sz1))
(setq sz1 sz1a)
(princ (strcat "\nMain pipe type <" ty1 "> : "))
(setq ty1a (GetStr))
(if (= ty1a "")(setq ty1a ty1))
(setq ty1 ty1a)
(princ (strcat "\nBranch line pipe size <" sz2 "> : "))
(setq sz2a (GetStr))
(if (= sz2a "")(setq sz2a sz2))
(setq sz2 sz2a)
(princ (strcat "\nBranch line pipe type <" ty2 "> : "))
(setq ty2a (GetStr))
(if (= ty2a "")(setq ty2a ty2))
(setq ty2 ty2a)
)
)
(if (setq ss (ssget '((0 . "LINE")(8 . "PIPEBL,PIPEMN,PIPEBLEX,PIPEMNEX"))))
(repeat (setq i (sslength ss))
(setq sn (ssname ss (setq i (1- i))))
(setq p1 (cdr (assoc 10 (setq e (entget sn)))))
(setq p2 (cdr (assoc 11 e)))
(if (or (= (cdr (assoc 8 e)) "PIPEMN")(= (cdr (assoc 8 e)) "PIPEMNEX"))
(setq sz sz1 ty ty1)
(setq sz sz2 ty ty2)
)
(progn
(setq ang (RtD (angle p1 p2)))
(cond ((and (<= ang 90.1)(>= ang 0))(setq ang ang))
((and (> ang 90.1)(< ang 180))(setq ang (+ ang 180)))
((and (>= ang 180)(<= ang 270.1))(setq ang (- ang 180)))
((and (> ang 270.1)(< ang 360))(setq ang ang))
((= ang 360)(setq ang 0))
(t)
)
(setq mid (list
(/ (+ (car p1) (car p2)) 2.0)
(/ (+ (cadr p1) (cadr p2)) 2.0)
))
)
(setq ang (rtos ang 2 1))
(if (= (substr ang (- (strlen ang) 1) 2) ".0")
(setq ang (substr ang 1 (- (strlen ang) 2)))
(setq ang ang)
)
(command "-insert" "PIPESPC" mid "1" ang sz ty)
)
(princ)
)
(setvar "ATTREQ" oReq)(setvar "ATTDIA" oDia)(setvar "CLAYER" oLay)(setvar "OSMODE" oOsmode)
(command "undo" "end")
(princ)
)
Solved! Go to Solution.