Lisp

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 161

;Count selected objects length by layer and put it in table form into a drawing

;Stefan M. 22.09.2016
(defun C:LAY ( / *error* acdoc ss p i e a d l s h dz) (vl-load-com)
(setq acdoc (vla-get-activedocument (vlax-get-acad-object))
dz (getvar 'dimzin))
(vla-startundomark acdoc)
(setvar 'dimzin 1)
(defun *error* (msg)
(and
msg
(not (wcmatch (strcase msg) "*CANCEL*,*QUIT*,*BREAK*,*EXIT*"))
(princ (strcat "\nError: " msg))
)
(setvar 'dimzin dz)
(if
(= 8 (logand (getvar 'undoctl) 8))
(vla-endundomark acdoc)
)
(princ)
)
(if
(and
(setq ss (ssget ":L" '((0 . "LINE,POLYLINE,LWPOLYLINE,ARC,CIRCLE,ELLIPSE,SPLINE,
HATCH"))))
(setq p (getpoint "\nTable scale depend on annotation scale.\nSpecify table inse
rt point: "))
)
(progn
(repeat
(setq i (sslength ss))
(setq e (vlax-ename->vla-object (ssname ss (setq i (1- i))))
a (vla-get-layer e)
)
(if
(setq h (eq (vla-get-objectname e) "AcDbHatch"))
(setq s (vla-get-area e))
(setq d (vlax-curve-getdistatparam e (vlax-curve-getendparam e)))
)
(if
(setq o (assoc a l))
(if h
(setq l (subst (list a (cadr o) (+ (caddr o) s)) o l))
(setq l (subst (list a (+ (cadr o) d) (caddr o)) o l))
)
(if h
(setq l (cons (list a 0.0 s) l))
(setq l (cons (list a d 0.0) l))
)
)
)
(setq l (vl-sort l '(lambda (a b) (< (car a) (car b)))))
(insert_table l p)
)
)
(*error* nil)
(princ)
)
(defun insert_table (lst pct / tab row col ht i n space )
(setq space (vlax-get acDoc (if (= 1 (getvar 'cvport)) 'PaperSpace 'ModelSpace))
ht (/ 2.5 (cond ((getvar 'cannoscalevalue)) (1.0)))
pct (trans pct 1 0)
n (trans '(1 0 0) 1 0 T)
tab (setq tab (vla-addtable space (vlax-3d-point pct) (+ 2 (length lst)) (length
(car lst)) (* 2.5 ht) ht))
)
(vlax-put tab 'direction n)
(mapcar
(function
(lambda (rowType)
(vla-SetTextStyle tab rowType (getvar 'textstyle))
(vla-SetTextHeight tab rowType ht)
)
)
'(2 4 1)
)
(vla-put-HorzCellMargin tab (* 0.14 ht))
(vla-put-VertCellMargin tab (* 0.14 ht))
(setq lst (cons '("Layer" "Length") lst))
(setq i 0)
(foreach col (apply 'mapcar (cons 'list lst))
(vla-SetColumnWidth tab i
(apply
'max
(mapcar
'(lambda (x)
((lambda (txb) (+ (abs (- (caadr txb) (caar txb))) (* 2.0 ht)))
(textbox
(list
(cons 1
(cond
((eq (type x) 'STR) x)
((eq (type x) 'INT) (itoa x))
((eq (type x) 'REAL) (rtos x))
)
)
(cons 7 (getvar 'textstyle))
(cons 40 ht))
)
)
)
col
)
)
)
(setq i (1+ i))
)
(setq lst (cons '("TITLE") lst))
(setq row 0)
(foreach r lst
(setq col 0)
(foreach c r
(if
(not (eq c 0))
(progn
(vla-SetText tab row col c)
(vla-SetCellDataType
tab row col
(cdr (assoc (type c) '((STR . 4) (REAL . 2) (INT . 1))))
acUnitless
)
(vla-setCellAlignment tab row col acMiddleCenter)
)
)
(setq col (1+ col))
)
(vla-SetRowHeight tab row (* 1.6 ht))
(setq row (1+ row))
)
)
(c:lay)

;;; Calculate Area by picking corners send it to excel file and import it to dra
wing as table
;;; Combined from existing routines and modified by Igal Averbuh 2016
(defun c:act (/ room outlist fh)
(while (/= "" (setq room (getstring 1 "\nEnter Name or Number of Digitizing Area
")))
(princ "\nDigitize Area by picking corners...\n")
(command "._AREA")
(while (not (zerop (getvar "CMDACTIVE"))) (command pause))
(setq outlist (cons (list room (rtos (getvar "AREA"))) outlist))
)
(and
outlist
(setq fl (getfiled "\nSpeficy csv file name to write area data:" "" "csv" 1))
(setq fh (open fl "w"))
(write-line "No Area m" fh)
(progn
(mapcar '(lambda (out)
(write-line (apply 'strcat (mapcar '(lambda (a) (strcat a ",")) out)) fh)
)
(reverse outlist)
)
(close fh)
)
)
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; TABLE.LSP
;;; This routine can read a comma seperated variable (CSV) file and import
;;; them to AutoCAD drafting screen as a table.
;;; Copyright 1997 Yuqun Lian, SimpleCAD http://www.simplecad.com
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Set the global variables, you can freely edit them
(setq ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
x_distance 10
y_distance 2
text_height 1
text_style "arial.ttf"
text_align "ml"
) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:csvtable(/ txt txt_lst x y)
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(command "style" "txt_style" text_style text_height "1.0" "" "" "" "")
(setq data_file (getfiled "Select created Area data file" "" "CSV" 0))
(setq start_pt (getpoint "\nPick the left-upper corner for the table: "))
(setq y (cadr start_pt))
(setq fp (open data_file "r"))
;; read data
(while (setq txt (read-line fp))
(setq txt_lst (parse txt))
(setq x (car start_pt))
(print_lst txt_lst)
(setq y (- y y_distance))
)
(close fp)
)
(defun parse(txt / n count word lst in_quart)
(setq n (strlen txt) count 1 word "" in_quart nil lst nil)
(while (<= count n)
(setq char (substr txt count 1))
(if (= char "\"")
(if in_quart
(setq in_quart nil)
(setq in_quart T)
)
)
(if (and (= char ",")(= in_quart nil))
(progn
(setq lst (append lst (list word)))
(setq word "")
)
(progn
(if (/= char "\"")
(setq word (strcat word char))
)
(if (= count n)
(setq lst (append lst (list word)))
)
)
)
(setq count (1+ count))
)
(setq lst lst)
)
(defun print_lst (lst / txt txt_pt)
(foreach txt lst
(setq txt_pt (list x y))
(command ".text" "s" "txt_style" "j" text_align txt_pt "0" txt )
(setq x (+ x x_distance))
)
)
(princ)
(defun c:car() ;Main function
(c:act)
(c:csvtable)
)
;(c:car)

;;; Calculate area of closed polyline and place text in Sq.cm in center of close
d area
;;; Modified by Igal Aberbuh 2016
(defun C:atc (/ acsp adoc ar axss hgt maxp minp obj p1 p2 pc ss txt)
(command "-style" "igal" "arial.ttf" "" "" "" "" "")
(vl-load-com)
(setq adoc (vla-get-activedocument
(vlax-get-acad-object)
)
)
(if (and
(= (getvar "tilemode") 0)
(= (getvar "cvport") 1)
)
(setq acsp (vla-get-paperspace adoc))
(setq acsp (vla-get-modelspace adoc))
)
(vla-startundomark (vla-get-activedocument
(vlax-get-acad-object)))
(initget 7)
(setvar 'textsize
(cond ((getdist (strcat "\nSpecify Area text height by two points on screen : ")
))
((getvar 'textsize))
)
)
(prompt "\nSelect objects on screen to add area label")
(if (setq ss (ssget))
(progn
(setq axss (vla-get-activeselectionset adoc))
(vlax-for obj axss
(if (not
(vl-catch-all-error-p
(setq
ar (vl-catch-all-apply
(function (lambda()
(vlax-curve-getarea obj)))))))
(progn
(setq txt (strcat "Area = " (rtos ar 2 2)"cm"))
(vla-getboundingbox obj 'minp 'maxp)
(setq p1 (vlax-safearray->list minp)
p2 (vlax-safearray->list maxp)
pc (mapcar (function (lambda(a b)(/ (+ a b) 2))) p1 p2)
)
(vlax-invoke acsp 'Addtext txt pc (getvar 'textsize))
)
)
)
)
)
(vla-endundomark (vla-get-activedocument
(vlax-get-acad-object)))
(princ)
)
(princ)
(c:atc)
Calculate area of closed polyline and place text in Sq.m in center of closed are
a
22
Sunday
May 2016
Posted by danglar71 in Counting, Utilites
Leave a comment

;;; Calculate area of closed polyline and place text in Sq.m in center of closed
area
;;; Modified by Igal Aberbuh 2016
(defun C:at (/ acsp adoc ar axss hgt maxp minp obj p1 p2 pc ss txt)
(command "-style" "igal" "arial.ttf" "" "" "" "" "")
(vl-load-com)
(setq adoc (vla-get-activedocument
(vlax-get-acad-object)
)
)
(if (and
(= (getvar "tilemode") 0)
(= (getvar "cvport") 1)
)
(setq acsp (vla-get-paperspace adoc))
(setq acsp (vla-get-modelspace adoc))
)
(vla-startundomark (vla-get-activedocument
(vlax-get-acad-object)))
(initget 7)
(setvar 'textsize
(cond ((getdist (strcat "\nSpecify Area text height by two points on screen : ")
))
((getvar 'textsize))
)
)
(prompt "\nSelect objects on screen to add area label")
(if (setq ss (ssget))
(progn
(setq axss (vla-get-activeselectionset adoc))
(vlax-for obj axss
(if (not
(vl-catch-all-error-p
(setq
ar (vl-catch-all-apply
(function (lambda()
(vlax-curve-getarea obj)))))))
(progn
(setq txt (strcat "Area = " (rtos ar 2 2)"m"))
(vla-getboundingbox obj 'minp 'maxp)
(setq p1 (vlax-safearray->list minp)
p2 (vlax-safearray->list maxp)
pc (mapcar (function (lambda(a b)(/ (+ a b) 2))) p1 p2)
)
(vlax-invoke acsp 'Addtext txt pc (getvar 'textsize))
)
)
)
)
)
(vla-endundomark (vla-get-activedocument
(vlax-get-acad-object)))
(princ)
)
(princ)
(c:at)

;elbowReducer.lsp
;elbow reducing
;Clovis Masse
;28-01-2009
;ask for center of smallest diameter D1
;ask for center of elbow C
(defun c:er( / Cs Ce D1 D2 ok ang R1 listPointInfo board hoek Startangle nb)
;;sub
;degre to radian dtor
(defun DtoR (a) (* pi (/ a 180.0)))
(defun c:info ()
(princ(strcat
"\t----\n"
"\nbuild one with\n"
(itoa Section) " las\n"
"radius large section = "(rtos (car tListRayDia))
"\nlarge Diameter = "(rtos (cadr tListRayDia))
))
)
;new diameter
(defun testDia (lRayDia / rayonInt rayonExt diametre Ri1 Di1 rayon)
(setq Ri1 (car lRayDia)
Di1 (cadr lRayDia)
)
(setq rayonInt (*(- Ri1 (/ Di1 2.0))
(cos (/ ang section))
)
)
(setq rayonExt (/(+ Ri1 (/ Di1 2.0))
(cos (/ ang section))
)
)
(setq diametre (- rayonExt rayonInt))
(setq rayon (/(+ rayonExt rayonInt) 2.0))
(list rayon diametre)
)
;make pline
(defun mPline(alist / NewListPoint LPE slop board)
(setq board(vlax-get(vlax-get(vlax-get-acad-object)'activedocument)'modelspace))
(setq NewListPoint '())
(setq LPE(reverse alist))
(foreach point LPE
(setq NewListPoint(cons '0.0 NewListPoint))
(setq NewListPoint(cons (cadr point) NewListPoint))
(setq NewListPoint(cons (car point) NewListPoint))
)
(setq slop(vlax-make-safearray vlax-vbDouble (cons 0 (-(length NewListPoint)1)))
)
(vlax-safearray-fill slop NewListPoint)
(vla-AddPolyline board slop)
(vlax-release-object board)
)
;make line between outline
(defun mLine(lPExt lPInt / board count)
(setq board(vlax-get(vlax-get(vlax-get-acad-object)'activedocument)'modelspace))
(setq count 0)
(repeat (length lPExt)
(vla-addline board
(vlax-3d-point(nth count lPExt))
(vlax-3d-point(nth count lPInt))
)
(setq count(1+ count))
)
(vlax-release-object board)
)
;;end sub
(setq Cs(getpoint"\nCenter of small section:"))
(setq Ce(getpoint"\nCenter of elbow:"))
(setq D1(getDist"\nDiameter small section:"))
(setq D2(getDist"\nDiameter large section:"))
(setq ok nil)
(initget 3)
(setq ang(dtor(getReal"\nAngle of elbow:")))
(cond ((< D2 D1)(setq temp D1 D1 D2 D2 temp)) ;inverse D1 D2
((= D2 D1)(progn(alert "Both Diameters are equals")(exit)))
)
(setq R1(distance Cs Ce))
(setq listRayDia (list R1 D1))
(setq section 2)
(while (and(not ok)(<= section 1000))
(setq tListRayDia listRayDia) ;start fresh
(setq listPointInfo '())
(repeat section
(setq listPointInfo (cons tListRayDia listPointInfo))
(setq tListRayDia (testDia tListRayDia))
)
(if (= section 100)
(alert "Too many sections > 100")
(c:info)
)
;MAKE list of points
;(polar pt ang dist)
(setq listPointInfo (reverse listPointInfo))
(setq startangle (angle Ce Cs))
(setq hoek (/ ang section)
listPointExt '()
listPointInt '()
nb 0
)
(foreach point listPointInfo
(setq listPointExt
(cons (polar Ce (+(* nb hoek) startangle)(+ (car point)(/(cadr point)2.0))) list
PointExt)
)
(setq nb(1+ nb))
)
(setq nb 0)
(foreach point listPointInfo
(setq listPointInt
(cons (polar Ce (+(* nb hoek)startangle)(- (car point)(/(cadr point)2.0))) listP
ointInt)
)
(setq nb(1+ nb))
)
;make pline
(mPline listPointExt)
(mPline ListPointInt)
(mLine listPointExt listPointInt)
(princ)
)
(c:er)

;;; 2D Duct Drawing program. Draw user defined diameter duct with radius elbow w
ith Split Double-Split and Transition option
;;; Based on existing routines. Deeply modified by Igal Averbuh 2016
(defun rtd (a)
(/ (* a 180.0) pi)
)
(defun c:dr(/ eao)
(setvar "blipmode" 0)
(if (not cwidth)
(setq cwidth 0.0)
)
(MENUCMD "S=DUCT1")
(prompt (strcat "\n Enter duct width : "))
(setq tcwidth (getdist))
(if tcwidth
(setq cwidth tcwidth)
)
(MENUCMD "S=S")
(setq pt1 (getpoint "\nStart point... "))
(if pt1
(setq pt2 (getpoint pt1 "\nTo point... "))
)
(setq threshold 1
segment 0
oang nil
ofrad (getvar "filletrad")
)
(if (>= cwidth threshold)
(setq inrad (* 1.0 cwidth) outrad (* 2.0 cwidth))
)
(while pt2
(setq a (angle pt1 pt2)
1o1 (polar pt1 (+ a (/ pi 2.0)) (/ cwidth 2.0))
1o2 (polar pt2 (+ a (/ pi 2.0)) (/ cwidth 2.0))
ro1 (polar pt1 (- a (/ pi 2.0)) (/ cwidth 2.0))
ro2 (polar pt2 (- a (/ pi 2.0)) (/ cwidth 2.0))
)
(if (> segment 0)
(setq eao ea ebo eb)
(setq dimpt (polar pt1 (+ a (/ pi 2.0))(+ (/ cwidth 2.0) 1.0)))
)
(command "line" 1o1 1o2 "")
(setq ea (entlast))
(command "line" ro1 ro2 "")
(setq eb (entlast))
(if (and (> segment 0)(/= a oang)(/= pi (abs (- a oang))))
(progn
(setq xa (- oang a))
(if (or ( xa 0)( segment 0)
(setq po1 (cdr (assoc 11 (entget eao))))
)
(setq ss (ssadd eb))
(setq ss (ssadd ebo ss))
(setvar "filletrad" rb)
(command "fillet" (ssname ss 0)(ssname ss 1))
)
)
(setq pp2 (cdr (assoc 10 (entget eb))))
(if (> segment 0)
(setq po2 (cdr (assoc 11 (entget ebo))))
)
(if (and (> segment 0)(/= a oang))
(command "line" pp1 pp2 "")
(command "line" 1o1 ro1 "")
)
(if (and (> segment 0)(/= a oang))
(command "line" po1 po2 "")
)
(setq res "C")
(menucmd "S=duct2")
(initget "Continue Split Double-Split Transition")
(setq res (getkword (strcat "[Continue/Split/Double-Split/Transition] : ")))
(menucmd "S=S")
(cond
((or (= res "Transition")(= res "Transition")) (transition))
((or (= res "Split")(= res "Split")) (splitter))
((or (= res "Double-Split")(= res "Double-Split")) (splitter2))
(t (carryon))
)
) ;; END WHILE
(setq op1 (cdr (assoc 11 (entget ea))))
(setq op2 (cdr (assoc 11 (entget eb))))
(if (/= a oang)
(command "line" op1 op2 "")
(command "line" 1o2 ro2 "")
)
(setvar "filletrad" ofrad)
(setvar "cmdecho" 1)
(setvar "blipmode" 0)
(prin1)
)
(defun transition ()
(menucmd "S=DUCT1")
(setq newsize (getdist "\nEnter new size: "))
(menucmd "S=S")
(setq tlen (abs (* 3.732 (- cwidth newsize))))
(setq apt (getpoint pt2 "\nSide to remain straight"))
(setq rt-a (angle pt2 apt))
(setq s-rt (rtd (- a (/ pi 2.0))))
(if (< s-rt 0.0)
(setq s-rt (+ 360.0 s-rt))
)
; make sure all angles are positive ie -90 deg = 270 deg
(if (= (rtd rt-a) s-rt)
(setq dir "R")
(if (= rt-a a)
(setq dir "S")
(setq dir "L")
)
)
(if (= dir "L")
(setq newang (- a (/ pi 2.0)) spt 1o2)
(if (= dir "R")
(setq newang (+ a (/ pi 2.0)) spt ro2)
(setq newang a spt 1o2)
)
)
(if (or (= dir "R")(= dir "L"))
(progn
(setq l1p (polar spt a tlen))
(setq pt1 (polar l1p newang (/ newsize 2.0)))
(setq r1p (polar l1p newang newsize ))
(if (= dir "L")
(command "line" 1o2 ro2 r1p l1p "c")
(command "line" 1o2 ro2 l1p r1p "c")
)
) ; end progn
(progn
(setq tlen (/ tlen 2.0))
(setq p1 (polar pt2 a tlen))
(setq p2 (polar p1 (+ a (/ pi 2.0)) (/ newsize 2.0)))
(setq p3 (polar p2 (- a (/ pi 2.0)) newsize))
(command "line" p2 p3 ro2 1o2 p2 "")
(setq pt1 p1)
)
)
(setq pt2 (getpoint pt1 "\nTo point..."))
(if pt2
(progn
(while (< (+ (distance pt1 pt2) (/ cwidth 2.0)) outrad)
(setq pt2 (getpoint pt1 "\nTo point..."))
)
(setq segment (1+ segment))
(setq tcwidth newsize cwidth newsize oang a)
(setq inrad (* 1.0 cwidth) outrad (* 2.0 cwidth))
) ;; END PROGN
) ;; END IF
)
(defun carryon ()
;; BEGINNING FOR NORMAL CONTINUE OF DUCTING
(progn
(setq oang a
pt1 pt2
pt2 (getpoint pt1 "\nTo point..."))
(if pt2
(progn
(while (< (+ (distance pt1 pt2) (/ cwidth 2.0)) outrad)
(setq pt2 (getpoint pt1 "\nTo point..."))
)
(setq segment (1+ segment))
) ;; END PROGN
) ;; END IF
) ;; END OF PROGN FOR CONTINUE OPTION
)
;; branching ductwork
(defun splitter ()
(setq orth (getvar "ORTHOMODE"))
(setvar "ORTHOMODE" 1)
(setq apt (getpoint pt2 "\nDirection of Branch"))
(setq rt-a (angle pt2 apt))
(setq s-rt (rtd (- a (/ pi 2.0))))
(if (< s-rt 0.0)
(setq s-rt (+ 360.0 s-rt))
)
; make sure all angles are positive ie -90 deg = 270 deg
(if (= (rtd rt-a) s-rt)
(setq s-dir "R")
(setq s-dir "L")
)
(setvar "ORTHOMODE" orth)
(menucmd "S=duct1")
(setq s-dw1 (getdist "\nWidth of Branch Duct: "))
(setq s-dw2 (1+ cwidth))
; the main duct cannot increase here
(while (< cwidth s-dw2)
(setq s-dw2 (getdist "\nWidth of Continuing Main Duct: "))
)
(menucmd "S=S")
(setq c-side (* 2.0 s-dw1))
(if (= s-dir "R")
(setq s-1o2 1o2 s-ro2 ro2 arc-ang -90.0)
(setq s-1o2 ro2 s-ro2 1o2 arc-ang 90.0)
)
(setq s-p1 (polar s-1o2 a c-side))
(setq s-p2 (polar s-1o2 rt-a s-dw2))
(setq s-p3 (polar s-p2 a c-side))
(setq s-p4 (polar s-ro2 rt-a s-dw1))
(setq s-p5 (polar s-p4 a s-dw1))
(setq s-p6 (polar s-p5 a s-dw1))
(command "arc" s-ro2 "c" s-p4 "a" arc-ang)
(command "line" s-p5 s-p6 "")
(setq b-side (+ s-dw1 (- cwidth s-dw2)))
(setq a-side (sqrt (- (* c-side c-side)(* b-side b-side))))
(setq intpt (polar s-p2 a a-side))
(if (= s-dir "R")
(command "arc" s-p6 "c" s-p4 intpt)
(command "arc" intpt "c" s-p4 s-p6)
)
(command "line" intpt s-p3 s-p1 s-1o2 s-Ro2 "")
(setq 1o2 s-p1
ro2 s-p3
1o1 s-1o2
ro1 s-p2
pt1 (polar s-p1 rt-a (/ s-dw2 2.0))
cwidth s-dw2)
(setq pt2 (getpoint pt1 "\nTo point..."))
(setq tcwidth s-dw2 cwidth s-dw2 oang a)
(setq inrad (* 1.0 cwidth) outrad (* 2.0 cwidth))
)
(defun splitter2 ()
(setq s-rt (- a (/ pi 2.0)))
(setq s-rt2 (+ a (/ pi 2.0)))
(menucmd "S=duct1")
(setq s-dw1 (getdist "\nWidth of Left Branch Duct: "))
(setq s-dw2 (getdist "\nWidth of Right Branch Duct: "))
(setq rad1 (* 2.0 s-dw1))
(setq rad2 (* 2.0 s-dw2))
(setq c (+ s-dw1 s-dw2 cwidth))
(setq cosA (/ (- (+ (* RAD1 RAD1) (* c c))(* RAD2 RAD2)) (* 2.0 RAD1 c)))
(setq xlen (* cosA rad1))
(setq p1 (polar 1o2 s-rt2 s-dw1))
(setq p2 (polar p1 a s-dw1))
(setq p3 (polar p2 a s-dw1))
(setq xpt (polar p1 s-rt xlen))
(setq ylen (sqrt (- (* rad1 rad1)(* xlen xlen))))
(setq intpt (polar xpt a ylen))
(command "arc" intpt "c" p1 p3)
(command "arc" 1o2 "c" p1 p2)
(command "line" p2 p3 "")
(setq p1 (polar ro2 s-rt s-dw2))
(setq p2 (polar p1 a s-dw2))
(setq p3 (polar p2 a s-dw2))
(command "arc" p3 "c" p1 intpt)
(command "arc" p2 "c" p1 ro2)
(command "line" p2 p3 "")
(command "line" 1o2 ro2 "")
(setq 1o2 p2
ro2 p3
1o1 p2
ro1 p3
pt1 (polar p2 a (/ s-dw2 2.0))
cwidth s-dw2)
(setq pt2 (getpoint pt1 "\nTo point..."))
(setq tcwidth s-dw2 cwidth s-dw2 oang (- a (/ pi 2.0)))
(setq inrad (* 1.0 cwidth) outrad (* 2.0 cwidth))
)
(c:dr)

; Draws continuous pipe (or duct) of any size with user defined inner bend radiu
s (default = 0.0)
(defun c:dcd (/ d1 d p1 p2 p3 rd1 rd2 lu1 lu2 u1 u2 u3 u5 erd elu erd2
elu2 ofr)
(setq oerr *error*)
(defun *error* (msg)
(setvar "filletrad" ofr)
(setvar "osmode" osn)
(princ
"Function cancelled by user, or radius is too large "
)
(setq *error* oerr)
(command)
(princ)
)
(setq osn (getvar "osmode"))
(setq ofr (getvar "filletrad"))
(setvar "cmdecho" 0)
(if (= d2 nil)
(setq d2 1.0)
)
(princ "\n Pipe diameter / duct width ?:")
(setq d1 (getdist))
(if (= d1 nil)
(setq d1 d2)
)
(setq d2 d1)
(if (= r1 nil)
(setq r1 0.0)
)
(princ "\n Inner bend radius ?:")
(setq r (getdist))
(if (= r nil)
(setq r r1)
)
(setq r1 r)
(setq d (/ d1 2))
(setq p1 (getpoint "\n Start point: "))
(setq p2 (getpoint p1 "\n Next point: "))
(setq u1 (angle p1 p2))
(setq rd1 (polar p1 (- u1 (* pi 0.5)) d)) ; rd = right
(setq rd2 (polar rd1 u1 (distance p1 p2)))
(setq lu1 (polar p1 (+ u1 (* pi 0.5)) d)) ; lu = left
(setq lu2 (polar lu1 u1 (distance p1 p2)))
(setvar "osmode" 0)
(command "line" rd1 lu1 "")
(command "line" rd1 rd2 "")
(setq erd (entlast))
(command "line" lu1 lu2 "")
(setq elu (entlast))
(setvar "osmode" osn)
(setq p3 (getpoint p2 "\n Next"))
(setvar "osmode" 0)
(setq u2 (angle p2 p3))
(setq u5 (+ (- pi u1) u2))
(if (> u5 (* pi 2))
(setq u5 (- u5 (* pi 2)))
)
(if (< u5 0)
(setq u5 (+ (* pi 2) u5))
)
(while p3
(setq p1 p2)
(setq p2 p3)
(setq u1 (angle p1 p2))
(setq rd1 (polar p1 (- u1 (* pi 0.5)) d)) ; rd = right/down
(setq rd2 (polar rd1 u1 (distance p1 p2)))
(setq lu1 (polar p1 (+ u1 (* pi 0.5)) d)) ; lu = left/up
(setq lu2 (polar lu1 u1 (distance p1 p2)))
(command "line" rd1 rd2 "")
(setq erd2 (entlast))
(command "line" lu1 lu2 "")
(setq elu2 (entlast))
(if ( u5 pi)
(progn
(setvar "filletrad" (+ d1 r))
(command "fillet" erd erd2)
(setvar "filletrad" r)
(command "fillet" elu elu2)
)
)
(setq erd erd2)
(setq elu elu2)
(setvar "osmode" osn)
(setq p3 (getpoint p2 "\n Next:"))
(setvar "osmode" 0)
(if (= p3 nil)
()
(setq u2 (angle p2 p3))
)
(setq u5 (+ (- pi u1) u2))
(if (> u5 (* pi 2))
(setq u5 (- u5 (* pi 2)))
)
(if (< u5 0)
(setq u5 (+ (* pi 2) u5))
)
)
(command "line" rd2 lu2 "")
(setvar "osmode" osn)
(setvar "filletrad" ofr)
(princ)
)
(c:dcd)

;;; Convert multiple plines to pipes (ducts) with user defined diameter
(defun c:p2p(/ lSet plLst pl pl1 pl2 oldOsm
actDoc vLst1 vLst2 stLst *error*)
(vl-load-com)
(defun GetPlineVer(plObj)
(mapcar 'cdr
(vl-remove-if-not
'(lambda(x)(=(car x)10))
(entget plObj)))
); end of GetPLineVer
(defun asmi-LayersUnlock(/ restLst)
(setq restLst '())
(vlax-for lay
(vla-get-Layers
(vla-get-ActiveDocument
(vlax-get-acad-object)))
(setq restLst
(append restLst
(list
(list
lay
(vla-get-Lock lay)
(vla-get-Freeze lay)
); end list
); end list
); end append
); end setq
(vla-put-Lock lay :vlax-false)
(if
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-put-Freeze(list lay :vlax-false)))
t)
); end vlax-for
restLst
); end of asmi-LayersUnlock
(defun asmi-LayersStateRestore(StateList)
(foreach lay StateList
(vla-put-Lock(car lay)(cadr lay))
(if
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-put-Freeze(list(car lay)(nth 2 lay))))
t)
); end foreach
(princ)
); end of asmi-LayersStateRestore
(if(not duct:pWd)(setq duct:pWd 1.0))
(setq oldWd duct:pWd
duct:pWd(getdist
(strcat "\nSpecify pipes diameter : "))
); end setq
(if(null duct:pWd)(setq duct:pWd oldWd))
(princ "\n>>> Select polylines <<vla-object
(vl-remove-if 'listp
(mapcar 'cadr(ssnamex lSet))))
); end setq
(vla-StartUndoMark
(setq actDoc
(vla-get-ActiveDocument
(vlax-get-acad-object))))
(foreach pl plLst
(command "_.fillet" "_r" duct:pWd)
(command "_.fillet" "_p"
(vlax-vla-object->ename pl))
(setq pl1(car(vlax-safearray->list
(vlax-variant-value
(vla-Offset pl (/ duct:pWd 2)))))
pl2(car(vlax-safearray->list
(vlax-variant-value
(vla-Offset pl (-(/ duct:pWd 2))))))
vLst1(GetPlineVer
(vlax-vla-object->ename pl1))
vLst2(GetPlineVer
(vlax-vla-object->ename pl2))
); end setq
(vla-put-ConstantWidth pl1 0.0)
(vla-put-ConstantWidth pl2 0.0)
(vla-Delete pl)
(foreach itm vLst1
(setq oldOsm(getvar "OSMODE"))
(setvar "OSMODE" 0)
(command "._line" itm (car vLst2) "")
(setvar "OSMODE" oldOsm)
(setq vLst2(cdr vLst2))
); end foreach
(asmi-LayersStateRestore stLst)
); end foreach
(vla-EndUndoMark actDoc)
); end progn
); end if
(princ)
); end of c:p2p
(c:p2p)

;;; Draw user defined diameter duct with radius elbow (mline version)
(defun c:rd(/ actDoc ang1 ang2 ang3 ptLst enDist
fPt lEnt lObj lPln oldVars oldWd
plEnd plStart1 plStart2 prDir
segLst Start stDist stLst tAng
vlaPln *error*)
(vl-load-com)
(defun GetPlineVer(plObj)
(mapcar 'cdr
(vl-remove-if-not
'(lambda(x)(=(car x)10))
(entget plObj)))
); end of GetPLineVer
(defun asmi-PlineSegmentDataList(plObj / cLst outLst)
(setq cLst
(vl-remove-if-not
'(lambda(x)(member(car x) '(10 40 41 42)))
(entget plObj))
outLst '()
); end setq
(while cLst
(if(assoc 40 cLst)
(progn
(setq outLst
(append outLst
(list
(list
(cdr(assoc 10 cLst))
(cdr(assoc 40 cLst))
(cdr(assoc 41 cLst))
(cdr(assoc 42 cLst))
); end list
); end list
); end if
); end setq
(repeat 4
(setq cLst(cdr cLst))
); end repeat
); end progn
(setq outLst
(append outLst
(list
(list
(cdr(assoc 10 cLst))
); end list
); end list
); end append
cLst nil
); end setq
); end if
); end while
outLst
); end of asmi-GetPlineSegmentData
(defun asmi-LayersUnlock(/ restLst)
(setq restLst '())
(vlax-for lay
(vla-get-Layers
(vla-get-ActiveDocument
(vlax-get-acad-object)))
(setq restLst
(append restLst
(list
(list
lay
(vla-get-Lock lay)
(vla-get-Freeze lay)
); end list
); end list
); end append
); end setq
(vla-put-Lock lay :vlax-false)
(if
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-put-Freeze(list lay :vlax-false)))
t)
); end vlax-for
restLst
); end of asmi-LayersUnlock
(defun asmi-LayersStateRestore(StateList)
(foreach lay StateList
(vla-put-Lock(car lay)(cadr lay))
(if
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-put-Freeze(list(car lay)(nth 2 lay))))
t)
); end foreach
(princ)
); end of asmi-LayersStateRestore
(defun PipeMLineStyle(/ dxfLst mlDict)
(setq dxfLst
(list'(0 . "MLINESTYLE")'(102 . "{ACAD_REACTORS")'(102 . "}")
'(100 . "AcDbMlineStyle") '(2 . "DUCT_PIPE")
'(70 . 272)'(3 . "")'(62 . 256)'(51 . 1.5708)'(52 . 1.5708)
'(71 . 2)'(49 . 0.5)'(62 . 256)'(6 . "BYBLOCK")
'(49 . -0.5)'(62 . 256)'(6 . "BYBLOCK"))); end setq
(if
(null
(member
(assoc 2 dxfLst)
(dictsearch
(namedobjdict)
"ACAD_MLINESTYLE")))
(progn
(setq mlDict
(cdr
(assoc -1
(dictsearch
(namedobjdict)
"ACAD_MLINESTYLE"))))
(dictadd mlDict
(cdr(assoc 2 dxfLst))(entmakex dxfLst))
); end progn
); end if
); end of PipeMLineStyle
(defun SideCalculate(Rad Ang)
(setq Ang(- pi Ang))
(*
(/
(sqrt(-(* 2(expt Rad 2))(* 2(expt Rad 2)(cos Ang))))
(sin(- pi Ang)))(sin(/(- pi(- pi Ang))2)
)
)
); end of SideCalculate
(defun *error*(msg)
(setvar "CMDECHO" 0)
(if lObj
(command "_.erase"(entnext lObj)"")
(command "_.erase"(entlast)"")
); end if
(if oldVars
(mapcar 'setvar
'("FILLMODE" "PLINEWID" "CMDECHO" "OSMODE")
oldVars); end mapcar
); end if
(if stLst
(asmi-LayersStateRestore stLst)
); end if
(if actDoc
(vla-EndUndoMark actDoc)
); end if
(princ "*Cancel* ")
(princ)
); end of *error*
(PipeMLineStyle)
(if(not dpipepWd)(setq dpipepWd 1.0))
(setq oldWd dpipepWd
dpipepWd(getdist
(strcat "\nSpecify first segment width : "))
oldVars(mapcar 'getvar '("FILLMODE" "PLINEWID" "CMDECHO" "OSMODE"))
); end setq
(if(null dpipepWd)(setq dpipepWd oldWd))
(mapcar 'setvar
'("FILLMODE" "PLINEWID" "CMDECHO")
(list 0 dpipepWd 1)); end mapcar
(if(entlast)(setq lObj(entlast)))
(vla-StartUndoMark
(setq actDoc
(vla-get-ActiveDocument
(vlax-get-acad-object))))
(setq fPt
(getpoint "\nSpecify start point: ")
); end setq
(command "_.pline" fPt)
(while(= 1(getvar "CMDACTIVE"))
(command pause)
); end while
(if
(not
(equal lObj(entlast)))
(progn
(setq lEnt(entlast)
stLst(asmi-LayersUnlock)
segLst(asmi-PlineSegmentDataList lEnt)
vlaPln(vlax-ename->vla-object lEnt)
); end setq
(setvar "OSMODE" 0)
(setvar "CMDECHO" 0)
(while (/= 1(length segLst))
(setq stDist
(vlax-curve-getDistAtPoint vlaPln
(caar segLst))
enDist
(vlax-curve-getDistAtPoint vlaPln
(caadr segLst))
); end setq
(if( ang1 ang2)
(setq ang3(- ang1 ang2))
(setq ang3(- ang2 ang1))
); end if
(setq ang3(- pi ang3)
tAng ang3)
(if(minusp ang3)(setq ang3(- ang3)))
); end progn
); end if
(if
(or
(equal ang1 ang2 0.000001)
(= 2(length segLst))
); end or
(setq plEnd
(vlax-curve-getPointAtDist vlaPln
enDist)
prDir T); end setq
(setq plEnd
(vlax-curve-getPointAtDist vlaPln
(- enDist(SideCalculate(cadar segLst)ang3)))
prDir nil); end setq
); end if
(if
(< 2(length segLst))
(setq plStart2
(vlax-curve-getPointAtDist vlaPln
(+ enDist(SideCalculate(cadar segLst)ang3)))); end setq
); end if
(if(< 2(length segLst))
(if
(=(cadar segLst)(nth 2(car segLst)))
(setq ptLst
(mapcar
'(lambda(x)(trans x 0 1)); end lambda
(list(polar plEnd ang1 (/(cadar segLst)2))
(polar plEnd (+ pi ang1)(/(cadar segLst)2))
(polar plStart2 (+ pi ang2)(/(cadar segLst)2))
(polar plStart2 ang2 (/(cadar segLst)2))
); end list
); end mapcar
); end setq
(setq ptLst
(mapcar
'(lambda(x)(trans x 0 1)); end lambda
(list (polar plStart1 ang1 (/(cadar segLst)2))
(polar plStart1 (+ pi ang1)(/(cadar segLst)2))
(polar(caadr segLst)(+ pi ang2)(/(nth 2(car segLst))2))
(polar(caadr segLst)ang2(/(nth 2(car segLst))2))
); end list
); end mapcar
); end setq
); end if
); end if
(setq plStart1(trans plStart1 0 1)
plEnd(trans plEnd 0 1)
); end setq
(if plStart2
(setq plStart2(trans plStart1 0 1))
); end if
(if
(and
(< 2(length segLst))
(or
(not(equal ang1 ang2 0.000001))
(/=(cadar segLst)(nth 2(car segLst)))
); end or
); end and
(progn
(setvar "PLINEWID" 0.0)
(command "_.pline")
(mapcar 'command ptLst)(command "_c")
(setvar "PLINEWID" dpipepWd)
); end progn
); end if
(if
(and
(not(equal ang1 ang2 0.000001))
(vla-object(entlast))
tAng(- ang2 ang1)
); end setq
(if(minusp tAng)(setq tAng(- tAng)))
(if
(and
(= pi tAng)
); end and
(progn
(vla-SetBulge lPln 1 (/(- ang2 ang1)4))
(vla-SetBulge lPln 3 (/(- ang1 ang2)4))
); end progn
(progn
(if(< ang1 ang2)
(setq ang1(+ ang1 pi)
ang2(- ang2 pi)); end setq
(setq ang1(- ang1 pi)
ang2(+ ang2 pi)); end setq
); end if
(vla-SetBulge lPln 1 (/(- ang2 ang1)4))
(vla-SetBulge lPln 3 (/(- ang1 ang2)4))
); end progn
); end if
); end progn
); end if
(if
(=(cadar segLst)(nth 2(car segLst)))
(command "_.mline" "_st" "DUCT_PIPE"
"_S" (cadar segLst) "_J" "_Z"
plStart1 plEnd "")
); end if
(setq segLst(cdr segLst)); end setq
); end while
(command "_.erase" lEnt "")
(asmi-LayersStateRestore stLst)
); end progn
); end if
(vla-EndUndoMark actDoc)
(mapcar 'setvar
'("FILLMODE" "PLINEWID" "CMDECHO" "OSMODE")
oldVars); end apply
(princ)
); end of c:rd
(c:rd)
;;; Convert pline to user defined diameter Duct or Pipe with radius elbow (mline
version)
(defun c:pd(/ actDoc Ang1 Ang2 enDist stDist lEnt
lObj lPln oldVars oldWd plEnd plLst
plSet plStart1 plStart2 prDir ptLst
segLst Start stLst tAng vlaPln)
(vl-load-com)
(defun GetPlineVer(plObj)
(mapcar 'cdr
(vl-remove-if-not
'(lambda(x)(=(car x)10))
(entget plObj)))
); end of GetPLineVer
(defun asmi-PlineSegmentDataList(plObj / cLst outLst)
(setq cLst
(vl-remove-if-not
'(lambda(x)(member(car x) '(10 40 41 42)))
(entget plObj))
outLst '()
); end setq
(while cLst
(if(assoc 40 cLst)
(progn
(setq outLst
(append outLst
(list
(list
(cdr(assoc 10 cLst))
(cdr(assoc 40 cLst))
(cdr(assoc 41 cLst))
(cdr(assoc 42 cLst))
); end list
); end list
); end if
); end setq
(repeat 4
(setq cLst(cdr cLst))
); end repeat
); end progn
(setq outLst
(append outLst
(list
(list
(cdr(assoc 10 cLst))
); end list
); end list
); end append
cLst nil
); end setq
); end if
); end while
outLst
); end of asmi-GetPlineSegmentData
(defun asmi-LayersUnlock(/ restLst)
(setq restLst '())
(vlax-for lay
(vla-get-Layers
(vla-get-ActiveDocument
(vlax-get-acad-object)))
(setq restLst
(append restLst
(list
(list
lay
(vla-get-Lock lay)
(vla-get-Freeze lay)
); end list
); end list
); end append
); end setq
(vla-put-Lock lay :vlax-false)
(if
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-put-Freeze(list lay :vlax-false)))
t)
); end vlax-for
restLst
); end of asmi-LayersUnlock
(defun asmi-LayersStateRestore(StateList)
(foreach lay StateList
(vla-put-Lock(car lay)(cadr lay))
(if
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-put-Freeze(list(car lay)(nth 2 lay))))
t)
); end foreach
(princ)
); end of asmi-LayersStateRestore
(defun PipeMLineStyle(/ dxfLst mlDict)
(setq dxfLst
(list'(0 . "MLINESTYLE")'(102 . "{ACAD_REACTORS")'(102 . "}")
'(100 . "AcDbMlineStyle") '(2 . "DUCT_PIPE")
'(70 . 272)'(3 . "")'(62 . 256)'(51 . 1.5708)'(52 . 1.5708)
'(71 . 2)'(49 . 0.5)'(62 . 256)'(6 . "BYBLOCK")
'(49 . -0.5)'(62 . 256)'(6 . "BYBLOCK"))); end setq
(if
(null
(member
(assoc 2 dxfLst)
(dictsearch
(namedobjdict)
"ACAD_MLINESTYLE")))
(progn
(setq mlDict
(cdr
(assoc -1
(dictsearch
(namedobjdict)
"ACAD_MLINESTYLE"))))
(dictadd mlDict
(cdr(assoc 2 dxfLst))(entmakex dxfLst))
); end progn
); end if
); end of PipeMLineStyle
(defun *error*(msg)
(if oldVars
(mapcar 'setvar
'("CMDECHO" "OSMODE" "PLINEWID")
oldVars); end mapcar
); end if
(if stLst
(asmi-LayersStateRestore stLst)
); end if
(if actDoc
(vla-EndUndoMark actDoc)
); end if
(princ)
); end of *error*
(PipeMLineStyle)
(if(not mpipepWd)(setq mpipepWd 1.0))
(setq oldWd mpipepWd
mpipepWd(getdist
(strcat "\nSpecify duct pipe width : "))
); end setq
(if(null mpipepWd)(setq mpipepWd oldWd))
(vla-StartUndoMark
(setq actDoc
(vla-get-ActiveDocument
(vlax-get-acad-object))))
(setq oldVars(mapcar 'getvar '("CMDECHO" "OSMODE" "PLINEWID")))
(princ "\n>>> Select polylines to transform to duct pipes <<vla-object pl)
); end setq
(while (/= 1(length segLst))
(setq stDist
(vlax-curve-getDistAtPoint vlaPln
(caar segLst))
enDist
(vlax-curve-getDistAtPoint vlaPln
(caadr segLst))
); end setq
(if(< 2(length segLst))
(setq ang1
(+(/ pi 2)(angle(caar segLst)(caadr segLst)))
ang2
(+(/ pi 2)(angle(caadr segLst)(car(nth 2 segLst))))
); end setq
); end if
(if
(or
(not Start)
prDir
);end or
(setq plStart1
(vlax-curve-getPointAtDist vlaPln
stDist)
Start T); end setq
(setq plStart1
(vlax-curve-getPointAtDist vlaPln
(+ stDist mpipepWd))); end setq
); end if
(if
(or
(equal ang1 ang2 0.000001)
(= 2(length segLst))
); end or
(setq plEnd
(vlax-curve-getPointAtDist vlaPln
enDist)
prDir T); end setq
(setq plEnd
(vlax-curve-getPointAtDist vlaPln
(- enDist mpipepWd))
prDir nil); end setq
); end if
(if
(vla-object(entlast))
tAng(- ang2 ang1)
); end setq
(if(minusp tAng)(setq tAng(- tAng)))
(if
(and
(= pi tAng)
); end and
(progn
(vla-SetBulge lPln 1 (/(- ang2 ang1)4))
(vla-SetBulge lPln 3 (/(- ang1 ang2)4))
); end progn
(progn
(vla-SetBulge lPln 1(/(- ang1 ang2)12))
(vla-SetBulge lPln 3(/(- ang2 ang1)12))
); end progn
); end if
); end progn
); end if
(command "_.mline" "_st" "DUCT_PIPE"
"_S" mpipepWd "_J" "_Z"
plStart1 plEnd "")
(setq segLst(cdr segLst)); end setq
); end while
(vla-Delete vlaPln)
); end foreach
(vla-EndUndoMark actDoc)
(asmi-LayersStateRestore stLst)
); end progn
); end if
(mapcar 'setvar
'("CMDECHO" "OSMODE" "PLINEWID")
oldVars); end apply
(princ)
); end of c:pd
(c:pd)

;;; Draw user defined diameter duct with radius elbow with center lines (axes)
(defun c:dc (/ d1 d p1 p2 p3 rd1 rd2 lu1 lu2 u1 u2 u3 u5 erd elu erd2
elu2 ofr cl cl1 rc cr u10 u11 pc1 pc2 pc3 pc4 fa)
(setq oerr *error*)
(defun *error* (msg)
(setvar "filletrad" ofr)
(setvar "osmode" osn)
(princ
"Function cancelled by user, or radius is too large "
)
(setq *error* oerr)
(command)
(princ)
)
(command "_.undo" "begin")
(setq osn (getvar "osmode"))
(setq ofr (getvar "filletrad"))
(setvar "cmdecho" 0)
(if (= d2 nil)(setq d2 1.0))
(princ "\n Pipe diameter / duct width ?:")
(setq d1 (getdist))
(if (= d1 nil)(setq d1 d2)(setq d2 d1))
(if (= r1 nil)(setq r1 0.0))
(princ "\n Inner bend radius ?:")
(setq r (getdist))
(if (= r nil)(setq r r1)(setq r1 r))
(setq d (/ d1 2)); pipe radius or duct half-width
(setq rc (+ r d)); center line bend radius
(setq p1 (getpoint "\n Start point: "))
(setq p2 (getpoint p1 "\n Next point: "))
(command "-layer" "m" "1" "")
(command "-layer" "m" "axes" "")
(command "-layer" "lt" "center" "" "")
(command "-layer" "c" "1" "" "")
(command "clayer" "1")
(command "line" p1 p2 ""); center line first segment
(setq cl1 (entlast))
(command "change" cl1 "" "p" "la" "axes" "" "")
(setq u1 (angle p1 p2))
(setq rd1 (polar p1 (- u1 (* pi 0.5)) d)) ; first point = rd = right
(setq rd2 (polar rd1 u1 (distance p1 p2)))
(setq lu1 (polar p1 (+ u1 (* pi 0.5)) d)) ; first point = lu = left
(setq lu2 (polar lu1 u1 (distance p1 p2)))
(setvar "osmode" 0)
(command "line" rd1 lu1 ""); cross line = L=diameter
(command "line" rd1 rd2 ""); first line (right)
(setq erd (entlast)); first line
(command "line" lu1 lu2 ""); first line (left)
(setq elu (entlast))
(setvar "osmode" osn)
(setq p3 (getpoint p2 "\n Next"))
(setvar "osmode" 0)
(setq u2 (angle p2 p3))
(setq u5 (+ (- pi u1) u2))
(if (> u5 (* pi 2))(setq u5 (- u5 (* pi 2))))
(if (< u5 0)(setq u5 (+ (* pi 2) u5)))
(while p3
(setq p1 p2)
(setq p2 p3)
(setq u1 (angle p1 p2))
(command "line" p1 p2 "")
(setq cl (entlast))
(command "change" cl "" "p" "la" "axes" "" "")
(setq rd1 (polar p1 (- u1 (* pi 0.5)) d)) ; rd = right/down
(setq rd2 (polar rd1 u1 (distance p1 p2)))
(setq lu1 (polar p1 (+ u1 (* pi 0.5)) d)) ; lu = left/up
(setq lu2 (polar lu1 u1 (distance p1 p2)))
(command "line" rd1 rd2 "")
(setq erd2 (entlast))
(command "line" lu1 lu2 "")
(setq elu2 (entlast))
(if ( u5 (* pi 2))(setq u5 (- u5 (* pi 2))))
(if (< u5 0)(setq u5 (+ (* pi 2) u5))))
(command "line" rd2 lu2 "")
(command "_.undo" "end")
(setvar "osmode" osn)
(setvar "filletrad" ofr)
(princ)
)

;;; Draw a "Smart" Duct with respect to many features of duct like elbow type, t
ext inside duct, center line, hatch duct and other.
(defun bd( dpipepwd dpipeert)
(if (not (tblsearch "LAYER" "axes"))
(command "_.-layer" "_m" "axes" "_c" "1" "" "_lt" "center" "" "")
)
;centerline properties format '("layer" "color" "ltype" "lweight")
(setq dpropcln '("axes" "Bylayer" "Bylayer" ""))
(if (not (tblsearch "LAYER" "patt"))
(command "_.-layer" "_m" "patt" "_c" "8" "" "_lt" "continuous" "" "")
)
;dproppat = hatching properties format '("name" "scale" "layer" "color" "ltype"
"lweight")
(setq dproppat '("ANSI32" 50.0 "patt" "Bylayer" "Bylayer" ""))
(if (not (tblsearch "LAYER" "1"))
(command "_.-layer" "_m" "1" "_c" "7" "" "_lt" "continuous" "" "")
)
;dpropobj = objectline properties format '("layer" "color" "ltype" "lweight")
(setq dpropobj '("1" "Bylayer" "Bylayer" ""))
(wpipe "Radius" dpipeert (/ pi 12) "None" 3 dpipepwd dpipesuf nil)
)
;dproptxt = text/label properties format '("style" "textsize" "layer" "color" "l
type" "lweight")
;(setq dproptxt '("Label" 0.1 "text" "Bylayer" "Bylayer" ""))
;(if (not (tblsearch "STYLE" "Label"))
; (command "_.-style" "Label" "romans" 0.0 1.0 0.0 "_N" "_N" "_N")
; )
;
;(wpipe "Mitered" 6 (/ pi 12) "None" 3 12 "x12" nil)
;(wpipe "Radius" "1.5" (/ pi 12) "All" 3 12 "%%c" nil)
;(defun c:tray( / LAY)
;;dproppat = hatching properties format '("name" "scale" "layer" "color" "ltype"
"lweight")
;(setq dproppat '("MUDST" 4.0 "" "8" "Bylayer" ""))
;(wpipe "Chamfered" 6 (/ pi 12) "All" 2 nil " " nil)
;)
;(defun c:pipe()
;(wpipe "Radius" "1.5" (/ pi 12) "None" 3 nil (strcat (if (= (getvar "MEASUREMEN
T") 0) "\"" "") "%%C") nil)
;)
;(defun c:duct()
;(wpipe nil nil (/ pi 12) "None" nil nil nil nil)
;)
(defun wpipe ( dpipeelb dpipeert dpipetrn dpipepat dpipecln dpipepwd dpipesuf dp
ipefpt /
actDoc ang1 ang2 ang3 ptLst enDist
dlastfpt
dpipetan
dpiperad ; = specified radius
fPt lEnt lObj lPln oldVars oldWd
plEnd plStart1 plStart2 pwd
prDir dlp txEnt
OldLineType NewLineType
segLst Start stDist stLst tAng
vlaPln cFlg *error*
;dpipewd
)
(vl-load-com)
(defun GetPlineVer(plObj)
(mapcar 'cdr
(vl-remove-if-not
'(lambda(x)(=(car x)10))
(entget plObj)))
); end of GetPLineVer
(defun asmi-PlineSegmentDataList(plObj / cLst outLst)
(setq cLst
(vl-remove-if-not
'(lambda(x)(member(car x) '(10 40 41 42)))
(entget plObj))
outLst '()
); end setq
(while cLst
(if(assoc 40 cLst)
(progn
(setq outLst
(append outLst
(list
(list
(cdr(assoc 10 cLst))
(cdr(assoc 40 cLst))
(cdr(assoc 41 cLst))
(cdr(assoc 42 cLst))
); end list
); end list
); end if
); end setq
(repeat 4
(setq cLst(cdr cLst))
); end repeat
); end progn
(setq outLst
(append outLst
(list
(list
(cdr(assoc 10 cLst))
); end list
); end list
); end append
cLst nil
); end setq
); end if
); end while
outLst
); end of asmi-GetPlineSegmentData
(defun asmi-LayersUnlock(/ restLst)
(setq restLst '())
(vlax-for lay
(vla-get-Layers
(vla-get-ActiveDocument
(vlax-get-acad-object)))
(setq restLst
(append restLst
(list
(list
lay
(vla-get-Lock lay)
(vla-get-Freeze lay)
); end list
); end list
); end append
); end setq
(vla-put-Lock lay :vlax-false)
(if
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-put-Freeze(list lay :vlax-false)))
t)
); end vlax-for
restLst
); end of asmi-LayersUnlock
(defun asmi-LayersStateRestore(StateList)
(foreach lay StateList
(vla-put-Lock(car lay)(cadr lay))
(if
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-put-Freeze(list(car lay)(nth 2 lay))))
t)
); end foreach
(princ)
); end of asmi-LayersStateRestore
(defun PipeMLineStyle(/ dxfLst mlDict)
(setq dxfLst
(list'(0 . "MLINESTYLE")'(102 . "{ACAD_REACTORS")'(102 . "}")
'(100 . "AcDbMlineStyle") '(2 . "DUCT_PIPE")
'(70 . 274)'(3 . "")'(62 . 256)'(51 . 1.5708)'(52 . 1.5708)
'(71 . 2)'(49 . 0.5)'(62 . 256)'(6 . "BYBLOCK")
'(49 . -0.5)'(62 . 256)'(6 . "BYBLOCK"))); end setq
(if
(null
(member
(assoc 2 dxfLst)
(dictsearch
(namedobjdict)
"ACAD_MLINESTYLE")))
(progn
(setq mlDict
(cdr
(assoc -1
(dictsearch
(namedobjdict)
"ACAD_MLINESTYLE"))))
(dictadd mlDict
(cdr(assoc 2 dxfLst))(entmakex dxfLst))
); end progn
); end if
); end of PipeMLineStyle
(defun SideCalculate(Wdth Ang / Rad)
(setq Ang(- pi Ang))
(setq Rad(+ (* 0.5 Wdth)(if (/= "Segmented" dpipeelb "Radius") 0.0 (if (numberp
dpiperad) dpiperad (* (- (distof dpiperad) 0.5) Wdth))))
)
(+ (if (/= "Chamfered" dpipeelb "Mitered")
0
(if (= dpipeelb "Mitered")
dpipetan
(+ (* dpipetan 0.5) (/ dpipetan 2.0 (cos (/ Ang 2.0))))
)
)
(*
(/
(sqrt(-(* 2(expt Rad 2))(* 2(expt Rad 2)(cos Ang))))
(sin(- pi Ang)))(sin(/(- pi(- pi Ang))2.0)
)
)
)
); end of SideCalculate
(defun BodyFunction()
(if
(not
(equal lObj(entlast)))
(progn
(setq lEnt(entlast)
stLst(asmi-LayersUnlock)
segLst(asmi-PlineSegmentDataList lEnt)
vlaPln(vlax-ename->vla-object lEnt)
); end setq
(setvar "OSMODE" 0)
(setvar "CMDECHO" 0)
(if (/= 1 (length segLst))
(progn
(if (or (/= (type dpropcln) 'LIST) (not (equal (mapcar 'type dpropcln) '(STR STR
STR STR))))
(setq dpropcln '("" "7" "Center2" ""));centerline properties format '("layer" "c
olor" "ltype" "lweight")
)
(if (and (= (logand dpipecln 1) 1) (read (caddr dpropcln)) (not (member (strcase
(caddr dpropcln)) '("BYBLOCK" "BYLAYER" "CONTINUOUS"))) (not (tblsearch "LTYPE"
(caddr dpropcln))))
(command "_.linetype" "_l" (caddr dpropcln) (findfile (nth (getvar "MEASUREMENT"
) '("acad.lin" "acadiso.lin"))) "")
)
(if (or (/= (type dproppat) 'LIST) (not (equal (mapcar 'type dproppat) '(STR REA
L STR STR STR STR))))
(setq dproppat '("ANSI32" 50.0 "" "8" "" ""));hatching properties format '("name
" "scale" "layer" "color" "ltype" "lweight")
)
(if (and (/= dpipepat "None") (read (nth 4 dproppat)) (not (member (strcase (nth
4 dproppat)) '("BYBLOCK" "BYLAYER" "CONTINUOUS"))) (not (tblsearch "LTYPE" (nth
4 dproppat))))
(command "_.linetype" "_l" (nth 4 dproppat) (findfile (nth (getvar "MEASUREMENT"
) '("acad.lin" "acadiso.lin"))) "")
)
(if (or (/= (type dproptxt) 'LIST) (not (equal (mapcar 'type dproptxt) '(STR REA
L STR STR STR STR))))
(setq dproptxt (list (getvar "TEXTSTYLE") (getvar "TEXTSIZE") "" "1" "" ""));tex
t label properties format '("style" "textsize" "layer" "color" "ltype" "lweight"
)
)
);end progn
);end if
(while (/= 1(length segLst))
(setq stDist
(vlax-curve-getDistAtPoint vlaPln
(caar segLst))
enDist
(vlax-curve-getDistAtPoint vlaPln
(caadr segLst))
); end setq
(if( ang1 ang2)
(setq ang3(- ang1 ang2))
(setq ang3(- ang2 ang1))
); end if
(setq ang3(- pi ang3)
tAng ang3)
(if(minusp ang3)(setq ang3(- ang3)))
); end progn
); end if
(if
(or
(equal ang1 ang2 0.000001)
(= 2(length segLst))
); end or
(setq plEnd
(vlax-curve-getPointAtDist vlaPln
enDist)
prDir T); end setq
(setq plEnd
(vlax-curve-getPointAtDist vlaPln
(- enDist(SideCalculate(cadar segLst)ang3)))
prDir nil); end setq
); end if
(if
(< 2(length segLst))
(setq plStart2
(vlax-curve-getPointAtDist vlaPln
(+ enDist(SideCalculate(cadar segLst)ang3)))); end setq
); end if
(if(< 2(length segLst))
(if
(=(cadar segLst)(nth 2(car segLst)))
(setq ptLst
(mapcar
'(lambda(x)(trans x 0 1)); end lambda
(append
(if (/= dpipeelb "Radius")
(progn
(setq ang4 (apply '(lambda(x)(atan x (sqrt (abs (1- (* x x))))))
(list (sin (- ang1 (/ pi 2.0) (angle plEnd plStart2)))))
)
(setq SegNum (cond ((or (/= dpipeelb "Segmented") (< (abs ang4)
(* (/ 35 360.0) pi))) 2) ((< (abs ang4) (* (/ 55 360.0) pi)) 3)
((< (abs ang4) (* (/ 75 360.0) pi)) 4) (T 5))
)
(setq tan4 (+ (if (= dpipeelb "Segmented") 0
(if (= dpipeelb "Mitered")
dpipetan (+ (* dpipetan 0.5) (/ dpipetan 2.0 (cos ang4)))))
(* (+ (* 0.5 (cadar segLst))
(if (/= dpipeelb "Segmented") 0.0 (if (numberp
dpiperad) dpiperad (* (- (distof dpiperad) 0.5) (cadar segLst)))))
(abs (apply '(lambda(x) (/ (sin x) (cos x))) (list (/ ang4
0.5 (1- SegNum) 2.0))))))
)
(setq mllst (list plEnd (polar plEnd (- ang1 (/ pi 2.0)) tan4)))
(setq SegCnt 0)
(while (< (+ SegCnt 2) SegNum)
(setq mllst (append mllst (list (polar (last mllst)
(+ (angle (cadr (reverse mllst)) (last mllst))
(/ ang4 -0.5 (1- SegNum))) (* tan4 2.0)))
)
SegCnt (1+ SegCnt)
)
)
(setq mllst (append mllst (list PlStart2)))
(setq SegCnt (- (length mllst) 2))
(setq pllst nil)
(if (and (= dpipeelb "Chamfered")
( SegCnt 0)
(setq pllst (append pllst (list (polar (nth SegCnt mllst)
(+ (angle (nth (1- SegCnt) mllst) (nth SegCnt mllst))
(/ pi 2.0) (/ ang4 0.5 (1- SegNum) -2.0))
(/(cadar segLst)2(cos (/ ang4 0.5 (1- SegNum) 2.0)))))
)
SegCnt (1- SegCnt)
)
)
)
; )
pllst
)
)
(list(polar plEnd ang1 (/(cadar segLst)2)))
(list(polar plEnd (+ pi ang1)(/(cadar segLst)2)))
(if (/= dpipeelb "Radius")
(progn
(setq SegCnt 1)
(setq pllst nil)
(if (and (= dpipeelb "Chamfered")
(< (distance (polar plStart2 (+ pi ang2) (/(cadar segLst)2)) (polar plEnd (+ pi
ang1) (/(cadar segLst)2)))
(distance (polar plStart2 ang2 (/(cadar segLst)2)) (polar plEnd ang1 (/(cadar se
gLst)2)))))
(setq pllst (list(polar (polar plEnd (+ pi ang1) (/(cadar segLst)2)) (- ang1 (/
pi 2)) (* dpipetan 0.5))
(polar (polar plStart2 (+ pi ang2) (/(cadar segLst)2)) (+ ang2 (/ pi 2)) (* dpip
etan 0.5)))
)
(while (< SegCnt (1- (length mllst)))
(setq pllst (append pllst (list (polar (nth SegCnt mllst)
(+ (angle (nth (1- SegCnt) mllst) (nth SegCnt mllst))
(* pi 1.5) (/ ang4 0.5 (1- SegNum) -2.0))
(/(cadar segLst)2(cos (/ ang4 0.5 (1- SegNum) 2.0)))))
)
SegCnt (1+ SegCnt)
)
)
)
(setq mllst (mapcar '(lambda(x)(trans x 0 1)) mllst))
pllst
)
)
(list(polar plStart2 (+ pi ang2)(/(cadar segLst)2)))
(list(polar plStart2 ang2 (/(cadar segLst)2)))
); end append
); end mapcar
); end setq
(setq ptLst
(mapcar
'(lambda(x)(trans x 0 1)); end lambda
(list (polar plStart1 ang1 (/(cadar segLst)2))
(polar plStart1 (+ pi ang1)(/(cadar segLst)2))
(polar(caadr segLst)(+ pi ang2)(/(nth 2(car segLst))2))
(polar(caadr segLst)ang2(/(nth 2(car segLst))2))
); end list
); end mapcar
); end setq
); end if
); end if
(setq plStart1(trans plStart1 0 1)
plEnd(trans plEnd 0 1)
); end setq
(if plStart2
(setq plStart2(trans plStart1 0 1))
); end if
(if (< 2(length segLst))
(if (or (/=(cadar segLst)(nth 2(car segLst)))
(and (/= "Segmented" dpipeelb) (not(equal ang1 ang2 0.000001))
); end and
); end or
(progn
(setvar "PLINEWID" 0.0)
(command "_.pline")
(mapcar 'command ptLst)(command "_c")
(setvar "PLINEWID" dpipepWd)
(if (and (/= dpipepat "None") (or (/= (cadar segLst) (nth 2(car segLst))) (and (
not (equal ang1 ang2 0.000001)) (= dpipepat "All") (/= "Radius" dpipeelb))))
(command "_.hatch" (nth 0 dproppat) (nth 1 dproppat) (if (< (sin (* PI 0.125)) (
abs (sin ang1)) (sin (* PI 0.375))) 45 0) "_l" "" "_.change" "_l" "" "_p" "_la"
(nth 2 dproppat) "_c" (nth 3 dproppat) "_lt" (nth 4 dproppat) "_lw" (nth 5 dprop
pat) "")
)
(if (and (= (logand dpipecln 1) 1) (or (equal ang1 ang2 0.000001) (/= "Radius" d
pipeelb)))
(progn
(setvar "PLINEWID" 0.0)
(command "_.pline")
(mapcar 'command (if (/= (cadar segLst) (nth 2(car segLst))) (list plStart1 plEn
d) mlLst))
(command "")
(setvar "PLINEWID" dpipepWd)
(command "_.change" "_l" "" "_p" "_la" (nth 0 dpropcln) "_c" (nth 1 dpropcln) "_
lt" (nth 2 dpropcln) "_lw" (nth 3 dpropcln) "")
); end progn
)
); end progn
(if (and (= "Segmented" dpipeelb) (not(equal ang1 ang2 0.000001)))
(progn
; (command "_.mline" "_st" "DUCT_PIPE" "_S" (cadar segLst) "_J" "_Z")
; (mapcar 'command mlLst)
; (command "")
(setvar "PLINEWID" 0.0)
(setq SegCnt 0)
(while (< SegCnt (1- SegNum))
(command "_.line" (nth SegCnt ptlst)
(nth (- (length ptlst) 3 SegCnt) ptlst)
""
)
(setq SegCnt (1+ SegCnt))
)
(command "_.pline")
(mapcar 'command ptLst)(command "_c")
(setvar "PLINEWID" dpipepWd)
(if (= dpipepat "All")
(command "_.hatch" (nth 0 dproppat) (nth 1 dproppat) (if (< (sin (* PI 0.125)) (
abs (sin ang1)) (sin (* PI 0.375))) 45 0) "_l" "" "_.change" "_l" "" "_p" "_la"
(nth 2 dproppat) "_c" (nth 3 dproppat) "_lt" (nth 4 dproppat) "_lw" (nth 5 dprop
pat) "")
)
(if (= (logand dpipecln 1) 1)
(progn
(setvar "PLINEWID" 0.0)
(command "_.pline")
(mapcar 'command (if (= (logand dpipecln 3) 3) mlLst (list (car mlLst) (trans (c
aadr segLst) 0 1) (last mlLst))))
(command "")
(setvar "PLINEWID" dpipepWd)
(command "_.change" "_l" "" "_p" "_la" (nth 0 dpropcln) "_c" (nth 1 dpropcln) "_
lt" (nth 2 dpropcln) "_lw" (nth 3 dpropcln) "")
); end progn
); end if
); end progn
); end if
); end if
); end if
(if
(and (= dpipeelb "Radius")
(not(equal ang1 ang2 0.000001))
(vla-object(entlast))
tAng (abs (- ang2 ang1))
); end setq
(if (> tAng pi)
(if(< ang1 ang2)
(setq ang1(+ ang1 pi)
ang2(- ang2 pi)); end setq
(setq ang1(- ang1 pi)
ang2(+ ang2 pi)); end setq
); end if
); end if
(setq Bulge(/(sin(/(rem(- ang2 ang1)pi)4.0))(cos(/(rem(- ang2 ang1)pi)4.0))))
(vla-SetBulge lPln 1 Bulge)
(vla-SetBulge lPln 3 (- Bulge))
(if
(= dpipepat "All")
(progn
(command "_.hatch" (nth 0 dproppat) (nth 1 dproppat) (if (vla-object(entlast)) 0
Bulge))
(setvar "PLINEWID" dpipepWd)
(command "_.change" "_l" "" "_p" "_la" (nth 0 dpropcln) "_c" (nth 1 dpropcln) "_
lt" (nth 2 dpropcln) "_lw" (nth 3 dpropcln) "")
); end progn
); end if
); end progn
); end if
(if (or (=(cadar segLst)(nth 2(car segLst)))(= 2(length segLst)))
(progn
; (if (=(cadar segLst)(nth 2(car segLst)))
; (command "_.mline" "_st" "DUCT_PIPE" "_S" (cadar segLst) "_J" "_Z" plStart1 pl
End "")
(progn
(setq ptLst
(list (polar plStart1 (+ (angle plStart1 plEnd) (/ pi 2.0)) (/(cadar segLst)2))
(polar plStart1 (- (angle plStart1 plEnd) (/ pi 2.0)) (/(cadar segLst)2))
(polar plEnd (- (angle plStart1 plEnd) (/ pi 2.0)) (/(nth 2(car segLst))2))
(polar plEnd (+ (angle plStart1 plEnd) (/ pi 2.0)) (/(nth 2(car segLst))2))
)
)
(setvar "PLINEWID" 0.0)
(command "_.pline")
(mapcar 'command ptLst)(command "_c")
(setvar "PLINEWID" dpipepWd)
(if (/= dpipepat "None")
(command "_.hatch" (nth 0 dproppat) (nth 1 dproppat) (if ( (setq tAng (/ (* 180
(angle plStart1 plEnd)) PI)) 112.5)(= (atof (getvar "ACADVER")) 16.1)
(progn
(setq txEnt (entget (entlast)))
(setq ptLst (textbox txEnt))
(entdel (cdr (assoc -1 txEnt)))
(setq txEnt (list '(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") (ass
oc 7 txEnt) (assoc 8 txEnt) (assoc 40 txEnt) (cons 1 (if (/= nil (cdr (assoc 51
txEnt)) 0)
(strcat "{\\Q" (dectos (deg (cdr (assoc 51 txEnt)))) ";" (cdr (assoc 1 txEnt)) "
}") (cdr (assoc 1 txEnt)))) (cons 10 (polar (polar (cdr (assoc 10 txEnt))
(+ (cdr (assoc 50 txEnt)) (/ PI 2.0)) (+ (cadar ptLst) (/ (- (cadadr ptLst) (cad
ar ptLst)) 2.0))) (cdr (assoc 50 txEnt)) (+ (caar ptLst) (/ (- (caadr ptLst) (ca
ar ptLst)) 2.0))))
(assoc 210 txEnt) (assoc 50 txEnt) '(71 . 5) '(72 . 5) '(90 . 1) '(63 . 1) '(45
. 1.25))
)
(entmake txEnt)
(setq txEnt (subst '(90 . 3) '(90 . 1) (entget (entlast))))
(entmod txEnt)
)
)
(command "_.change" "_l" "" "_p" "_la" (nth 2 dproptxt) "_c" (nth 3 dproptxt) "_
lt" (nth 4 dproptxt) "_lw" (nth 5 dproptxt) "")
); end progn
); end if
); end progn
); end if
(setq segLst(cdr segLst)); end setq
); end while
(command "_.erase" lEnt "")
(asmi-LayersStateRestore stLst)
); end progn
); end if
); end of Body Function
(defun *error*(msg)
(if actDoc
(vla-EndUndoMark actDoc)
); end if
(setvar "CMDECHO" 0)
(command "_.undo" "1")
(if oldVars
(mapcar 'setvar
'("FILLMODE" "PLINEWID" "HPANG" "HPSCALE" "HPNAME" "CMDECHO" "OSMODE" "CLAYER" "
CECOLOR" "CELTYPE" "CELWEIGHT")
oldVars); end mapcar
); end if
(if (not (member msg '("console break" "Function cancelled" "quit / exit abort"
"")))
(princ (strcat "\nError: " msg))
(princ)
)
); end of *error*
(PipeMLineStyle)
(setq oldVars(mapcar 'getvar '("FILLMODE" "PLINEWID" "HPANG" "HPSCALE" "HPNAME"
"CMDECHO" "OSMODE" "CLAYER" "CECOLOR" "CELTYPE" "CELWEIGHT"))
); end setq
(if(entlast)(setq lObj(entlast)))
(vla-StartUndoMark
(setq actDoc
(vla-get-ActiveDocument
(vlax-get-acad-object))))
(if (not (member dpipeelb '("Mitered" "Radius" "Segmented" "Chamfered")))
(progn
(initget "Mitered Radius Segmented Chamfered")
(setq dpipeelb (getkword (strcat "\nSpecify elbow type "
(if (= dlastelb "Chamfered") "/" "Chamfered/")
(if (= dlastelb "Mitered") "/" "Mitered/")
(if (= dlastelb "Segmented") "/" "Segmented/")
(if (not (member dlastelb '("Chamfered" "Mitered" "Segmented")))
(strcat ": ")
"Radius: ")))
)
)
)
(if (not (member dpipeelb '("Chamfered" "Mitered" "Radius" "Segmented"))) (setq
dpipeelb dlastelb))
(if (/= "Radius" dpipeelb "Segmented") (setq dpipetan dpipeert) (setq dpiperad d
pipeert))
(if (not (and (numberp dlastpwd) (< 0 dlastpwd))) (setq dlastpwd (if (= (getvar
"MEASUREMENT") 0) 6.0 100.0)))
(if (/= (type dlastsuf) 'STR) (setq dlastsuf (if (= (getvar "MEASUREMENT") 0) "x
6" "x100")))
(if (/= "Radius" dpipeelb "Segmented")
(if (not (and (numberp dpipetan) (< 0 dpipetan)))
(progn
(initget 6)
(setq dpipetan (getdist (strcat "\nSpecify " (if (= dpipeelb "Mitered") "elbow t
hroat" "diagonal chamfer") " length <"
(rtos (if (not (and (numberp dlasttan) (: "))
)
(if (not (and (numberp dpipetan) (< 0 dpipetan))) (setq dpipetan dlasttan))
)
)
(while (not (or (and (numberp dpiperad) (< 0 dpiperad)) (and (= (type dpiperad)
'STR) (< 0 (distof dpiperad)))))
(initget 6 "Throat R/w(d)")
(setq dpiperad (getdist (strcat "\nSpecify radius [" (if (and (= (type dpiperad)
'STR) (< 0 (distof dpiperad)))
"/R/w(d)] <" "Throat/] <") (cond ((and (numberp dlastrad) (< 0 dlastrad)) (rtos
dlastrad))
((and (= (type dlastrad) 'STR) (: "))
)
(cond
((= dpiperad "Throat") (setq dpiperad nil dlastrad (if (numberp dlastrad) dlastr
ad (* (- (distof dlastrad) 0.5) dlastpwd))))
((= dpiperad "R/w(d)") (setq dpiperad nil dlastrad (if (numberp dlastrad) (rtos
(* (/ dlastrad dlastpwd) 1.5) 2) dlastrad)))
((numberp dpiperad) (setq dpiperad (if (numberp dlastrad) dpiperad (rtos dpipera
d 2))))
(T (setq dpiperad dlastrad))
)
)
)
(if (not (and (numberp dpipetrn) (<= 0 dpipetrn (/ PI 2.0))))
(setq dpipetrn (getangle (strcat "\nSpecify transition angle <"
(angtos (if (and (numberp dlasttrn) (: "))
)
)
(if (not (and (numberp dpipetrn) (<= 0 dpipetrn (/ PI 2.0)))) (setq dpipetrn dla
sttrn))
(if (not (member dpipepat '("All" "Straight" "None")))
(progn
(initget "All Straight None")
(setq dpipepat (getkword (strcat "\nSpecify segments to hatch "
(if (= dlastpat "All") "/" "All/")
(if (= dlastpat "Straight") "/" "Straight/")
(if (/= "All" dlastpat "Straight")
(strcat ": ")
"None: ")))
)
)
)
(if (not (member dpipepat '("All" "Straight" "None"))) (setq dpipepat dlastpat))
(if (not (member dpipecln '(0 1 2 3)))
(progn
(initget "Yes No")
(setq dpipecln (getkword (strcat "\nWould you like to have centerline shown? " (
progn (setq dlastcln (if (= dlastcln 2) 2 0))"N>"))))
)
(cond
((= dpipecln "Yes")(setq dpipecln (logior dlastcln 1)))
((= dpipecln "No") (setq dpipecln (logand dlastcln -2)))
(T (setq dpipecln dlastcln))
)
(if (and (= (logand dpipecln 1) 1) (/= "Chamfered" dpipeelb "Mitered"))
(progn
(initget "Yes No")
(setq dpipecln (getkword (strcat "\nWould you like elbow centerlines filleted? "
"N>")))
)
(cond
((= dpipecln "Yes")(setq dpipecln 3))
((= dpipecln "No") (setq dpipecln 1))
(T (setq dpipecln (logior dlastcln 1)))
)
)
)
)
)
(if (not (member dpipecln '(0 1 2 3))) (setq dpipecln dlastcln))
(if (/= (type dpipesuf) 'STR)
(progn
(initget "Yes No")
(setq dpipesuf (getkword (strcat "\nWould you like to have size label shown? " (
progn (if (/= (type dlastsuf) 'STR) (setq dlastsuf " "))"N>"))))
)
(cond
((= dpipesuf "Yes")(setq dpipesuf (if (/= " " dlastsuf) dlastsuf "")))
((= dpipesuf "No") (setq dpipesuf " "))
(T (setq dpipesuf dlastsuf))
)
)
)
(if (/= (type dpipesuf) 'STR) (setq dpipesuf dlastsuf) (setq dlastsuf dpipesuf))
(if (not (and (numberp dpipepwd) (< 0 dpipepwd))) (setq dpipepwd dlastpwd) (setq
dlastpwd dpipepwd))
(if (or (/= (type dpropobj) 'LIST) (not (equal (mapcar 'type dpropobj) '(STR STR
STR STR))))
(setq dpropobj '("" "" "" ""));objectline properties format '("layer" "color" "l
type" "lweight")
)
(setvar "CMDECHO" 0)
(if (and (read (caddr dpropobj)) (not (member (strcase (caddr dpropobj)) '("BYBL
OCK" "BYLAYER" "CONTINUOUS"))) (not (tblsearch "LTYPE" (caddr dpropobj))))
(command "_.linetype" "_l" (caddr dpropobj) (findfile (nth (getvar "MEASUREMENT"
) '("acad.lin" "acadiso.lin"))) "")
)
(command "_.clayer" (nth 0 dpropobj) "_.cecolor" (nth 1 dpropobj) "_.celtype" (n
th 2 dpropobj) "_.celweight" (nth 3 dpropobj))
(while (not (and (numberp dpipepWd) (< 0 dpipepWd) (= 'LIST (type dpipefpt)) (<=
2 (length dpipefpt) 3) (apply 'and (mapcar 'numberp dpipefpt))))
(if (/= " " dpipesuf)
(progn
(initget 128 "Suffix Width")
(setq dlastfpt (getpoint (strcat "\nSpecify start point or [Width/Suffix] : " ))
); end setq
)
(setq dlastfpt (getpoint (strcat "\nSpecify start point or width : " ))
); end setq
)
(cond
((and (= 'LIST (type dlastfpt)) (<= 2 (length dlastfpt) 3) (apply 'and (mapcar '
numberp dlastfpt)))
(setq dpipefpt dlastfpt)
); end condition #1
((and (= 'REAL (type (distof dlastfpt))) (< 0 (distof dlastfpt)))
(setq dpipepWd (distof dlastfpt) dlastpWd dpipepWd); end setq
); end condition #2
((= dlastfpt "Width")
(initget 128)
(setq dpipepWd (getdist (strcat "\nSpecify starting width : ")) dlastpWd dpipepW
d); end setq
); end condition #3
((= dlastfpt "Suffix")
(initget 128)
(setq dpipesuf (getstring (strcat "\nEnter text for suffix : " ))
dlastsuf dpipesuf); end setq
); end condition #4
(T
(princ "\nInvalid option keyword! ")
); end condition #5
); end cond
); end while
(mapcar 'setvar '("FILLMODE" "PLINEWID" "CMDECHO") (list 0 dpipepWd 0))
(setq ERRENT (entlast))
(command "_.pline" dpipefpt)
(setq DLP (list dpipefpt))
(while (= (getvar "CMDNAMES") "PLINE")
(setvar "CMDECHO" 0)
(initget (strcat "Width " (if (/= " " dpipesuf) "Suffix " "") "Undo"))
(setq PNT (getpoint (last DLP) (strcat "\nSpecify next point" (if (>= (length DL
P) 2) (strcat " or [Undo/Width" (if (/= " " dpipesuf) "/Suffix" "") "]") "") ":
")))
(cond
((/= (getvar "CMDNAMES") "PLINE"))
((= PNT "Width")
(setq PWD (getvar "PLINEWID"))
(princ (strcat "\nSpecify ending width : "))
(command "_Width" "" PAUSE)
(cond
((or (= PWD (getvar "PLINEWID")) ( (distof (angtos dpipetrn 0 16)) 90)))
((= (distof (angtos dpipetrn 0 16)) 90)
(setq PWD (getvar "PLINEWID"))
(command (getvar "LASTPOINT") "_u" (getvar "LASTPOINT") "_w" PWD PWD)
)
(T
(command (last (setq DLP (append DLP (list (polar (getvar "LASTPOINT") (angle (c
adr (reverse DLP)) (last DLP))
(/ (abs (- PWD (getvar "PLINEWID"))) 2.0 (/ (sin dpipetrn) (cos dpipetrn))))))))
)
)
)
)
((= PNT "Suffix")
(initget 128)
(setq dpipesuf (getstring (strcat "\nEnter text for suffix : " ))
)
(if (/= dpipesuf dlastsuf)
(progn
(mapcar 'set '(dpipesuf dlastsuf) (list dlastsuf dpipesuf))
(setq dlastpwd (getvar "PLINEWID")
dlastfpt (last DLP)
DLP (list dlastfpt)
)
(while (= (getvar "CMDNAMES") "PLINE") (command ""))
(BodyFunction)
(setq dpipesuf dlastsuf)
(setvar "PLINEWID" dlastpwd)
(command "_.pline" dlastfpt)
)
)
)
((= PNT "Undo")
(command "_Undo")
(setq DLP (reverse (cdr (reverse DLP))))
)
((and (= 'LIST (type PNT)) (= (length DLP) 2) " or [Undo/Width/Suffix]" "") ": "
))
; (command PAUSE)
; (initget "Width Suffix Undo")
; (getpoint (last DLP) (strcat "\nSpecify next point" (if (>= (length DLP) 2) "
or [Undo/Width/Suffix]" "") ": "))
; (cond
; ((/= (getvar "CMDNAMES") "PLINE"))
; ((and (equal (getvar "LASTPOINT") (last DLP)) (wcmatch (strcase (getvar "LASTP
ROMPT")) "*: W,*: W[I ],*: WI[D ],*: WID[T ],*: WIDTH,*: WIDTH "))
; (setq PWD (getvar "PLINEWID"))
; (princ (strcat "\nSpecify ending width : "))
; (command "" PAUSE)
; (cond
; ((or (= PWD (getvar "PLINEWID")) ( (distof (angtos dpipetrn 0 16)) 90)))
; ((= (distof (angtos dpipetrn 0 16)) 90)
; (setq PWD (getvar "PLINEWID"))
; (command (getvar "LASTPOINT") "_u" (getvar "LASTPOINT") "_w" PWD PWD)
; )
; (T
; (command (last (setq DLP (append DLP (list (polar (getvar "LASTPOINT") (angle
(cadr (reverse DLP)) (last DLP))
; (/ (abs (- PWD (getvar "PLINEWID"))) 2.0 (/ (sin dpipetrn) (cos dpipetrn))))))
))
; )
; )
; )
; )
; ((and (equal (getvar "LASTPOINT") (last DLP)) (wcmatch (strcase (getvar "LASTP
ROMPT")) "*: S,*: S[U ],*: SU[F ],*: SUF[F ],*: SUFF[I ],*: SUFFI[X ],*: SUFFIX
"))
; (initget 128)
; (setq dpipesuf (getstring (strcat "\nEnter text for suffix : " ))
; dlastsuf dpipesuf
; )
; )
; ((and (equal (getvar "LASTPOINT") (last DLP)) (wcmatch (strcase (getvar "LASTP
ROMPT")) "*: U,*: UN,*: UND,*: UNDO"))
; (setq DLP (reverse (cdr (reverse DLP))))
; )
; ((setq DLP (append DLP (list (getvar "LASTPOINT")))))
; )
; )
(setq dlastpwd (getvar "PLINEWID"))
(BodyFunction)
(vla-EndUndoMark actDoc)
(mapcar 'setvar
'("FILLMODE" "PLINEWID" "HPANG" "HPSCALE" "HPNAME" "CMDECHO" "OSMODE")
oldVars); end apply
(command "_.regen")
(setq dlastelb dpipeelb dlasttan dpipetan dlastrad dpiperad dlasttrn dpipetrn dl
astpat dpipepat dlastcln dpipecln dlastsuf dpipesuf)
(princ)
); end of wpipe
(defun c:sd()
(wpipe nil nil nil nil nil nil nil nil)
)
(c:sd)
;;; ------------------------------------------------------------------------
;;; CreateWye.lsp v1.1
;;;
;;; Copyright January, 2007
;;; Timothy G. Spangler
;;;
;;; Permission to use, copy, modify, and distribute this software
;;; for any purpose and without fee is hereby granted, provided
;;; that the above copyright notice appears in all copies and
;;; that both that copyright notice and the limited warranty and
;;; restricted rights notice below appear in all supporting
;;; documentation.
;;;
;;; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;; WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;; PURPOSE AND OF MERCHANTIBILITY ARE HEREBY DISCLAIMED BY THE
;;; PROGRAMMER.
;;;
;;; -----------------------------------------------------------------------
;;; ------------ COMMAND LINE FUNCTIONS
(defun c:WYE (/)(WYE_START))
;;; ------------ MAIN FUNCTION
(defun WYE_START (/ *error* ActiveDoc Space OldClayer OldCmdEcho OldOsmode LineS
tart LineEnd
LineAngle TrunkSize WyeStart SidePoint TrunkDirection BlockName)
;;; Begin Error Handler -------------------------------------------------
(defun *error* (MSG)
(if (not (member MSG '("Function cancelled" "quit / exit abort")))
(princ (strcat "\n*** Program Error: " (strcase MSG) " ***"))
(princ "\n... Program Cancelled ...")
)
(while (< 0 (getvar "cmdactive"))
(command)
)
(WYE_RESET_ENV)
(princ)
)
;;; End Error Handler ---------------------------------------------------
(WYE_SET_ENV)
)
;;; ------------ SET ENVIROMENT BEFORE LAUNCH
(defun WYE_SET_ENV(/)
(setq OldClayer (getvar "CLAYER"))
(setq OldCmdEcho (getvar "CMDECHO"))
(setq OldOsmode (getvar "OSMODE"))
(setq OldCeColor (getvar "CECOLOR"))
(setvar "CMDECHO" 0)
(command "_undo" "begin")
(vl-load-com)
(setq ActiveDoc (vla-get-activedocument (vlax-get-acad-object)))
(setq Space
(if (= (getvar "cvport") 1)
(vla-get-paperspace ActiveDoc)
(vla-get-modelspace ActiveDoc)
)
)
;; Setup layer for centerline
(WYE_CREATE_LAYER "M-HVAC-CNTR" "Mechanical Plan - Ductwork centerline" "CENTER2
" "25" "12" "0")
;; Setup layer for insulation
(WYE_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork insulation" "HIDDEN2
" "15" "201" "1")
;; Run wye
(WYE_RUN)
)
;;; ------------ RUN WYE SUB ROUTINE - GET VARIABLES
(defun WYE_RUN (/ TrunkLine EntList WyeLayer)
;; Get properties from current trunk line
(while (null (setq TrunkLine (car(nentsel "\n Select trunk to add wye to: "))))
(princ "\n Duct not selected")
)
(setq EntList (entget TrunkLine))
(setq WyeLayer (cdr (assoc 8 EntList)))
;; Set layer
(setvar "CLAYER" WyeLayer)
;; Set wye properties
(if (equal (cdr (assoc 0 EntList)) "LINE")
(progn
(setq LineStart (cdr (assoc 10 EntList)))
(setq LineEnd (cdr (assoc 11 EntList)))
(setq LineAngle (angle LineStart LineEnd))
(setq TrunkSize (distance LineStart LineEnd))
(setq WyeStart (polar LineStart LineAngle (/ (distance LineStart LineEnd) 2)))
)
(progn
(princ " Trunk must be a line. ")
(WYE_RUN)
)
)
;; Get wye direction
(setq SidePoint (getpoint WyeStart "\n Define wye direction "))
(setq TrunkDirection (WYE_GET_PERP LineStart LineEnd SidePoint))
;; Get wye outlet size
(setq WyeOutlet (- TrunkSize 4.0))
(initget 6)
(if (not(setq WyeOutlet (getreal (strcat "\n Enter wye outlet size: " ""))))
(setq WyeOutlet (- TrunkSize 4.0))
)
;; Get wye insulation
(initget 1 "None Inside Outside Both")
(setq WyeInsul (getkword "\n Insulation options: (None/Inside/Oustside/Both)"))
;; Create wye
(WYE_CREATE WyeInsul)
)
;;; ------------ CREATE WYE SUB ROUTINE
(defun WYE_CREATE (WyeInsul / WyePt01 WyePt02 WyePt03 WyePt04 WyePt05 WyePt06 Wy
ePt07 WyePt08 WyePt09
WyePt10 WyePt11 WyePt12 WyeLine01 WyeLine02 WyeLine03 WyeLine04 WyeLine05 WyeLin
e06 WyeLine07 WyeLine08
WyeLine09 WyeLine10 WyeLine11 DivAngle DivStart InsLine01 InsLine02 InsLine03 In
sLine04 InsLine05
InsLine06 InsLine07 InsLine08 InsLine09 InsLine10 InsLine11 Inter01 Inter02 Inte
r03 Inter04 Inter05
Inter06 CntrLineRad CntrPt01 CntrPt02 CntrPt03 CntrPt04 CntrPt05 CntrPt06 WyeCnt
rLine01 WyeCntrLine02
WyeCntrLine03 WyeCntrLine04 WyeCntrLine05 WyeCntrLine06 WyeCntrLine07 WyeCntrLin
e08 VaneLine01 VaneLine02)
;; Create outside points
(setq WyePt01 (polar WyeStart (WYE_ADD_ANGLE TrunkDirection 90.0)(/ TrunkSize 2.
0)))
(setq WyePt02 (polar WyeStart (WYE_SUBTRACT_ANGLE TrunkDirection 90.0)(/ TrunkSi
ze 2.0)))
(setq WyePt03 (polar WyePt01 TrunkDirection 3.0))
(setq WyePt04 (polar WyePt02 TrunkDirection 3.0))
(setq WyePt05 (polar WyePt03 (WYE_ADD_ANGLE TrunkDirection 45.0) 3.0))
(setq WyePt06 (polar WyePt04 (WYE_SUBTRACT_ANGLE TrunkDirection 45.0) 3.0))
(setq WyePt07 (polar WyePt05 (WYE_SUBTRACT_ANGLE TrunkDirection 45.0) WyeOutlet)
)
(setq WyePt08 (polar WyePt06 (WYE_ADD_ANGLE TrunkDirection 45.0) WyeOutlet))
(setq WyePt09 (polar WyePt07 (WYE_SUBTRACT_ANGLE TrunkDirection 135.0) 3.0))
(setq WyePt10 (polar WyePt08 (WYE_ADD_ANGLE TrunkDirection 135.0) 3.0))
(setq WyePt11
(inters
(list (car WyePt07)(cadr WyePt07))
(list (car WyePt09)(cadr WyePt09))
(list (car WyePt08)(cadr WyePt08))
(list (car WyePt10)(cadr WyePt10))
nil)
)
(setq WyePt11 (list (car WyePt11)(cadr WyePt11) 0.0))
(setq WyePt12 (polar WyeStart TrunkDirection 3.0))
;; Create wye
(setq WyeLine01 (vlax-invoke space 'addline WyePt01 WyePt02))
(setq WyeLine02 (vlax-invoke space 'addline WyePt01 WyePt03))
(setq WyeLine03 (vlax-invoke space 'addline WyePt02 WyePt04))
(setq WyeLine04 (vlax-invoke space 'addline WyePt03 WyePt05))
(setq WyeLine05 (vlax-invoke space 'addline WyePt04 WyePt06))
(setq WyeLine06 (vlax-invoke space 'addline WyePt05 WyePt07))
(setq WyeLine07 (vlax-invoke space 'addline WyePt06 WyePt08))
(setq WyeLine08 (vlax-invoke space 'addline WyePt07 WyePt11))
(setq WyeLine09 (vlax-invoke space 'addline WyePt08 WyePt11))
(setq WyeLine10 (vlax-invoke space 'addline WyePt11 WyePt12))
;;Create divider
(setq DivAngle (+ TrunkDirection (/ pi 4)))
(setq DivStart (polar WyePt12 DivAngle 0.5))
(command "_.arc" DivStart "C" WyePt12 "A" 270)
;; Create inside insulation
(if (or (= WyeInsul "Inside")(= WyeInsul "Both"))
(progn
;; Create insulation
(setq InsLine01 (car (vlax-invoke WyeLine02 'offset -1.0)))
(setq InsLine02 (car (vlax-invoke WyeLine03 'offset 1.0)))
(setq InsLine03 (car (vlax-invoke WyeLine04 'offset -1.0)))
(setq InsLine04 (car (vlax-invoke WyeLine05 'offset 1.0)))
(setq InsLine05 (car (vlax-invoke WyeLine08 'offset -1.0)))
(setq InsLine06 (car (vlax-invoke WyeLine09 'offset 1.0)))
(setq Inter01 (vlax-invoke InsLine01 'intersectwith InsLine03 acExtendBoth))
(setq Inter02 (vlax-invoke InsLine02 'intersectwith InsLine04 acExtendBoth))
(setq Inter03 (vlax-invoke InsLine05 'intersectwith InsLine06 acExtendBoth))
(vlax-put InsLine01 'endpoint Inter01)
(vlax-put InsLine03 'startpoint Inter01)
(vlax-put InsLine02 'endpoint Inter02)
(vlax-put InsLine04 'startpoint Inter02)
(vlax-put InsLine05 'endpoint Inter03)
(vlax-put InsLine06 'endpoint Inter03)
;; Set insulation properties
(vlax-put InsLine01 'Layer "M-HVAC-INSL")
(vlax-put InsLine02 'Layer "M-HVAC-INSL")
(vlax-put InsLine03 'Layer "M-HVAC-INSL")
(vlax-put InsLine04 'Layer "M-HVAC-INSL")
(vlax-put InsLine05 'Layer "M-HVAC-INSL")
(vlax-put InsLine06 'Layer "M-HVAC-INSL")
)
)
;; Create outside insulation
(if (or (= WyeInsul "Outside")(= WyeInsul "Both"))
(progn
;; Create isnulation
(setq InsLine07 (car (vlax-invoke WyeLine02 'offset 1.0)))
(setq InsLine08 (car (vlax-invoke WyeLine03 'offset -1.0)))
(setq InsLine09 (car (vlax-invoke WyeLine04 'offset 1.0)))
(setq InsLine10 (car (vlax-invoke WyeLine05 'offset -1.0)))
(setq InsLine11 (car (vlax-invoke WyeLine08 'offset 1.0)))
(setq InsLine12 (car (vlax-invoke WyeLine09 'offset -1.0)))
(setq Inter04 (vlax-invoke InsLine07 'intersectwith InsLine09 acExtendBoth))
(setq Inter05 (vlax-invoke InsLine08 'intersectwith InsLine10 acExtendBoth))
(setq Inter06 (vlax-invoke InsLine11 'intersectwith InsLine12 acExtendBoth))
(vlax-put InsLine07 'endpoint Inter04)
(vlax-put InsLine09 'startpoint Inter04)
(vlax-put InsLine08 'endpoint Inter05)
(vlax-put InsLine10 'startpoint Inter05)
(vlax-put InsLine11 'endpoint Inter06)
(vlax-put InsLine12 'endpoint Inter06)
;; Set insulation properties
(vlax-put InsLine07 'Layer "M-HVAC-INSL")
(vlax-put InsLine08 'Layer "M-HVAC-INSL")
(vlax-put InsLine09 'Layer "M-HVAC-INSL")
(vlax-put InsLine10 'Layer "M-HVAC-INSL")
(vlax-put InsLine11 'Layer "M-HVAC-INSL")
(vlax-put InsLine12 'Layer "M-HVAC-INSL")
)
)
;; Set centerline layer
(setvar "CLAYER" "M-HVAC-CNTR")
;; Set centerline radius
(setq CntrLineRad (/ TrunkSize 8.0))
;; Create centerline points - right side
(setq CntrPt01 (polar WyePt05 (angle WyePt05 WyePt07) (/ (distance WyePt05 WyePt
07) 2.0)))
(setq CntrPt02 (polar CntrPt01 (WYE_ADD_ANGLE (angle WyePt03 WyePt05) 180.0) 2.0
))
(setq CntrPt02
(inters
(list (car CntrPt01)(cadr CntrPt01))
(list (car CntrPt02)(cadr CntrPt02))
(list (car WyePt03)(cadr WyePt03))
(list (car WyePt11)(cadr WyePt11))
nil)
)
(setq CntrPt02 (list(car CntrPt02)(cadr CntrPt02) 0.0))
(setq CntrPt03 (polar CntrPt02 (WYE_ADD_ANGLE TrunkDirection 180.0) (* 2 CntrLin
eRad)))
(setq CntrPt03
(inters
(list (car CntrPt02)(cadr CntrPt02))
(list (car CntrPt03)(cadr CntrPt03))
(list (car WyePt01)(cadr WyePt01))
(list (car WyePt02)(cadr WyePt02))
nil)
)
(setq CntrPt03 (polar CntrPt03 TrunkDirection (* 2 CntrLineRad)))
(setq CntrPt03 (list(car CntrPt03)(cadr CntrPt03) 0.0))
;; Create centerline points - left side
(setq CntrPt04 (polar WyePt06 (angle WyePt06 WyePt08) (/ (distance WyePt06 WyePt
08) 2.0)))
(setq CntrPt05 (polar CntrPt04 (WYE_ADD_ANGLE (angle WyePt04 WyePt06) 180.0) 2.0
))
(setq CntrPt05
(inters
(list (car CntrPt04)(cadr CntrPt04))
(list (car CntrPt05)(cadr CntrPt05))
(list (car WyePt04)(cadr WyePt04))
(list (car WyePt11)(cadr WyePt11))
nil)
)
(setq CntrPt05 (list(car CntrPt05)(cadr CntrPt05) 0.0))
(setq CntrPt06 (polar CntrPt05 (WYE_ADD_ANGLE TrunkDirection 180.0) (* 2 CntrLin
eRad)))
(setq CntrPt06
(inters
(list (car CntrPt05)(cadr CntrPt05))
(list (car CntrPt06)(cadr CntrPt06))
(list (car WyePt01)(cadr WyePt01))
(list (car WyePt02)(cadr WyePt02))
nil)
)
(setq CntrPt06 (polar CntrPt06 TrunkDirection (* 2 CntrLineRad)))
(setq CntrPt06 (list(car CntrPt06)(cadr CntrPt06) 0.0))
;; Create centerline - right side
(setq WyeCntrLine01 (vlax-invoke space 'addline CntrPt01 CntrPt02))
(setq WyeCntrLine02 (vlax-invoke space 'addline CntrPt02 CntrPt03))
(setq WyeCntrLine03
(vlax-invoke Space 'addArc
(polar CntrPt03 (WYE_SUBTRACT_ANGLE TrunkDirection 90.0) CntrLineRad)
CntrLineRad
(WYE_ADD_ANGLE TrunkDirection 90.0)
(WYE_ADD_ANGLE TrunkDirection 180.0)
)
)
(setq WyeCntrLine04
(vlax-invoke Space 'addArc
(polar WyeStart (WYE_ADD_ANGLE TrunkDirection 90.0) CntrLineRad)
CntrLineRad
(WYE_ADD_ANGLE TrunkDirection 270.0)
(WYE_ADD_ANGLE TrunkDirection 360.0)
)
)
;; Create centerline - left side
(setq WyeCntrLine05 (vlax-invoke space 'addline CntrPt04 CntrPt05))
(setq WyeCntrLine06 (vlax-invoke space 'addline CntrPt05 CntrPt06))
(setq WyeCntrLine07
(vlax-invoke Space 'addArc
(polar CntrPt06 (WYE_ADD_ANGLE TrunkDirection 90.0) CntrLineRad)
CntrLineRad
(WYE_SUBTRACT_ANGLE TrunkDirection 180.0)
(WYE_SUBTRACT_ANGLE TrunkDirection 90.0)
)
)
(setq WyeCntrLine08
(vlax-invoke Space 'addArc
(polar WyeStart (WYE_SUBTRACT_ANGLE TrunkDirection 90.0) CntrLineRad)
CntrLineRad
TrunkDirection
(WYE_ADD_ANGLE TrunkDirection 90.0)
)
)
;; Set vane properties
(setvar "CLAYER" WyeLayer)
(setvar "CECOLOR" "9")
;; Create vane block
(WYE_CREATE_VANE)
;; Create vanes
(setq VaneLine01 (vlax-invoke space 'addline WyePt11 WyePt03))
(setq VaneLine02 (vlax-invoke space 'addline WyePt11 WyePt04))
;; Add "vane" to wye
(command "_divide" (vlax-vla-object->ename VaneLine01) "block" BlockName "y" 3)
(command "_divide" (vlax-vla-object->ename VaneLine02) "block" BlockName "y" 3)
;; Reset environment
(WYE_RESET_ENV)
)
;;; ------------ CREATE VANE BLOCK SUB - DOES NOT INSERT BLOCK
(defun WYE_CREATE_VANE (/ OldLunits OldLuPrec)
(setq OldLunits (getvar "LUNITS"))
(setq OldLuPrec (getvar "LUPREC"))
(setvar "LUNITS" 2)
(setvar "LUPREC" 1)
(setq BlockName "VANE")
(if (= (tblsearch "block" BlockName) nil)
(progn
(entmake
(list
(cons 0 "BLOCK")
(cons 2 BlockName)
(cons 70 64)
(cons 10 (list 0.0 0.0 0.0))
(cons 8 "0")
)
)
(entmake
(list
(cons 0 "ARC")
(cons 10 (list 2.0 0.0 0.0))
(cons 40 2.0)
(cons 50 2.74889)
(cons 51 3.53429)
(cons 8 "0")
(cons 62 9)
)
)
(entmake
'((0 . "ENDBLK"))
)
)
)
(setvar "LUNITS" OldLunits)
(setvar "LUPREC" OldLuPrec)
BlockName
)
;;; ------------ LAYER CREATION ROUINE
(defun WYE_CREATE_LAYER (Layer Descpition Linetype Thickness Color Plot / Linety
pe TmpList VLA-Obj)
;; Check to see if linetype exsists
(if (= (tblsearch "ltype" Linetype) nil)
(if (WYE_CHECK_LINETYPE (findfile "acad.lin") Linetype)
(command "linetype" "load" Linetype "acad.lin" "")
(setq Linetype "Continuous")
)
)
;;; ------------ CREATE A LIST FOR ENTMAKE
(setq TmpList
(list
(cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 70 0)
)
)
;; Create layer name list
(setq TmpList (append TmpList (list (cons 2 Layer))))
;; Create layer color list
(setq TmpList (append TmpList (list (cons 62 (atoi Color)))))
;; Create layer linetype list
(setq TmpList (append TmpList (list (cons 6 Linetype))))
;; Create layer lineweight list
(setq TmpList (append TmpList (list (cons 370 (atoi Thickness)))))
;; Create layer plot list
(setq TmpList (append TmpList (list (cons 290 (atoi Plot)))))
;; Create layer from first item in the list
(entmake TmpList)
;; Create layer description
(if(or(= 16.1 (atof(getvar "acadver")))(< 16.1 (atof(getvar "acadver"))))
(progn
(setq VLA-Obj(vla-Add (vla-Get-Layers ActiveDoc)Layer))
(vla-Put-Description VLA-Obj Descpition)
(vlax-release-object VLA-Obj)
)
)
)
;;; ------------ CHECKS TO SEE IF A LINETYPE IS AVAILIBLE
(defun WYE_CHECK_LINETYPE (LINFile Linetype / OpenFile LineNumber CurrentLine Re
sult)
(setq OpenFile (open LINFile "r"))
(while (setq CurrentLine (read-line OpenFile))
(if (wcmatch CurrentLine "`**")
(progn
(setq LinetypeName (substr(car(WYE_STRING_TO_LIST CurrentLine ","))2))
(if (= (strcase Linetype) LinetypeName)
(setq Result T)
)
)
)
)
(close OpenFile)
Result
)
;;; ------------ STRING TO LIST SUB ROUTINE
(defun WYE_STRING_TO_LIST (Stg Del / CurChr PosCnt TmpLst TmpStr)
(setq PosCnt 1
TmpStr ""
)
(repeat (1+ (strlen Stg))
(setq CurChr (substr Stg PosCnt 1))
(if (= CurChr Del)
(progn
(setq TmpLst (cons TmpStr TmpLst))
(setq TmpStr "")
)
(setq TmpStr (strcat TmpStr CurChr))
)
(setq PosCnt (1+ PosCnt))
)
(setq TmpLst (reverse TmpLst))
)
;;; ------------ ADD / SUBTRACT ANGLE SUB ROUTINES
(defun WYE_ADD_ANGLE (Radians AddAngle / )
(WYE_DTR(+ (WYE_RTD Radians) AddAngle))
)
(defun WYE_SUBTRACT_ANGLE (Radians AddAngle / )
(WYE_DTR(- (WYE_RTD Radians) AddAngle))
)
;;; ------------ GET PERPENDICULAR POINT
(defun WYE_GET_PERP (StartPoint EndPoint Point / EntList LineStart LineEnd LineA
ngle PerpAngle)
(setq PerpStart (trans StartPoint 0 1))
(setq PerpEnd (trans EndPoint 0 1))
(setq PerpAngle (angle PerpStart PerpEnd))
(if (minusp (sin (- (angle PerpStart Point) PerpAngle))) ;determine direction
(setq NewAngle (- PerpAngle (/ pi 2))) ;if "below" -90 deg
(setq NewAngle (+ PerpAngle (/ pi 2))) ;or "above" +90 deg
)
NewAngle
)
;;; ------------ ROUND NUMBER
(defun WYE_RND (Number Precision)
(setq Number(distof (rtos Number 4 Precision)4))
)
;; ------------ DEGREES / RADIANS SUB ROUTINES
(defun WYE_DTR (NumberOfDegrees)
(* pi (/ NumberOfDegrees 180.0))
)
(defun WYE_RTD (NumberOfRadians)
(* 180.0 (/ NumberOfRadians pi))
)
;;; ------------ RESET SYSEM VARIABLES
(defun WYE_RESET_ENV (/)
(setvar "CMDECHO" OldCmdEcho)
(setvar "CLAYER" OldClayer)
(setvar "OSMODE" OldOsmode)
(setvar "CECOLOR" OldCeColor)
(command "_undo" "end")
(princ)
)
;;;
;;; Echos to the command line
(princ "\n CreateWye v1.1 Timothy Spangler, \n January, 2007....loaded.")
(terpri)
(princ "C:WYE")
(print)
;;; End echo

;;; ------------------------------------------------------------------------
;;; CreateTransition.lsp v1.1
;;;
;;; Copyright January, 2007
;;; Timothy G. Spangler
;;;
;;; Permission to use, copy, modify, and distribute this software
;;; for any purpose and without fee is hereby granted, provided
;;; that the above copyright notice appears in all copies and
;;; that both that copyright notice and the limited warranty and
;;; restricted rights notice below appear in all supporting
;;; documentation.
;;;
;;; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;; WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;; PURPOSE AND OF MERCHANTIBILITY ARE HEREBY DISCLAIMED BY THE
;;; PROGRAMMER.
;;;
;;; -----------------------------------------------------------------------
;;; ------------ COMMAND LINE FUNCTIONS
(defun c:TRANS (/) (TRANS_START))
;;; ------------ MAIN FUNCTION
(defun TRANS_START ( / *error* ActiveDoc Space OldClayer OldCmdEcho TrunkLine En
tList
LineStart LineEnd LineAngle TrunkSize TransStart TrunkDirection TransOutSize Tra
nsLength
TransStyle TransInsul )
;;; Begin Error Handler -------------------------------------------------
(defun *error* (MSG)
(if (not (member MSG '("Function cancelled" "quit / exit abort")))
(princ (strcat "\n*** Program Error: " (strcase MSG) " ***"))
(princ "\n... Program Cancelled ...")
)
(while (Rnd/Rnd->Sq)"))
;; Get insulation
(initget 1 "None Inside Outside Both")
(setq TransInsul (getkword "\n Insulation options: (None/Inside/Oustside/Both)")
)
;; Create transition type
(cond
((= (strcase TransStyle) "SQUARE")
(TRANS_SQ->TRANS_RND TrunkSize TransOutSize TransStart TransLayer TransInsul)
)
((= (strcase TransStyle) "ROUND")
(TRANS_RND->SQ TrunkSize TransOutSize TransStart TransLayer TransInsul)
)
)
)
;;; ------------ SQUARE TO ROUND TRANSITION
(defun TRANS_SQ->TRANS_RND (TrunkSize TransOutSize TransStart TransLayer TransIn
sul / TransCntr TransBreaks
TransInsPoint01 TransInsPoint02 TransInsPoint03 TransInsPoint04 TransInsPoint05
TransInsPoint06
TransInsPoint01 TransInsPoint02 TransInsPoint03 TransInsPoint04 TransInsPoint05
TransInsPoint06
TransInsPoint07 TransInsPoint08)
;; Get transition outer points
(setq TransCntr (polar TransStart TrunkDirection TransLength))
(setq TransPoint01 (polar TransStart (TRANS_ADD_ANGLE TrunkDirection 90.0) (* 0.
5 TrunkSize)))
(setq TransPoint02 (polar TransStart (TRANS_SUBTRACT_ANGLE TrunkDirection 90.0)
(* 0.5 TrunkSize)))
(setq TransPoint03 (polar TransCntr (TRANS_ADD_ANGLE TrunkDirection 90.0) (* 0.5
TransOutSize)))
(setq TransPoint04 (polar TransCntr (TRANS_SUBTRACT_ANGLE TrunkDirection 90.0) (
* 0.5 TransOutSize)))
;; Get transition inner point (curves for round outlet)
(setq TransBreaks (* 0.25 TransOutSize))
(setq TransPoint05 (polar TransCntr (TRANS_ADD_ANGLE TrunkDirection 90.0) TransB
reaks))
(setq TransPoint06 (polar TransCntr (TRANS_SUBTRACT_ANGLE TrunkDirection 90.0) T
ransBreaks))
;; Get Insulation Points - INSIDE
(setq TransInsPoint01 (polar TransStart (TRANS_ADD_ANGLE TrunkDirection 90.0) (-
1.0 (* 0.5 TrunkSize))))
(setq TransInsPoint02 (polar TransStart (TRANS_SUBTRACT_ANGLE TrunkDirection 90.
0) (- 1.0 (* 0.5 TrunkSize))))
(setq TransInsPoint03 (polar TransCntr (TRANS_ADD_ANGLE TrunkDirection 90.0) (-
1.0 (* 0.5 TransOutSize))))
(setq TransInsPoint04 (polar TransCntr (TRANS_SUBTRACT_ANGLE TrunkDirection 90.0
) (- 1.0 (* 0.5 TransOutSize))))
;; Get Insulation Points - OUTSIDE
(setq TransInsPoint05 (polar TransStart (TRANS_ADD_ANGLE TrunkDirection 90.0) (+
1.0 (* 0.5 TrunkSize))))
(setq TransInsPoint06 (polar TransStart (TRANS_SUBTRACT_ANGLE TrunkDirection 90.
0) (+ 1.0 (* 0.5 TrunkSize))))
(setq TransInsPoint07 (polar TransCntr (TRANS_ADD_ANGLE TrunkDirection 90.0) (+
1.0 (* 0.5 TransOutSize))))
(setq TransInsPoint08 (polar TransCntr (TRANS_SUBTRACT_ANGLE TrunkDirection 90.0
) (+ 1.0 (* 0.5 TransOutSize))))
;; Draw Transition
(vlax-invoke space 'addline TransPoint01 TransPoint02)
(vlax-invoke space 'addline TransPoint02 TransPoint04)
(vlax-invoke space 'addline TransPoint04 TransPoint03)
(vlax-invoke space 'addline TransPoint03 TransPoint01)
;; Change layer color
(setvar "CECOLOR" "8")
;; Draw Transition Breaks
(vlax-invoke space 'addline TransPoint01 TransPoint05)
(vlax-invoke space 'addline TransPoint02 TransPoint06)
(vlax-invoke space 'addline TransPoint01 TransCntr)
(vlax-invoke space 'addline TransPoint02 TransCntr)
;; Set Center Line properties
(setvar "CLAYER" "M-HVAC-CNTR")
(setvar "CECOLOR" "BYLAYER")
;; Draw Centerline
(vlax-invoke space 'addline TransStart TransCntr)
;; Set Insulation Line properties
(setvar "CLAYER" "M-HVAC-INSL")
;; Draw Insulation
(if (= (strcase TransInsul) "INSIDE")
(progn
(vlax-invoke space 'addline TransInsPoint01 TransInsPoint03)
(vlax-invoke space 'addline TransInsPoint02 TransInsPoint04)
)
)
(if (= (strcase TransInsul) "OUTSIDE")
(progn
(vlax-invoke space 'addline TransInsPoint05 TransInsPoint07)
(vlax-invoke space 'addline TransInsPoint06 TransInsPoint08)
)
)
(if (= (strcase TransInsul) "BOTH")
(progn
(vlax-invoke space 'addline TransInsPoint01 TransInsPoint03)
(vlax-invoke space 'addline TransInsPoint02 TransInsPoint04)
(vlax-invoke space 'addline TransInsPoint05 TransInsPoint07)
(vlax-invoke space 'addline TransInsPoint06 TransInsPoint08)
)
)
(TRANS_RESET_ENV)
)
;;; ------------ SQUARE TO SQUARE TRANSITION
(defun TRANS_RND->SQ (TrunkSize TransOutSize TransStart TransLayer TransInsul /
TransInsPoint01 TransInsPoint02 TransInsPoint03 TransInsPoint04 TransInsPoint05
TransInsPoint06
TransInsPoint01 TransInsPoint02 TransInsPoint03 TransInsPoint04 TransInsPoint05
TransInsPoint06
TransInsPoint07 TransInsPoint08 )
;; Get transition outer points
(setq TransCntr (polar TransStart TrunkDirection TransLength))
(setq TransPoint01 (polar TransStart (TRANS_ADD_ANGLE TrunkDirection 90.0) (* 0.
5 TrunkSize)))
(setq TransPoint02 (polar TransStart (TRANS_SUBTRACT_ANGLE TrunkDirection 90.0)
(* 0.5 TrunkSize)))
(setq TransPoint03 (polar TransCntr (TRANS_ADD_ANGLE TrunkDirection 90.0) (* 0.5
TransOutSize)))
(setq TransPoint04 (polar TransCntr (TRANS_SUBTRACT_ANGLE TrunkDirection 90.0) (
* 0.5 TransOutSize)))
;; Get transition inner point (curves for round outlet)
(setq TransBreaks (* 0.25 TransOutSize))
(setq TransPoint05 (polar TransStart (TRANS_ADD_ANGLE TrunkDirection 90.0) Trans
Breaks))
(setq TransPoint06 (polar TransStart (TRANS_SUBTRACT_ANGLE TrunkDirection 90.0)
TransBreaks))
;; Get Insulation Points - INSIDE
(setq TransInsPoint01 (polar TransStart (TRANS_ADD_ANGLE TrunkDirection 90.0) (-
1.0 (* 0.5 TrunkSize))))
(setq TransInsPoint02 (polar TransStart (TRANS_SUBTRACT_ANGLE TrunkDirection 90.
0) (- 1.0 (* 0.5 TrunkSize))))
(setq TransInsPoint03 (polar TransCntr (TRANS_ADD_ANGLE TrunkDirection 90.0) (-
1.0 (* 0.5 TransOutSize))))
(setq TransInsPoint04 (polar TransCntr (TRANS_SUBTRACT_ANGLE TrunkDirection 90.0
) (- 1.0 (* 0.5 TransOutSize))))
;; Get Insulation Points - OUTSIDE
(setq TransInsPoint05 (polar TransStart (TRANS_ADD_ANGLE TrunkDirection 90.0) (+
1.0 (* 0.5 TrunkSize))))
(setq TransInsPoint06 (polar TransStart (TRANS_SUBTRACT_ANGLE TrunkDirection 90.
0) (+ 1.0 (* 0.5 TrunkSize))))
(setq TransInsPoint07 (polar TransCntr (TRANS_ADD_ANGLE TrunkDirection 90.0) (+
1.0 (* 0.5 TransOutSize))))
(setq TransInsPoint08 (polar TransCntr (TRANS_SUBTRACT_ANGLE TrunkDirection 90.0
) (+ 1.0 (* 0.5 TransOutSize))))
;; Draw Transition
(vlax-invoke space 'addline TransPoint01 TransPoint02)
(vlax-invoke space 'addline TransPoint02 TransPoint04)
(vlax-invoke space 'addline TransPoint04 TransPoint03)
(vlax-invoke space 'addline TransPoint03 TransPoint01)
;; Change layer color
(setvar "CECOLOR" "8")
;; Draw Transition Breaks
(vlax-invoke space 'addline TransPoint03 TransPoint05)
(vlax-invoke space 'addline TransPoint04 TransPoint06)
(vlax-invoke space 'addline TransPoint03 TransStart)
(vlax-invoke space 'addline TransPoint04 TransStart)
;; Set Center Line properties
(setvar "CLAYER" "M-HVAC-CNTR")
(setvar "CECOLOR" "BYLAYER")
;; Draw Centerline
(vlax-invoke space 'addline TransStart TransCntr)
;; Set Insulation Line properties
(setvar "CLAYER" "M-HVAC-INSL")
;; Draw Insulation
(if (= (strcase TransInsul) "INSIDE")
(progn
(vlax-invoke space 'addline TransInsPoint01 TransInsPoint03)
(vlax-invoke space 'addline TransInsPoint02 TransInsPoint04)
)
)
(if (= (strcase TransInsul) "OUTSIDE")
(progn
(vlax-invoke space 'addline TransInsPoint05 TransInsPoint07)
(vlax-invoke space 'addline TransInsPoint06 TransInsPoint08)
)
)
(if (= (strcase TransInsul) "BOTH")
(progn
(vlax-invoke space 'addline TransInsPoint01 TransInsPoint03)
(vlax-invoke space 'addline TransInsPoint02 TransInsPoint04)
(vlax-invoke space 'addline TransInsPoint05 TransInsPoint07)
(vlax-invoke space 'addline TransInsPoint06 TransInsPoint08)
)
)
(TRANS_RESET_ENV)
)
;;; ------------ LAYER CREATION ROUINE
(defun TRANS_CREATE_LAYER (Layer Descpition Linetype Thickness Color Plot / TmpL
ist VLA-Obj)
;; Check to see if linetype exsists
(if (= (tblsearch "ltype" Linetype) nil)
(if (TRANS_CHECK_LINETYPE (findfile "acad.lin") Linetype)
(command "linetype" "load" Linetype "acad.lin" "")
(setq Linetype "Continuous")
)
)
;;; ------------ CREATE A LIST FOR ENTMAKE
(setq TmpList
(list
(cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 70 0)
)
)
;; Create layer name list
(setq TmpList (append TmpList (list (cons 2 Layer))))
;; Create layer color list
(setq TmpList (append TmpList (list (cons 62 (atoi Color)))))
;; Create layer linetype list
(setq TmpList (append TmpList (list (cons 6 Linetype))))
;; Create layer lineweight list
(setq TmpList (append TmpList (list (cons 370 (atoi Thickness)))))
;; Create layer plot list
(setq TmpList (append TmpList (list (cons 290 (atoi Plot)))))
;; Create layer from first item in the list
(entmake TmpList)
;; Create layer description
(if(or(= 16.1 (atof(getvar "acadver")))(< 16.1 (atof(getvar "acadver"))))
(progn
(setq VLA-Obj(vla-Add (vla-Get-Layers ActiveDoc)Layer))
(vla-Put-Description VLA-Obj Descpition)
(vlax-release-object VLA-Obj)
)
)
)
;;; ------------ CHECKS TO SEE IF A LINETYPE IS AVAILIBLE
(defun TRANS_CHECK_LINETYPE (LINFile Linetype / OpenFile LineNumber CurrentLine
Result)
(setq OpenFile (open LINFile "r"))
(while (setq CurrentLine (read-line OpenFile))
(if (wcmatch CurrentLine "`**")
(progn
(setq LinetypeName (substr(car(TRANS_STRING_TO_LIST CurrentLine ","))2))
(if (= (strcase Linetype) LinetypeName)
(setq Result T)
)
)
)
)
(close OpenFile)
Result
)
;;; ------------ STRING TO LIST SUB ROUTINE
(defun TRANS_STRING_TO_LIST (Stg Del / CurChr PosCnt TmpLst TmpStr)
(setq PosCnt 1
TmpStr ""
)
(repeat (1+ (strlen Stg))
(setq CurChr (substr Stg PosCnt 1))
(if (= CurChr Del)
(progn
(setq TmpLst (cons TmpStr TmpLst))
(setq TmpStr "")
)
(setq TmpStr (strcat TmpStr CurChr))
)
(setq PosCnt (1+ PosCnt))
)
(setq TmpLst (reverse TmpLst))
)
;;; ------------ GET PERPENDICULAR POINT
(defun TRANS_GET_PERP (StartPoint EndPoint Point / EntList LineStart LineEnd Lin
eAngle PerpAngle)
(setq PerpStart (trans StartPoint 0 1))
(setq PerpEnd (trans EndPoint 0 1))
(setq PerpAngle (angle PerpStart PerpEnd))
(if (minusp (sin (- (angle PerpStart Point) PerpAngle))) ;determine direction
(setq NewAngle (- PerpAngle (/ pi 2))) ;if "below" -90 deg
(setq NewAngle (+ PerpAngle (/ pi 2))) ;or "above" +90 deg
)
NewAngle
)
;;; ------------ ADD / SUBTRACT ANGLE SUB ROUTINES
(defun TRANS_ADD_ANGLE (Radians AddAngle / )
(TRANS_DTR(+ (TRANS_RTD Radians) AddAngle))
)
(defun TRANS_SUBTRACT_ANGLE (Radians AddAngle / )
(TRANS_DTR(- (TRANS_RTD Radians) AddAngle))
)
;;; ------------ ROUND NUMBER
(defun TRANS_RND (Number Precision)
(setq Number(distof (rtos Number 4 Precision)4))
)
;; ------------ DEGREES / RADIANS SUB ROUTINES
(defun TRANS_DTR (NumberOfDegrees)
(* pi (/ NumberOfDegrees 180.0))
)
(defun TRANS_RTD (NumberOfRadians)
(* 180.0 (/ NumberOfRadians pi))
)
;;; ------------ LAW OF SINS (2 ANGLES & 1 SIDE)
(defun TRANS_LoSIN (SinAngle1 SinAngle2 Side1 Round / A SinA SinB Sidelength)
(setq SinA (sin (TRANS_DTR SinAngle1)))
(setq SinB (sin (TRANS_DTR SinAngle2)))
(if (= Round 1)
(setq SideLength (TRANS_RND (/ (* Side1 SinB) SinA)4))
(setq SideLength (/ (* Side1 SinB) SinA))
)
Sidelength
)
;;; ------------ RESET SYSEM VARIABLES
(defun TRANS_RESET_ENV (/)
(setvar "CMDECHO" OldCmdEcho)
(setvar "CLAYER" OldClayer)
(princ)
)
;;;
;;; Echos to the command line
(princ "\n CreateTransitions v1.1 Timothy Spangler, \n January, 2007....loaded.")
(terpri)
(princ "C:TRANS")
(print)
;;; End echo

;;; ------------------------------------------------------------------------
;;; CreateTakeoff.lsp v1.1
;;;
;;; Copyright January, 2007
;;; Timothy G. Spangler
;;;
;;; Permission to use, copy, modify, and distribute this software
;;; for any purpose and without fee is hereby granted, provided
;;; that the above copyright notice appears in all copies and
;;; that both that copyright notice and the limited warranty and
;;; restricted rights notice below appear in all supporting
;;; documentation.
;;;
;;; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;; WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;; PURPOSE AND OF MERCHANTIBILITY ARE HEREBY DISCLAIMED BY THE
;;; PROGRAMMER.
;;;
;;; -----------------------------------------------------------------------
;;; ------------ COMMAND LINE FUNCTIONS
(defun c:TAKEOFF (/)(TAKEOFF_START))
;;; ------------ MAIN FUNCTION
(defun TAKEOFF_START (/
*error*
)
;;; Begin Error Handler -------------------------------------------------
(defun *error* (MSG)
(if (not (member MSG '("Function cancelled" "quit / exit abort")))
(princ (strcat "\n*** Program Error: " (strcase MSG) " ***"))
(princ "\n... Program Cancelled ...")
)
(while (SQ TakeOffSize TakeOffInsPoint TakeOffEntry TakeOffInsul)
)
((and(= (strcase TrunkStyle) "SQUARE")(= (strcase TakeOffStyle) "ROUND"))
(TAKEOFF_SQ->TAKEOFF_RND TakeOffSize TakeOffInsPoint TakeOffEntry TakeOffInsul)
)
((and(= (strcase TrunkStyle) "ROUND")(= (strcase TakeOffStyle) "ROUND"))
(TAKEOFF_RND->SQ TakeOffSize TakeOffInsPoint TakeOffEntry TakeOffInsul)
)
((and(= (strcase TrunkStyle) "ROUND")(= (strcase TakeOffStyle) "SQUARE"))
(TAKEOFF_RND->SQ TakeOffSize TakeOffInsPoint TakeOffEntry TakeOffInsul)
)
)
)
;;; ------------ SQUARE TO SQUARE TAKEOFF
(defun TAKEOFF_SQ->SQ (TakeOffSize TakeOffInsPoint TakeOffEntry TakeOffInsul /
TakeOffPoint1
TakeOffPoint2
TakeOffPoint3
TakeOffPoint4
TakeOffPoint5
TakeOffPoint6
TakeOffPoint7
TakeOffPoint8
TakeOffPoint9
TakeOffPoint10
TakeOffPoint11
TakeOffPoint12
TakeOffPoint13
TakeOffLine1
TakeOffLine2
TakeOffLine3
TakeOffLine4
TakeOffCntrLine1
TakeOffFlare
)
(cond
((= (strcase TakeOffEntry) "SINGLE")
;; Get takeoff outer points
(setq TakeOffPoint1 (polar TakeOffInsPoint FlowDirection (/ TakeoffSize 2)))
(setq TakeOffPoint2 (polar TakeOffInsPoint (TAKEOFF_DTR (+ (TAKEOFF_RTD FlowDire
ction)180)) TakeoffSize))
(setq TakeOffPoint3 (polar TakeOffPoint1 TakeOffAngle (/ TakeoffSize 2)))
(setq TakeOffPoint4 (polar TakeOffPoint3 (TAKEOFF_DTR (+ (TAKEOFF_RTD FlowDirect
ion)180)) TakeoffSize))
;; Get transition center end point
(setq TakeOffPoint5 (polar TakeOffInsPoint TakeOffAngle (/ TakeoffSize 2)))
;; Draw Transition
(setq TakeOffLine1 (vlax-invoke Space 'addline TakeOffPoint1 TakeOffPoint3))
(setq TakeOffLine2 (vlax-invoke Space 'addline TakeOffPoint3 TakeOffPoint4))
(setq TakeOffLine3 (vlax-invoke Space 'addline TakeOffPoint4 TakeOffPoint2))
(cond
((= (strcase TakeOffInsul) "OUTSIDE")
;; Setup layer
(TAKEOFF_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Get takeoff insulation points - OUTSIDE -
(setq TakeOffPoint6 (polar (polar TakeOffPoint1 FlowDirection 1) TakeOffAngle 1)
)
(setq TakeOffPoint7 (polar TakeOffPoint2 TakeOffAngle 1))
(setq TakeOffPoint8 (polar TakeOffPoint3 FlowDirection 1))
(setq TakeOffPoint9 (polar TakeOffPoint4 (+ FlowDirection (TAKEOFF_DTR 180)) 1))
;; Draw insulation
(setq TakeOffLine4 (vlax-invoke Space 'addline TakeOffPoint6 TakeOffPoint8))
(setq TakeOffLine5 (vlax-invoke Space 'addline TakeOffPoint9 TakeOffPoint7))
;; Set properties for insulation
(vlax-put TakeOffLine4 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine5 'Layer "M-HVAC-INSL")
)
((= (strcase TakeOffInsul) "INSIDE")
;; Setup layer
(TAKEOFF_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Get takeoff insulation points - INSIDE -
(setq TakeOffPoint10 (polar (polar TakeOffPoint1 (- FlowDirection (TAKEOFF_DTR 1
80)) 1) Angle-180 1))
(setq TakeOffPoint11 (polar TakeOffPoint2 Angle-180 1))
(setq TakeOffPoint12 (polar TakeOffPoint3 (+ FlowDirection (TAKEOFF_DTR 180)) 1)
)
(setq TakeOffPoint13 (polar TakeOffPoint4 FlowDirection 1))
;;; Draw insulation
(setq TakeOffLine6 (vlax-invoke Space 'addline TakeOffPoint10 TakeOffPoint12))
(setq TakeOffLine7 (vlax-invoke Space 'addline TakeOffPoint13 TakeOffPoint11))
;; Set properties for insulation
(vlax-put TakeOffLine6 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine7 'Layer "M-HVAC-INSL")
)
((= (strcase TakeOffInsul) "BOTH")
;; Setup layer
(TAKEOFF_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Get takeoff insulation points - OUTSIDE -
(setq TakeOffPoint6 (polar (polar TakeOffPoint1 FlowDirection 1) TakeOffAngle 1)
)
(setq TakeOffPoint7 (polar TakeOffPoint2 TakeOffAngle 1))
(setq TakeOffPoint8 (polar TakeOffPoint3 FlowDirection 1))
(setq TakeOffPoint9 (polar TakeOffPoint4 (+ FlowDirection (TAKEOFF_DTR 180)) 1))
;; Get takeoff insulation points - INSIDE -
(setq TakeOffPoint10 (polar (polar TakeOffPoint1 (- FlowDirection (TAKEOFF_DTR 1
80)) 1) Angle-180 1))
(setq TakeOffPoint11 (polar TakeOffPoint2 Angle-180 1))
(setq TakeOffPoint12 (polar TakeOffPoint3 (+ FlowDirection (TAKEOFF_DTR 180)) 1)
)
(setq TakeOffPoint13 (polar TakeOffPoint4 FlowDirection 1))
;;; Draw insulation
(setq TakeOffLine4 (vlax-invoke Space 'addline TakeOffPoint10 TakeOffPoint12))
(setq TakeOffLine5 (vlax-invoke Space 'addline TakeOffPoint13 TakeOffPoint11))
(setq TakeOffLine6 (vlax-invoke Space 'addline TakeOffPoint6 TakeOffPoint8))
(setq TakeOffLine7 (vlax-invoke Space 'addline TakeOffPoint9 TakeOffPoint7))
;; Set properties for insulation
(vlax-put TakeOffLine4 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine5 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine6 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine7 'Layer "M-HVAC-INSL")
)
)
)
((= (strcase TakeOffEntry) "DOUBLE")
(setq TakeOffFlare (TAKEOFF_LAWOFSINE 60 30 (/ TakeoffSize 2)))
;; Get takeoff outer points
(setq TakeOffPoint1 (polar TakeOffInsPoint Angle-90 (+ (/ TakeoffSize 2) TakeOff
Flare)))
(setq TakeOffPoint2 (polar TakeOffInsPoint Angle+90 (+ (/ TakeoffSize 2) TakeOff
Flare)))
(setq TakeOffPoint3 (polar (polar TakeOffInsPoint Angle-90 (/ TakeoffSize 2)) Ta
keOffAngle (/ TakeoffSize 2)))
(setq TakeOffPoint4 (polar (polar TakeOffInsPoint Angle+90 (/ TakeoffSize 2)) Ta
keOffAngle (/ TakeoffSize 2)))
;; Get transition center end point
(setq TakeOffPoint5 (polar TakeOffInsPoint TakeOffAngle (/ TakeoffSize 2)))
;; Draw Transition
(setq TakeOffLine1 (vlax-invoke Space 'addline TakeOffPoint1 TakeOffPoint3))
(setq TakeOffLine2 (vlax-invoke Space 'addline TakeOffPoint3 TakeOffPoint4))
(setq TakeOffLine3 (vlax-invoke Space 'addline TakeOffPoint4 TakeOffPoint2))
;; Get points / draw insulation
(cond
((= (strcase TakeOffInsul) "OUTSIDE")
;; Setup layer
(TAKEOFF_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Get takeoff insulation points - OUTSIDE -
(setq TakeOffPoint6 (polar (polar TakeOffPoint1 Angle-90 (TAKEOFF_LAWOFSINE 60 3
0 1)) TakeOffAngle 1))
(setq TakeOffPoint7 (polar (polar TakeOffPoint2 Angle+90 (TAKEOFF_LAWOFSINE 60 3
0 1)) TakeOffAngle 1))
(setq TakeOffPoint8 (polar TakeOffPoint3 Angle-90 1))
(setq TakeOffPoint9 (polar TakeOffPoint4 Angle+90 1))
;; Draw insulation
(setq TakeOffLine4 (vlax-invoke Space 'addline TakeOffPoint6 TakeOffPoint8))
(setq TakeOffLine5 (vlax-invoke Space 'addline TakeOffPoint9 TakeOffPoint7))
;; Set properties for insulation
(vlax-put TakeOffLine4 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine5 'Layer "M-HVAC-INSL")
)
((= (strcase TakeOffInsul) "INSIDE")
;; Setup layer
(TAKEOFF_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Get takeoff insulation points - INSIDE -
(setq TakeOffPoint10 (polar (polar TakeOffPoint1 Angle+90 (TAKEOFF_LAWOFSINE 60
30 1)) Angle-180 1))
(setq TakeOffPoint11 (polar (polar TakeOffPoint2 Angle-90 (TAKEOFF_LAWOFSINE 60
30 1)) Angle-180 1))
(setq TakeOffPoint12 (polar TakeOffPoint3 Angle+90 1))
(setq TakeOffPoint13 (polar TakeOffPoint4 Angle-90 1))
;;; Draw insulation
(setq TakeOffLine6 (vlax-invoke Space 'addline TakeOffPoint10 TakeOffPoint12))
(setq TakeOffLine7 (vlax-invoke Space 'addline TakeOffPoint13 TakeOffPoint11))
;; Set properties for insulation
(vlax-put TakeOffLine6 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine7 'Layer "M-HVAC-INSL")
)
((= (strcase TakeOffInsul) "BOTH")
;; Setup layer
(TAKEOFF_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Get takeoff insulation points - OUTSIDE -
(setq TakeOffPoint6 (polar (polar TakeOffPoint1 Angle-90 (TAKEOFF_LAWOFSINE 60 3
0 1)) TakeOffAngle 1))
(setq TakeOffPoint7 (polar (polar TakeOffPoint2 Angle+90 (TAKEOFF_LAWOFSINE 60 3
0 1)) TakeOffAngle 1))
(setq TakeOffPoint8 (polar TakeOffPoint3 Angle-90 1))
(setq TakeOffPoint9 (polar TakeOffPoint4 Angle+90 1))
;; Get takeoff insulation points - INSIDE -
(setq TakeOffPoint10 (polar (polar TakeOffPoint1 Angle+90 (TAKEOFF_LAWOFSINE 60
30 1)) Angle-180 1))
(setq TakeOffPoint11 (polar (polar TakeOffPoint2 Angle-90 (TAKEOFF_LAWOFSINE 60
30 1)) Angle-180 1))
(setq TakeOffPoint12 (polar TakeOffPoint3 Angle+90 1))
(setq TakeOffPoint13 (polar TakeOffPoint4 Angle-90 1))
;;; Draw insulation
(setq TakeOffLine4 (vlax-invoke Space 'addline TakeOffPoint10 TakeOffPoint12))
(setq TakeOffLine5 (vlax-invoke Space 'addline TakeOffPoint13 TakeOffPoint11))
(setq TakeOffLine6 (vlax-invoke Space 'addline TakeOffPoint6 TakeOffPoint8))
(setq TakeOffLine7 (vlax-invoke Space 'addline TakeOffPoint9 TakeOffPoint7))
;; Set properties for insulation
(vlax-put TakeOffLine4 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine5 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine6 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine7 'Layer "M-HVAC-INSL")
)
)
)
)
;; Setup layer for centerline
(TAKEOFF_CREATE_LAYER "M-HVAC-CNTR" "Mechanical Plan - Ductwork centerline" "CEN
TER2" "25" "12" "0")
;; Draw Centerline
(setq TakeOffCntrLine1 (vlax-invoke Space 'addline TakeOffInsPoint TakeOffPoint5
))
;; Set properties for centerline
(vlax-put TakeOffCntrLine1 'Layer "M-HVAC-CNTR")
;; Reset envireonment
(TAKEOFF_RESET_ENV)
)
;;; ------------ SQUARE TO SQUARE TAKEOFF
(defun TAKEOFF_SQ->TAKEOFF_RND (TakeOffSize TakeOffInsPoint TakeOffEntry TakeOff
Insul /
TakeOffPoint1
TakeOffPoint2
TakeOffPoint3
TakeOffPoint4
TakeOffPoint5
TakeOffPoint6
TakeOffPoint7
TakeOffPoint8
TakeOffPoint9
TakeOffPoint10
TakeOffPoint11
TakeOffPoint12
TakeOffPoint13
TakeOffLine1
TakeOffLine2
TakeOffLine3
TakeOffLine4
TakeOffCntrLine1
TakeOffFlare
TakeOffBreakPoint1
TakeOffBreakPoint2
TakeOffBreakLine1
TakeOffBreakLine2
TakeOffBreakLine3
TakeOffBreakLine4
)
(cond
((= (strcase TakeOffEntry) "SINGLE")
;; Get takeoff outer points
(setq TakeOffPoint1 (polar TakeOffInsPoint FlowDirection (/ TakeoffSize 2)))
(setq TakeOffPoint2 (polar TakeOffInsPoint (TAKEOFF_DTR (+ (TAKEOFF_RTD FlowDire
ction)180)) TakeoffSize))
(setq TakeOffPoint3 (polar TakeOffPoint1 TakeOffAngle (/ TakeoffSize 2)))
(setq TakeOffPoint4 (polar TakeOffPoint3 (TAKEOFF_DTR (+ (TAKEOFF_RTD FlowDirect
ion)180)) TakeoffSize))
;; Get transition center end point
(setq TakeOffPoint5 (polar TakeOffInsPoint TakeOffAngle (/ TakeoffSize 2)))
;; Get transition inner point (curves for round outlet)
(setq TakeOffBreakPoint1 (polar TakeOffPoint5 FlowDirection (/ (/ TakeoffSize 2)
2)))
(setq TakeOffBreakPoint2 (polar TakeOffPoint5 (TAKEOFF_DTR (+ (TAKEOFF_RTD FlowD
irection)180)) (/ (/ TakeoffSize 2)2)))
;; Draw Transition
(setq TakeOffLine1 (vlax-invoke Space 'addline TakeOffPoint1 TakeOffPoint3))
(setq TakeOffLine2 (vlax-invoke Space 'addline TakeOffPoint3 TakeOffPoint4))
(setq TakeOffLine3 (vlax-invoke Space 'addline TakeOffPoint4 TakeOffPoint2))
;; Draw breaks
(setq TakeOffBreakLine1 (vlax-invoke Space 'addline TakeOffPoint1 TakeOffPoint5)
)
(setq TakeOffBreakLine2 (vlax-invoke Space 'addline TakeOffPoint1 TakeOffBreakPo
int1))
(setq TakeOffBreakLine3 (vlax-invoke Space 'addline TakeOffPoint2 TakeOffPoint5)
)
(setq TakeOffBreakLine4 (vlax-invoke Space 'addline TakeOffPoint2 TakeOffBreakPo
int2))
;; Set properties for insulation
(vlax-put TakeOffBreakLine1 'Color 8)
(vlax-put TakeOffBreakLine2 'Color 8)
(vlax-put TakeOffBreakLine3 'Color 8)
(vlax-put TakeOffBreakLine4 'Color 8)
(cond
((= (strcase TakeOffInsul) "OUTSIDE")
;; Setup layer
(TAKEOFF_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Get takeoff insulation points - OUTSIDE -
(setq TakeOffPoint6 (polar (polar TakeOffPoint1 FlowDirection 1) TakeOffAngle 1)
)
(setq TakeOffPoint7 (polar TakeOffPoint2 TakeOffAngle 1))
(setq TakeOffPoint8 (polar TakeOffPoint3 FlowDirection 1))
(setq TakeOffPoint9 (polar TakeOffPoint4 (+ FlowDirection (TAKEOFF_DTR 180)) 1))
;; Draw insulation
(setq TakeOffLine4 (vlax-invoke Space 'addline TakeOffPoint6 TakeOffPoint8))
(setq TakeOffLine5 (vlax-invoke Space 'addline TakeOffPoint9 TakeOffPoint7))
;; Set properties for insulation
(vlax-put TakeOffLine4 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine5 'Layer "M-HVAC-INSL")
)
((= (strcase TakeOffInsul) "INSIDE")
;; Setup layer
(TAKEOFF_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Get takeoff insulation points - INSIDE -
(setq TakeOffPoint10 (polar (polar TakeOffPoint1 (- FlowDirection (TAKEOFF_DTR 1
80)) 1) Angle-180 1))
(setq TakeOffPoint11 (polar TakeOffPoint2 Angle-180 1))
(setq TakeOffPoint12 (polar TakeOffPoint3 (+ FlowDirection (TAKEOFF_DTR 180)) 1)
)
(setq TakeOffPoint13 (polar TakeOffPoint4 FlowDirection 1))
;;; Draw insulation
(setq TakeOffLine6 (vlax-invoke Space 'addline TakeOffPoint10 TakeOffPoint12))
(setq TakeOffLine7 (vlax-invoke Space 'addline TakeOffPoint13 TakeOffPoint11))
;; Set properties for insulation
(vlax-put TakeOffLine6 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine7 'Layer "M-HVAC-INSL")
)
((= (strcase TakeOffInsul) "BOTH")
;; Setup layer
(TAKEOFF_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Get takeoff insulation points - OUTSIDE -
(setq TakeOffPoint6 (polar (polar TakeOffPoint1 FlowDirection 1) TakeOffAngle 1)
)
(setq TakeOffPoint7 (polar TakeOffPoint2 TakeOffAngle 1))
(setq TakeOffPoint8 (polar TakeOffPoint3 FlowDirection 1))
(setq TakeOffPoint9 (polar TakeOffPoint4 (+ FlowDirection (TAKEOFF_DTR 180)) 1))
;; Get takeoff insulation points - INSIDE -
(setq TakeOffPoint10 (polar (polar TakeOffPoint1 (- FlowDirection (TAKEOFF_DTR 1
80)) 1) Angle-180 1))
(setq TakeOffPoint11 (polar TakeOffPoint2 Angle-180 1))
(setq TakeOffPoint12 (polar TakeOffPoint3 (+ FlowDirection (TAKEOFF_DTR 180)) 1)
)
(setq TakeOffPoint13 (polar TakeOffPoint4 FlowDirection 1))
;;; Draw insulation
(setq TakeOffLine4 (vlax-invoke Space 'addline TakeOffPoint10 TakeOffPoint12))
(setq TakeOffLine5 (vlax-invoke Space 'addline TakeOffPoint13 TakeOffPoint11))
(setq TakeOffLine6 (vlax-invoke Space 'addline TakeOffPoint6 TakeOffPoint8))
(setq TakeOffLine7 (vlax-invoke Space 'addline TakeOffPoint9 TakeOffPoint7))
;; Set properties for insulation
(vlax-put TakeOffLine4 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine5 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine6 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine7 'Layer "M-HVAC-INSL")
)
)
)
((= (strcase TakeOffEntry) "DOUBLE")
(setq TakeOffFlare (TAKEOFF_LAWOFSINE 60 30 (/ TakeoffSize 2)))
;; Get takeoff outer points
(setq TakeOffPoint1 (polar TakeOffInsPoint Angle-90 (+ (/ TakeoffSize 2) TakeOff
Flare)))
(setq TakeOffPoint2 (polar TakeOffInsPoint Angle+90 (+ (/ TakeoffSize 2) TakeOff
Flare)))
(setq TakeOffPoint3 (polar (polar TakeOffInsPoint Angle-90 (/ TakeoffSize 2)) Ta
keOffAngle (/ TakeoffSize 2)))
(setq TakeOffPoint4 (polar (polar TakeOffInsPoint Angle+90 (/ TakeoffSize 2)) Ta
keOffAngle (/ TakeoffSize 2)))
;; Get transition center end point
(setq TakeOffPoint5 (polar TakeOffInsPoint TakeOffAngle (/ TakeoffSize 2)))
;; Get transition inner point (curves for round outlet)
(setq TakeOffBreakPoint1 (polar TakeOffPoint5 Angle-90 (/ (/ TakeoffSize 2)2)))
(setq TakeOffBreakPoint2 (polar TakeOffPoint5 Angle+90 (/ (/ TakeoffSize 2)2)))
;; Draw Transition
(setq TakeOffLine1 (vlax-invoke Space 'addline TakeOffPoint1 TakeOffPoint3))
(setq TakeOffLine2 (vlax-invoke Space 'addline TakeOffPoint3 TakeOffPoint4))
(setq TakeOffLine3 (vlax-invoke Space 'addline TakeOffPoint4 TakeOffPoint2))
;; Draw breaks
(setq TakeOffBreakLine1 (vlax-invoke Space 'addline TakeOffPoint1 TakeOffPoint5)
)
(setq TakeOffBreakLine2 (vlax-invoke Space 'addline TakeOffPoint1 TakeOffBreakPo
int1))
(setq TakeOffBreakLine3 (vlax-invoke Space 'addline TakeOffPoint2 TakeOffPoint5)
)
(setq TakeOffBreakLine4 (vlax-invoke Space 'addline TakeOffPoint2 TakeOffBreakPo
int2))
;; Set properties for insulation
(vlax-put TakeOffBreakLine1 'Color 8)
(vlax-put TakeOffBreakLine2 'Color 8)
(vlax-put TakeOffBreakLine3 'Color 8)
(vlax-put TakeOffBreakLine4 'Color 8)
;; Get points / draw insulation
(cond
((= (strcase TakeOffInsul) "OUTSIDE")
;; Setup layer
(TAKEOFF_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Get takeoff insulation points - OUTSIDE -
(setq TakeOffPoint6 (polar (polar TakeOffPoint1 Angle-90 (TAKEOFF_LAWOFSINE 60 3
0 1)) TakeOffAngle 1))
(setq TakeOffPoint7 (polar (polar TakeOffPoint2 Angle+90 (TAKEOFF_LAWOFSINE 60 3
0 1)) TakeOffAngle 1))
(setq TakeOffPoint8 (polar TakeOffPoint3 Angle-90 1))
(setq TakeOffPoint9 (polar TakeOffPoint4 Angle+90 1))
;; Draw insulation
(setq TakeOffLine4 (vlax-invoke Space 'addline TakeOffPoint6 TakeOffPoint8))
(setq TakeOffLine5 (vlax-invoke Space 'addline TakeOffPoint9 TakeOffPoint7))
;; Set properties for insulation
(vlax-put TakeOffLine4 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine5 'Layer "M-HVAC-INSL")
)
((= (strcase TakeOffInsul) "INSIDE")
;; Setup layer
(TAKEOFF_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Get takeoff insulation points - INSIDE -
(setq TakeOffPoint10 (polar (polar TakeOffPoint1 Angle+90 (TAKEOFF_LAWOFSINE 60
30 1)) Angle-180 1))
(setq TakeOffPoint11 (polar (polar TakeOffPoint2 Angle-90 (TAKEOFF_LAWOFSINE 60
30 1)) Angle-180 1))
(setq TakeOffPoint12 (polar TakeOffPoint3 Angle+90 1))
(setq TakeOffPoint13 (polar TakeOffPoint4 Angle-90 1))
;;; Draw insulation
(setq TakeOffLine6 (vlax-invoke Space 'addline TakeOffPoint10 TakeOffPoint12))
(setq TakeOffLine7 (vlax-invoke Space 'addline TakeOffPoint13 TakeOffPoint11))
;; Set properties for insulation
(vlax-put TakeOffLine6 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine7 'Layer "M-HVAC-INSL")
)
((= (strcase TakeOffInsul) "BOTH")
;; Setup layer
(TAKEOFF_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Get takeoff insulation points - OUTSIDE -
(setq TakeOffPoint6 (polar (polar TakeOffPoint1 Angle-90 (TAKEOFF_LAWOFSINE 60 3
0 1)) TakeOffAngle 1))
(setq TakeOffPoint7 (polar (polar TakeOffPoint2 Angle+90 (TAKEOFF_LAWOFSINE 60 3
0 1)) TakeOffAngle 1))
(setq TakeOffPoint8 (polar TakeOffPoint3 Angle-90 1))
(setq TakeOffPoint9 (polar TakeOffPoint4 Angle+90 1))
;; Get takeoff insulation points - INSIDE -
(setq TakeOffPoint10 (polar (polar TakeOffPoint1 Angle+90 (TAKEOFF_LAWOFSINE 60
30 1)) Angle-180 1))
(setq TakeOffPoint11 (polar (polar TakeOffPoint2 Angle-90 (TAKEOFF_LAWOFSINE 60
30 1)) Angle-180 1))
(setq TakeOffPoint12 (polar TakeOffPoint3 Angle+90 1))
(setq TakeOffPoint13 (polar TakeOffPoint4 Angle-90 1))
;;; Draw insulation
(setq TakeOffLine4 (vlax-invoke Space 'addline TakeOffPoint10 TakeOffPoint12))
(setq TakeOffLine5 (vlax-invoke Space 'addline TakeOffPoint13 TakeOffPoint11))
(setq TakeOffLine6 (vlax-invoke Space 'addline TakeOffPoint6 TakeOffPoint8))
(setq TakeOffLine7 (vlax-invoke Space 'addline TakeOffPoint9 TakeOffPoint7))
;; Set properties for insulation
(vlax-put TakeOffLine4 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine5 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine6 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine7 'Layer "M-HVAC-INSL")
)
)
)
)
;; Setup layer for centerline
(TAKEOFF_CREATE_LAYER "M-HVAC-CNTR" "Mechanical Plan - Ductwork centerline" "CEN
TER2" "25" "12" "0")
;; Draw Centerline
(setq TakeOffCntrLine1 (vlax-invoke Space 'addline TakeOffInsPoint TakeOffPoint5
))
;; Set properties for centerline
(vlax-put TakeOffCntrLine1 'Layer "M-HVAC-CNTR")
;; Reset envireonment
(TAKEOFF_RESET_ENV)
)
;;; ------------ SQUARE TO SQUARE TAKEOFF
(defun TAKEOFF_RND->SQ (TakeOffSize TakeOffInsPoint TakeOffEntry TakeOffInsul /
TakeOffPoint1
TakeOffPoint2
TakeOffPoint3
TakeOffPoint4
TakeOffPoint5
TakeOffPoint6
TakeOffPoint7
TakeOffPoint8
TakeOffPoint9
TakeOffPoint10
TakeOffPoint11
TakeOffPoint12
TakeOffPoint13
TakeOffLine1
TakeOffLine2
TakeOffLine3
TakeOffLine4
TakeOffCntrLine1
TakeOffFlare
TakeOffMidPt1
TakeOffArcPt1
TakeOffArcPt2
)
(cond
((= (strcase TakeOffEntry) "SINGLE")
;; Get takeoff outer points
(setq TakeOffPoint1 (polar TakeOffInsPoint FlowDirection (/ TakeoffSize 2)))
(setq TakeOffPoint2 (polar TakeOffInsPoint (TAKEOFF_DTR (+ (TAKEOFF_RTD FlowDire
ction)180)) TakeoffSize))
(setq TakeOffPoint3 (polar TakeOffPoint1 TakeOffAngle (/ TakeoffSize 2)))
(setq TakeOffPoint4 (polar TakeOffPoint3 (TAKEOFF_DTR (+ (TAKEOFF_RTD FlowDirect
ion)180)) TakeoffSize))
(setq TakeOffMidPt1 (polar TakeOffPoint1 (TAKEOFF_DTR (+ (TAKEOFF_RTD FlowDirect
ion)180)) (/ (distance TakeOffPoint1 TakeOffPoint2) 2)))
(setq TakeOffArcPt1 (polar TakeOffMidPt1 (TAKEOFF_DTR (+ (TAKEOFF_RTD TakeOffAng
le)180))(/ TakeoffSize 4)))
(setq TakeOffArcPt2 (polar TakeOffArcPt1 TakeOffAngle (setq TakeOffRad (TAKEOFF_
GET_RADIUS (distance TakeOffPoint1 TakeOffPoint2)(distance TakeOffMidPt1 TakeOff
ArcPt1)))))
;; Get transition center end point
(setq TakeOffPoint5 (polar TakeOffInsPoint TakeOffAngle (/ TakeoffSize 2)))
;; Draw Transition
(setq TakeOffLine1 (vlax-invoke Space 'addline TakeOffPoint1 TakeOffPoint3))
(setq TakeOffLine2 (vlax-invoke Space 'addline TakeOffPoint3 TakeOffPoint4))
(setq TakeOffLine3 (vlax-invoke Space 'addline TakeOffPoint4 TakeOffPoint2))
(command "_arc" TakeOffPoint1 TakeOffArcPt1 TakeOffPoint2)
(cond
((= (strcase TakeOffInsul) "OUTSIDE")
;; Setup layer
(TAKEOFF_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Get takeoff insulation points - OUTSIDE -
(setq TakeOffPoint6 (polar (polar TakeOffPoint1 FlowDirection 1) TakeOffAngle 1)
)
(setq TakeOffPoint7 (polar TakeOffPoint2 TakeOffAngle 1))
(setq TakeOffPoint8 (polar TakeOffPoint3 FlowDirection 1))
(setq TakeOffPoint9 (polar TakeOffPoint4 (+ FlowDirection (TAKEOFF_DTR 180)) 1))
;; Draw insulation
(setq TakeOffLine4 (vlax-invoke Space 'addline TakeOffPoint6 TakeOffPoint8))
(setq TakeOffLine5 (vlax-invoke Space 'addline TakeOffPoint9 TakeOffPoint7))
;; Set properties for insulation
(vlax-put TakeOffLine4 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine5 'Layer "M-HVAC-INSL")
)
((= (strcase TakeOffInsul) "INSIDE")
;; Setup layer
(TAKEOFF_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Get takeoff insulation points - INSIDE -
(setq TakeOffPoint10 (polar (polar TakeOffPoint1 (- FlowDirection (TAKEOFF_DTR 1
80)) 1) Angle-180 1))
(setq TakeOffPoint11 (polar TakeOffPoint2 Angle-180 1))
(setq TakeOffPoint12 (polar TakeOffPoint3 (+ FlowDirection (TAKEOFF_DTR 180)) 1)
)
(setq TakeOffPoint13 (polar TakeOffPoint4 FlowDirection 1))
;;; Draw insulation
(setq TakeOffLine6 (vlax-invoke Space 'addline TakeOffPoint10 TakeOffPoint12))
(setq TakeOffLine7 (vlax-invoke Space 'addline TakeOffPoint13 TakeOffPoint11))
;; Set properties for insulation
(vlax-put TakeOffLine6 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine7 'Layer "M-HVAC-INSL")
)
((= (strcase TakeOffInsul) "BOTH")
;; Setup layer
(TAKEOFF_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Get takeoff insulation points - OUTSIDE -
(setq TakeOffPoint6 (polar (polar TakeOffPoint1 FlowDirection 1) TakeOffAngle 1)
)
(setq TakeOffPoint7 (polar TakeOffPoint2 TakeOffAngle 1))
(setq TakeOffPoint8 (polar TakeOffPoint3 FlowDirection 1))
(setq TakeOffPoint9 (polar TakeOffPoint4 (+ FlowDirection (TAKEOFF_DTR 180)) 1))
;; Get takeoff insulation points - INSIDE -
(setq TakeOffPoint10 (polar (polar TakeOffPoint1 (- FlowDirection (TAKEOFF_DTR 1
80)) 1) Angle-180 1))
(setq TakeOffPoint11 (polar TakeOffPoint2 Angle-180 1))
(setq TakeOffPoint12 (polar TakeOffPoint3 (+ FlowDirection (TAKEOFF_DTR 180)) 1)
)
(setq TakeOffPoint13 (polar TakeOffPoint4 FlowDirection 1))
;;; Draw insulation
(setq TakeOffLine4 (vlax-invoke Space 'addline TakeOffPoint10 TakeOffPoint12))
(setq TakeOffLine5 (vlax-invoke Space 'addline TakeOffPoint13 TakeOffPoint11))
(setq TakeOffLine6 (vlax-invoke Space 'addline TakeOffPoint6 TakeOffPoint8))
(setq TakeOffLine7 (vlax-invoke Space 'addline TakeOffPoint9 TakeOffPoint7))
;; Set properties for insulation
(vlax-put TakeOffLine4 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine5 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine6 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine7 'Layer "M-HVAC-INSL")
)
)
)
((= (strcase TakeOffEntry) "DOUBLE")
(setq TakeOffFlare (TAKEOFF_LAWOFSINE 60 30 (/ TakeoffSize 2)))
;; Get takeoff outer points
(setq TakeOffPoint1 (polar TakeOffInsPoint Angle-90 (+ (/ TakeoffSize 2) TakeOff
Flare)))
(setq TakeOffPoint2 (polar TakeOffInsPoint Angle+90 (+ (/ TakeoffSize 2) TakeOff
Flare)))
(setq TakeOffPoint3 (polar (polar TakeOffInsPoint Angle-90 (/ TakeoffSize 2)) Ta
keOffAngle (/ TakeoffSize 2)))
(setq TakeOffPoint4 (polar (polar TakeOffInsPoint Angle+90 (/ TakeoffSize 2)) Ta
keOffAngle (/ TakeoffSize 2)))
(setq TakeOffMidPt1 (polar TakeOffPoint1 (TAKEOFF_DTR (+ (TAKEOFF_RTD FlowDirect
ion)180)) (/ (distance TakeOffPoint1 TakeOffPoint2) 2)))
(setq TakeOffArcPt1 (polar TakeOffInsPoint (TAKEOFF_DTR (+ (TAKEOFF_RTD TakeOffA
ngle)180))(/ TakeoffSize 4)))
(setq TakeOffArcPt2 (polar TakeOffArcPt1 TakeOffAngle (setq TakeOffRad (TAKEOFF_
GET_RADIUS (distance TakeOffPoint1 TakeOffPoint2)(distance TakeOffMidPt1 TakeOff
ArcPt1)))))
;; Get transition center end point
(setq TakeOffPoint5 (polar TakeOffInsPoint TakeOffAngle (/ TakeoffSize 2)))
;; Draw Transition
(setq TakeOffLine1 (vlax-invoke Space 'addline TakeOffPoint1 TakeOffPoint3))
(setq TakeOffLine2 (vlax-invoke Space 'addline TakeOffPoint3 TakeOffPoint4))
(setq TakeOffLine3 (vlax-invoke Space 'addline TakeOffPoint4 TakeOffPoint2))
(command "_arc" TakeOffPoint1 TakeOffArcPt1 TakeOffPoint2)
;; Get points / draw insulation
(cond
((= (strcase TakeOffInsul) "OUTSIDE")
;; Setup layer
(TAKEOFF_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Get takeoff insulation points - OUTSIDE -
(setq TakeOffPoint6 (polar (polar TakeOffPoint1 Angle-90 (TAKEOFF_LAWOFSINE 60 3
0 1)) TakeOffAngle 1))
(setq TakeOffPoint7 (polar (polar TakeOffPoint2 Angle+90 (TAKEOFF_LAWOFSINE 60 3
0 1)) TakeOffAngle 1))
(setq TakeOffPoint8 (polar TakeOffPoint3 Angle-90 1))
(setq TakeOffPoint9 (polar TakeOffPoint4 Angle+90 1))
;; Draw insulation
(setq TakeOffLine4 (vlax-invoke Space 'addline TakeOffPoint6 TakeOffPoint8))
(setq TakeOffLine5 (vlax-invoke Space 'addline TakeOffPoint9 TakeOffPoint7))
;; Set properties for insulation
(vlax-put TakeOffLine4 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine5 'Layer "M-HVAC-INSL")
)
((= (strcase TakeOffInsul) "INSIDE")
;; Setup layer
(TAKEOFF_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Get takeoff insulation points - INSIDE -
(setq TakeOffPoint10 (polar (polar TakeOffPoint1 Angle+90 (TAKEOFF_LAWOFSINE 60
30 1)) Angle-180 1))
(setq TakeOffPoint11 (polar (polar TakeOffPoint2 Angle-90 (TAKEOFF_LAWOFSINE 60
30 1)) Angle-180 1))
(setq TakeOffPoint12 (polar TakeOffPoint3 Angle+90 1))
(setq TakeOffPoint13 (polar TakeOffPoint4 Angle-90 1))
;;; Draw insulation
(setq TakeOffLine6 (vlax-invoke Space 'addline TakeOffPoint10 TakeOffPoint12))
(setq TakeOffLine7 (vlax-invoke Space 'addline TakeOffPoint13 TakeOffPoint11))
;; Set properties for insulation
(vlax-put TakeOffLine6 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine7 'Layer "M-HVAC-INSL")
)
((= (strcase TakeOffInsul) "BOTH")
;; Setup layer
(TAKEOFF_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Get takeoff insulation points - OUTSIDE -
(setq TakeOffPoint6 (polar (polar TakeOffPoint1 Angle-90 (TAKEOFF_LAWOFSINE 60 3
0 1)) TakeOffAngle 1))
(setq TakeOffPoint7 (polar (polar TakeOffPoint2 Angle+90 (TAKEOFF_LAWOFSINE 60 3
0 1)) TakeOffAngle 1))
(setq TakeOffPoint8 (polar TakeOffPoint3 Angle-90 1))
(setq TakeOffPoint9 (polar TakeOffPoint4 Angle+90 1))
;; Get takeoff insulation points - INSIDE -
(setq TakeOffPoint10 (polar (polar TakeOffPoint1 Angle+90 (TAKEOFF_LAWOFSINE 60
30 1)) Angle-180 1))
(setq TakeOffPoint11 (polar (polar TakeOffPoint2 Angle-90 (TAKEOFF_LAWOFSINE 60
30 1)) Angle-180 1))
(setq TakeOffPoint12 (polar TakeOffPoint3 Angle+90 1))
(setq TakeOffPoint13 (polar TakeOffPoint4 Angle-90 1))
;;; Draw insulation
(setq TakeOffLine4 (vlax-invoke Space 'addline TakeOffPoint10 TakeOffPoint12))
(setq TakeOffLine5 (vlax-invoke Space 'addline TakeOffPoint13 TakeOffPoint11))
(setq TakeOffLine6 (vlax-invoke Space 'addline TakeOffPoint6 TakeOffPoint8))
(setq TakeOffLine7 (vlax-invoke Space 'addline TakeOffPoint9 TakeOffPoint7))
;; Set properties for insulation
(vlax-put TakeOffLine4 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine5 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine6 'Layer "M-HVAC-INSL")
(vlax-put TakeOffLine7 'Layer "M-HVAC-INSL")
)
)
)
)
;; Setup layer for centerline
(TAKEOFF_CREATE_LAYER "M-HVAC-CNTR" "Mechanical Plan - Ductwork centerline" "CEN
TER2" "25" "12" "0")
;; Draw Centerline
(setq TakeOffCntrLine1 (vlax-invoke Space 'addline TakeOffInsPoint TakeOffPoint5
))
;; Set properties for centerline
(vlax-put TakeOffCntrLine1 'Layer "M-HVAC-CNTR")
;; Reset envireonment
(TAKEOFF_RESET_ENV)
)
;;; ------------ LAYER CREATION ROUINE
(defun TAKEOFF_CREATE_LAYER (Layer Descpition Linetype Thickness Color Plot / Tm
pList VLA-Obj)
;; Check to see if linetype exsists
(if (= (tblsearch "ltype" Linetype) nil)
(if (TAKEOFF_CHECK_LINETYPE (findfile "acad.lin") Linetype)
(command "linetype" "load" Linetype "acad.lin" "")
(setq Linetype "Continuous")
)
)
;;; ------------ CREATE A LIST FOR ENTMAKE
(setq TmpList
(list
(cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 70 0)
)
)
;; Create layer name list
(setq TmpList (append TmpList (list (cons 2 Layer))))
;; Create layer color list
(setq TmpList (append TmpList (list (cons 62 (atoi Color)))))
;; Create layer linetype list
(setq TmpList (append TmpList (list (cons 6 Linetype))))
;; Create layer lineweight list
(setq TmpList (append TmpList (list (cons 370 (atoi Thickness)))))
;; Create layer plot list
(setq TmpList (append TmpList (list (cons 290 (atoi Plot)))))
;; Create layer from first item in the list
(entmake TmpList)
;; Create layer description
(if(or(= 16.1 (atof(getvar "acadver")))(< 16.1 (atof(getvar "acadver"))))
(progn
(setq VLA-Obj(vla-Add (vla-Get-Layers ActiveDoc)Layer))
(vla-Put-Description VLA-Obj Descpition)
(vlax-release-object VLA-Obj)
)
)
)
;;; ------------ CHECKS TO SEE IF A LINETYPE IS AVAILIBLE
(defun TAKEOFF_CHECK_LINETYPE (LINFile Linetype / OpenFile LineNumber CurrentLin
e Result)
(setq OpenFile (open LINFile "r"))
(while (setq CurrentLine (read-line OpenFile))
(if (wcmatch CurrentLine "`**")
(progn
(setq LinetypeName (substr(car(TAKEOFF_STRING_TO_LIST CurrentLine ","))2))
(if (= (strcase Linetype) LinetypeName)
(setq Result T)
)
)
)
)
(close OpenFile)
Result
)
;;; ------------ STRING TO LIST SUB ROUTINE
(defun TAKEOFF_STRING_TO_LIST (Stg Del / CurChr PosCnt TmpLst TmpStr)
(setq PosCnt 1
TmpStr ""
)
(repeat (1+ (strlen Stg))
(setq CurChr (substr Stg PosCnt 1))
(if (= CurChr Del)
(progn
(setq TmpLst (cons TmpStr TmpLst))
(setq TmpStr "")
)
(setq TmpStr (strcat TmpStr CurChr))
)
(setq PosCnt (1+ PosCnt))
)
(setq TmpLst (reverse TmpLst))
)
;; ------------ DEGREES / RADIANS SUB ROUTINES
(defun TAKEOFF_DTR (NumberOfDegrees)
(* pi (/ NumberOfDegrees 180.0))
)
(defun TAKEOFF_RTD (NumberOfRadians)
(* 180.0 (/ NumberOfRadians pi))
)
;;; ------------ ROUND NUMBER
(defun TAKEOFF_RND (Number Precision)
(setq Number(distof (rtos Number 4 Precision)4))
)
;;; ------------ LAW OF SINS (2 ANGLES & 1 SIDE)
(defun TAKEOFF_LAWOFSINE (SinAngle1 SinAngle2 Side1 / A SinA SinB Sidelength)
(setq SinA (sin (TAKEOFF_DTR SinAngle1)))
(setq SinB (sin (TAKEOFF_DTR SinAngle2)))
(setq SideLength (TAKEOFF_RND (/ (* Side1 SinB) SinA)4))
Sidelength
)
;;; ------------ GET RADIUS OF ARC (CHORD LENGTH & CHORD HEIGHT KNOWN)
(defun TAKEOFF_GET_RADIUS (ChordLength ChordHeight / Radius)
(setq Radius (/(+(expt ChordHeight 2)(/ (expt ChordLength 2)4))(* ChordHeight 2)
))
Radius
)
;;; ------------ RESET SYSEM VARIABLES
(defun TAKEOFF_RESET_ENV (/)
(setvar "CMDECHO" OldCmdEcho)
(setvar "CLAYER" OldClayer)
(setvar "OSMODE" OldOsmode)
(princ)
)
;;;
;;; Echos to the command line
(princ "\n CreateTakeoff v1.1 Timothy Spangler, \n January, 2007....loaded.")
(terpri)
(princ "C:TAKEOFF")
(print)
;;; End echo

;;; ------------------------------------------------------------------------
;;; CreateSection.lsp v1.1
;;;
;;; Copyright January, 2007
;;; Timothy G. Spangler
;;;
;;; Permission to use, copy, modify, and distribute this software
;;; for any purpose and without fee is hereby granted, provided
;;; that the above copyright notice appears in all copies and
;;; that both that copyright notice and the limited warranty and
;;; restricted rights notice below appear in all supporting
;;; documentation.
;;;
;;; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;; WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;; PURPOSE AND OF MERCHANTIBILITY ARE HEREBY DISCLAIMED BY THE
;;; PROGRAMMER.
;;;
;;; -----------------------------------------------------------------------
;;; ------------ COMMAND LINE FUNCTIONS
(defun c:SECT (/) (SECTION_START))
;;; ------------ MAIN FUNCTION
(defun SECTION_START ( / *error* Angle+90 Angle-90 ActiveDoc OldClayer OldCmdEch
o Space
SectStyle
SectShape
SectWidth
SectLength
SectAlign
SectType
SectInsul
InsPoint
InsAngle
)
;;; Begin Error Handler -------------------------------------------------
(defun *error* (MSG)
(if (not (member MSG '("Function cancelled" "quit / exit abort")))
(princ (strcat "\n*** Program Error: " (strcase MSG) " ***"))
(princ "\n... Program Cancelled ...")
)
(while (< 0 (getvar "cmdactive"))
(command)
)
(princ)
)
;;; End Error Handler ---------------------------------------------------
(SECTION_SET_ENV)
)
;;; ------------ SET ENVIROMENT BEFORE LAUNCH
(defun SECTION_SET_ENV(/)
(setq OldClayer (getvar "CLAYER"))
(setq OldCmdEcho (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(vl-load-com)
(setq ActiveDoc (vla-get-activedocument (vlax-get-acad-object)))
(setq Space
(if (= (getvar "cvport") 1)
(vla-get-paperspace ActiveDoc)
(vla-get-modelspace ActiveDoc)
)
)
;; Run duct
(SECTION_RUN)
)
;;; ------------ GET VARIABLES FOR DIFFUSER CREATION
(defun SECTION_RUN (/)
;; Get section style
(initget "Supply s S Return r R Exhaust e E Dust d D")
(if(not(setq SectStyle (getkword "Enter section style: (Supply/Return/Exhaust/Du
st) ")))
(setq SectStyle "Supply")
)
;; Get section shape
(initget "Square s S Round r R")
(if (not(setq SectShape (getkword "Enter section shape: (Square/Round) ")))
(setq SectShape "Square")
)
(if (= (strcase SectShape) "SQUARE")
(progn
;; If square
(setq SectWidth (getreal "\n Enter section width: (6\")"))
(if (not SectWidth)
(setq SectWidth 6.0)
)
(if (< SectWidth 6.0)
(setq SectWidth (getreal "\n Enter section width: \n -Must be greater than 6\"-
"))
)
(setq SectLength (getreal "\n Enter section length: (6\")"))
(if (not SectLength)
(setq SectLength 6.0)
)
(if (< SectLength 6.0)
(setq SectLength (getreal "\n Enter section length: \n -Must be greater than 6\"
- "))
)
)
(progn
;; If round
(setq SectWidth (getreal "\n Enter section diameter: (12\")"))
(if (not SectWidth)
(setq SectWidth 12.0)
)
(if (< SectWidth 4.0)
(setq SectWidth (getreal "\n Enter diffuser diameter: \n -Must be greater than 4
\"- "))
)
)
)
;; Get section alignment
(initget 1 "Center c C Top t T Bottom b B")
(if (not(setq SectAlign (getkword "\n Enter duct alignment: (Center/Top/Bottom)
")))
(setq SectAlign "Center")
)
;; Get section type
(initget "Up u U Down d D")
(if (not(setq SectType (getkword "\n Enter section type: (Up/Down) ")))
(setq SectType "Up")
)
;; Get section insulation
(initget 1 "None Inside Outside Both")
(if (not (setq SectInsul (getkword "\n Insulation options: (None/Inside/Oustside
/Both) ")))
(setq SectInsul "None")
)
;; Get insertion point
(while(null(setq InsPoint (getpoint "\n Define insertion point: ")))
(princ "-Point not defined-")
)
;; Get insertion angle
(setq InsAngle (getangle InsPoint "\n Define section direction: "))
;; Setup angles
(setq Angle+90 (+ InsAngle (SECTION_DTR 90)))
(setq Angle-90 (- InsAngle (SECTION_DTR 90)))
(if(= (strcase SectShape) "SQUARE")
(SECTION_CREATE_SQUARE InsPoint InsAngle SectWidth SectLength SectAlign SectType
)
(SECTION_CREATE_ROUND InsPoint SectWidth SectType)
)
(princ)
)
;;; ------------ LAYER CREATION ROUINE
(defun SECTION_CREATE_LAYER (Layer Descpition Linetype Thickness Color Plot / Tm
pList VLA-Obj)
;; Check to see if linetype exsists
(if (= (tblsearch "ltype" Linetype) nil)
(if (SECTION_CHECK_LINETYPE (findfile "acad.lin") Linetype)
(command "linetype" "load" Linetype "acad.lin" "")
(setq Linetype "Continuous")
)
)
;;; ------------ CREATE A LIST FOR ENTMAKE
(setq TmpList
'((0 . "LAYER")
(100 . "AcDbSymbolTableRecord")
(100 . "AcDbLayerTableRecord")
(70 . 0)
)
)
;; Create layer name list
(setq TmpList (append TmpList (list (cons 2 Layer))))
;; Create layer color list
(setq TmpList (append TmpList (list (cons 62 (atoi Color)))))
;; Create layer linetype list
(setq TmpList (append TmpList (list (cons 6 Linetype))))
;; Create layer lineweight list
(setq TmpList (append TmpList (list (cons 370 (atoi Thickness)))))
;; Create layer plot list
(setq TmpList (append TmpList (list (cons 290 (atoi Plot)))))
;; Create layer from first item in the list
(entmake TmpList)
;; Create layer description
(if(or(= 16.1 (atof(getvar "acadver")))(< 16.1 (atof(getvar "acadver"))))
(progn
(setq VLA-Obj(vla-Add (vla-Get-Layers ActiveDoc)Layer))
(vla-Put-Description VLA-Obj Descpition)
(vlax-release-object VLA-Obj)
)
)
)
;;; ------------ CHECKS TO SEE IF A LINETYPE IS AVAILIBLE
(defun SECTION_CHECK_LINETYPE (LINFile Linetype / OpenFile LineNumber CurrentLin
e Result)
(setq OpenFile (open LINFile "r"))
(while (setq CurrentLine (read-line OpenFile))
(if (wcmatch CurrentLine "`**")
(progn
(setq LinetypeName (substr(car(SECTION_STRING_TO_LIST CurrentLine ","))2))
(if (= (strcase Linetype) LinetypeName)
(setq Result T)
)
)
)
)
(close OpenFile)
Result
)
;;; ------------ STRING TO LIST SUB ROUTINE
(defun SECTION_STRING_TO_LIST (Stg Del / CurChr PosCnt TmpLst TmpStr)
(setq PosCnt 1
TmpStr ""
)
(repeat (1+ (strlen Stg))
(setq CurChr (substr Stg PosCnt 1))
(if (= CurChr Del)
(progn
(setq TmpLst (cons TmpStr TmpLst))
(setq TmpStr "")
)
(setq TmpStr (strcat TmpStr CurChr))
)
(setq PosCnt (1+ PosCnt))
)
(setq TmpLst (reverse TmpLst))
)
;;; ------------ CREATE LAY-IN SQUARE DIFFUSER
(defun SECTION_CREATE_SQUARE(InsPoint InsAngle SectWidth SectLength SectAlign Se
ctType /
SectPoint1
SectPoint2
SectPoint3
SectPoint4
SectCenter
SectPointList
SectPoints
Stop
Counter
TempPoint
vlaSection
VlaSectLine1
VlaSectLine2
SectInsulIn
SectInsulOut
)
(setvar "CLAYER" "0")
;; Set up creation points
(cond
((= (strcase SectAlign) "CENTER")
(setq SectPoint1 (polar InsPoint Angle+90 (/ SectWidth 2)))
(setq SectPoint2 (polar InsPoint Angle-90 (/ SectWidth 2)))
(setq SectPoint3 (polar SectPoint1 InsAngle SectLength))
(setq SectPoint4 (polar SectPoint2 InsAngle SectLength))
(setq SectCenter (polar SectPoint1 (angle SectPoint1 SectPoint4) (/(distance Sec
tPoint1 SectPoint4)2)))
)
((= (strcase SectAlign) "TOP")
(setq SectPoint1 InsPoint)
(setq SectPoint2 (polar SectPoint1 Angle+90 SectWidth))
(setq SectPoint3 (polar SectPoint1 InsAngle SectLength))
(setq SectPoint4 (polar SectPoint2 InsAngle SectLength))
(setq SectCenter (polar SectPoint1 (angle SectPoint1 SectPoint4) (/(distance Sec
tPoint1 SectPoint4)2)))
)
((= (strcase SectAlign) "BOTTOM")
(setq SectPoint1 InsPoint)
(setq SectPoint2 (polar SectPoint1 Angle-90 SectWidth))
(setq SectPoint3 (polar SectPoint1 InsAngle SectLength))
(setq SectPoint4 (polar SectPoint2 InsAngle SectLength))
(setq SectCenter (polar SectPoint1 (angle SectPoint1 SectPoint4) (/(distance Sec
tPoint1 SectPoint4)2)))
)
)
(setq SectPointList (list SectPoint1 SectPoint3 SectPoint4 SectPoint2))
;; Create list of 2D point from list of points
(setq SectPoints nil)
(setq Stop (length SectPointList))
(setq Counter 0)
(while (/= Counter Stop)
(setq TempPoint(reverse(cdr(reverse (nth Counter SectPointList)))))
(setq SectPoints (append TempPoint SectPoints))
(setq Counter (1+ Counter))
)
;; Draw the outside of the section
(setq vlaSection (vla-addLightweightPolyline Space
(vlax-safearray-fill
(vlax-make-safearray vlax-vbDouble (cons 0 (- (length SectPoints) 1)))
SectPoints))
)
;; Close the polyline
(vla-put-closed vlaSection :vlax-true)
(cond
((= (strcase SectStyle) "SUPPLY")
;; Setup layer
(SECTION_CREATE_LAYER "M-HVAC-SUPP" "Mechanical Plan - Supply ductwork" "Continu
ous" "35" "133" "1")
;; Create line for supply
(setq VlaSectLine1 (vlax-invoke space 'AddLine SectPoint1 SectPoint4))
(setq VlaSectLine2 (vlax-invoke space 'AddLine SectPoint2 SectPoint3))
;; Set layer properties
(vlax-put vlaSection 'Layer "M-HVAC-SUPP")
(vlax-put VlaSectLine1 'Layer "M-HVAC-SUPP")
(vlax-put VlaSectLine2 'Layer "M-HVAC-SUPP")
;; Set linetype properties
(if (= (strcase SectType) "UP")
(progn
(vlax-put vlaSection 'Linetype "BYLAYER")
(vlax-put VlaSectLine1 'Linetype "BYLAYER")
(vlax-put VlaSectLine2 'Linetype "BYLAYER")
)
(progn
(vlax-put vlaSection 'Linetype "HIDDEN2")
(vlax-put VlaSectLine1 'Linetype "HIDDEN2")
(vlax-put VlaSectLine2 'Linetype "HIDDEN2")
)
)
)
((= (strcase SectStyle)"RETURN")
;; Setup layer
(SECTION_CREATE_LAYER "M-HVAC-RETN" "Mechanical Plan - Return ductwork" "Continu
ous" "35" "23" "1")
;; Create line for return
(setq VlaSectLine1 (vlax-invoke space 'AddLine SectPoint1 SectPoint4))
;; Set layer properties
(vlax-put vlaSection 'Layer "M-HVAC-RETN")
(vlax-put VlaSectLine1 'Layer "M-HVAC-RETN")
;; Set linetype properties
(if (= (strcase SectType) "UP")
(progn
(vlax-put vlaSection 'Linetype "BYLAYER")
(vlax-put VlaSectLine1 'Linetype "BYLAYER")
)
(progn
(vlax-put vlaSection 'Linetype "HIDDEN2")
(vlax-put VlaSectLine1 'Linetype "HIDDEN2")
)
)
)
((= (strcase SectStyle)"EXHAUST")
;; Setup layer
(SECTION_CREATE_LAYER "M-HVAC-EXHS" "Mechanical Plan - Exhaust ductwork" "Contin
uous" "35" "83" "1")
;; Create line for exhaust
(setq VlaSectLine1 (vlax-invoke space 'AddLine SectPoint1 SectPoint4))
(setq VlaSectLine2 (vlax-invoke space 'AddLine SectPoint2 SectCenter))
;; Set layer properties
(vlax-put vlaSection 'Layer "M-HVAC-EXHS")
(vlax-put VlaSectLine1 'Layer "M-HVAC-EXHS")
(vlax-put VlaSectLine2 'Layer "M-HVAC-EXHS")
;; Set linetype properties
(if (= (strcase SectType) "UP")
(progn
(vlax-put vlaSection 'Linetype "BYLAYER")
(vlax-put VlaSectLine1 'Linetype "BYLAYER")
(vlax-put VlaSectLine2 'Linetype "BYLAYER")
)
(progn
(vlax-put vlaSection 'Linetype "HIDDEN2")
(vlax-put VlaSectLine1 'Linetype "HIDDEN2")
(vlax-put VlaSectLine2 'Linetype "HIDDEN2")
)
)
)
((= (strcase SectStyle)"DUST")
;; Setup layer
(SECTION_CREATE_LAYER "M-HVAC-DUST" "Mechanical Plan - Dust and fume collection
ductwork" "Continuous" "35" "203" "1")
;; Create line for exhaust
(setq VlaSectLine1 (vlax-invoke space 'AddLine SectPoint1 SectCenter))
(setq VlaSectLine2 (vlax-invoke space 'AddLine SectPoint3 SectCenter))
;; Set layer properties
(vlax-put vlaSection 'Layer "M-HVAC-DUST")
(vlax-put VlaSectLine1 'Layer "M-HVAC-DUST")
(vlax-put VlaSectLine2 'Layer "M-HVAC-DUST")
;; Set linetype properties
(if (= (strcase SectType) "UP")
(progn
(vlax-put vlaSection 'Linetype "BYLAYER")
(vlax-put VlaSectLine1 'Linetype "BYLAYER")
(vlax-put VlaSectLine2 'Linetype "BYLAYER")
)
(progn
(vlax-put vlaSection 'Linetype "HIDDEN2")
(vlax-put VlaSectLine1 'Linetype "HIDDEN2")
(vlax-put VlaSectLine2 'Linetype "HIDDEN2")
)
)
)
)
;; Setup layer for centerline
(SECTION_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Create insulation
(cond
((= (strcase SectInsul) "INSIDE")
;; Offset the polyline for insulation
(setq SectInsulIn (car(vlax-invoke vlaSection 'Offset -1)))
(vlax-put SectInsulIn 'Layer "M-HVAC-INSL")
(vlax-put SectInsulIn 'Linetype "BYLAYER")
)
((= (strcase SectInsul) "OUTSIDE")
;; Offset the polyline for insulation
(setq SectInsulOut (car(vlax-invoke vlaSection 'Offset 1)))
(vlax-put SectInsulOut 'Layer "M-HVAC-INSL")
(vlax-put SectInsulOut 'Linetype "BYLAYER")
)
((= (strcase SectInsul) "BOTH")
;; Offset the polyline for insulation
(setq SectInsulIn (car(vlax-invoke vlaSection 'Offset -1)))
(setq SectInsulOut (car(vlax-invoke vlaSection 'Offset 1)))
(vlax-put SectInsulIn 'Layer "M-HVAC-INSL")
(vlax-put SectInsulIn 'Linetype "BYLAYER")
(vlax-put SectInsulOut 'Layer "M-HVAC-INSL")
(vlax-put SectInsulOut 'Linetype "BYLAYER")
)
)
(SECTION_RESET_ENV)
)
;;; ------------ CREATE LAY-IN SQUARE ROUND
(defun SECTION_CREATE_ROUND(InsPoint SectWidth SectType /
vlaSection
VlaLine
SectPoint1
SectCenter
SectPointList
SuppPoints
RtrnPoints
ExhsPoints
DustPoints
SectInsulIn
SectInsulOut
)
(setvar "CLAYER" "0")
;; Set up creation points
(cond
((= (strcase SectAlign) "CENTER")
(setq SectPoint1 InsPoint)
(setq SectCenter SectPoint1)
(setq SectPointList (SECTION_GET_POINTS SectPoint1 (SECTION_INSCRIBE_SQUARE Sect
Width)(SECTION_INSCRIBE_SQUARE SectWidth)))
)
((= (strcase SectAlign) "TOP")
(setq SectPoint1 (polar InsPoint Angle-90 (/ Sectwidth 2)))
(setq SectCenter SectPoint1)
(setq SectPointList (SECTION_GET_POINTS SectPoint1 (SECTION_INSCRIBE_SQUARE Sect
Width)(SECTION_INSCRIBE_SQUARE SectWidth)))
)
((= (strcase SectAlign) "BOTTOM")
(setq SectPoint1 (polar InsPoint Angle+90 (/ Sectwidth 2)))
(setq SectCenter SectPoint1)
(setq SectPointList (SECTION_GET_POINTS SectPoint1 (SECTION_INSCRIBE_SQUARE Sect
Width)(SECTION_INSCRIBE_SQUARE SectWidth)))
)
)
;; Draw the outside of the section
(setq vlaSection (vlax-invoke space 'AddCircle SectPoint1 (/ SectWidth 2)))
;; Draw lines to show type os section
(cond
((= (strcase SectStyle)"SUPPLY")
;; Setup layer
(SECTION_CREATE_LAYER "M-HVAC-SUPP" "Mechanical Plan - Supply ductwork" "Continu
ous" "35" "133" "1")
;; Set properties
(vlax-put vlaSection 'Layer "M-HVAC-SUPP")
;; Set poits for section type
(setq SuppPoints (list (nth 0 SectPointList)(nth 1 SectPointList)(nth 2 SectPoin
tList)(nth 3 SectPointList)))
(if (= (strcase SectType) "UP")
;; Up duct
(foreach X SuppPoints
(setq VlaLine (vlax-invoke space 'AddLine X SectCenter))
;; Set properties
(vlax-put VlaLine 'Layer "M-HVAC-SUPP")
(vlax-put VlaLine 'Linetype "BYLAYER")
)
;; Down duct
(foreach X SuppPoints
(setq VlaLine (vlax-invoke space 'AddLine X SectCenter))
;; Set properties
(vlax-put VlaLine 'Layer "M-HVAC-SUPP")
(vlax-put VlaLine 'Linetype "HIDDEN2")
(vlax-put vlaSection 'Linetype "HIDDEN2")
)
)
)
((= (strcase SectStyle) "RETURN")
;; Setup layer
(SECTION_CREATE_LAYER "M-HVAC-RETN" "Mechanical Plan - Return ductwork" "Continu
ous" "35" "23" "1")
;; Set properties
(vlax-put vlaSection 'Layer "M-HVAC-RETN")
;; Set poits for section type
(setq RtrnPoints (list (nth 0 SectPointList)(nth 2 SectPointList)))
(if (= (strcase SectType) "UP")
;; Up duct
(foreach X RtrnPoints
(setq VlaLine (vlax-invoke space 'AddLine X SectCenter))
;; Set properties
(vlax-put VlaLine 'Layer "M-HVAC-RETN")
(vlax-put VlaLine 'Linetype "BYLAYER")
)
;; Down duct
(foreach X RtrnPoints
(setq VlaLine (vlax-invoke space 'AddLine X SectCenter))
;; Set properties
(vlax-put VlaLine 'Layer "M-HVAC-RETN")
(vlax-put VlaLine 'Linetype "HIDDEN2")
(vlax-put vlaSection 'Linetype "HIDDEN2")
)
)
)
((= (strcase SectStyle)"EXHAUST")
;; Setup layer
(SECTION_CREATE_LAYER "M-HVAC-EXHS" "Mechanical Plan - Exhaust ductwork" "Contin
uous" "35" "83" "1")
;; Set properties
(vlax-put vlaSection 'Layer "M-HVAC-EXHS")
;; Set poits for section type
(setq ExhsPoints (list (nth 0 SectPointList)(nth 1 SectPointList)(nth 2 SectPoin
tList)))
(if (= (strcase SectType) "UP")
;; Up duct
(foreach X ExhsPoints
(setq VlaLine (vlax-invoke space 'AddLine X SectCenter))
;; Set properties
(vlax-put VlaLine 'Layer "M-HVAC-EXHS")
(vlax-put VlaLine 'Linetype "BYLAYER")
)
;; Down duct
(foreach X ExhsPoints
(setq VlaLine (vlax-invoke space 'AddLine X SectCenter))
;; Set properties
(vlax-put VlaLine 'Layer "M-HVAC-EXHS")
(vlax-put VlaLine 'Linetype "HIDDEN2")
(vlax-put vlaSection 'Linetype "HIDDEN2")
)
)
)
((= (strcase SectStyle) "DUST")
;; Setup layer
(SECTION_CREATE_LAYER "M-HVAC-DUST" "Mechanical Plan - Dust and fume collection
ductwork" "Continuous" "35" "203" "1")
;; Set properties
(vlax-put vlaSection 'Layer "M-HVAC-DUST")
;; Set poits for section type
(setq DustPoints (list (nth 0 SectPointList)(nth 1 SectPointList)))
(if (= (strcase SectType) "UP")
;; Up duct
(foreach X DustPoints
(setq VlaLine (vlax-invoke space 'AddLine X SectCenter))
;; Set properties
(vlax-put VlaLine 'Layer "M-HVAC-DUST")
(vlax-put VlaLine 'Linetype "BYLAYER")
)
;; Down duct
(foreach X DustPoints
(setq VlaLine (vlax-invoke space 'AddLine X SectCenter))
;; Set properties
(vlax-put VlaLine 'Layer "M-HVAC-DUST")
(vlax-put VlaLine 'Linetype "HIDDEN2")
(vlax-put vlaSection 'Linetype "HIDDEN2")
)
)
)
)
;; Setup layer for centerline
(SECTION_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Create insulation
(cond
((= (strcase SectInsul) "INSIDE")
;; Offset the polyline for insulation
(setq SectInsulIn (car(vlax-invoke vlaSection 'Offset -1)))
(vlax-put SectInsulIn 'Layer "M-HVAC-INSL")
(vlax-put SectInsulIn 'Linetype "BYLAYER")
)
((= (strcase SectInsul) "OUTSIDE")
;; Offset the polyline for insulation
(setq SectInsulOut (car(vlax-invoke vlaSection 'Offset 1)))
(vlax-put SectInsulOut 'Layer "M-HVAC-INSL")
(vlax-put SectInsulOut 'Linetype "BYLAYER")
)
((= (strcase SectInsul) "BOTH")
;; Offset the polyline for insulation
(setq SectInsulIn (car(vlax-invoke vlaSection 'Offset -1)))
(setq SectInsulOut (car(vlax-invoke vlaSection 'Offset 1)))
(vlax-put SectInsulIn 'Layer "M-HVAC-INSL")
(vlax-put SectInsulIn 'Linetype "BYLAYER")
(vlax-put SectInsulOut 'Layer "M-HVAC-INSL")
(vlax-put SectInsulOut 'Linetype "BYLAYER")
)
)
(SECTION_RESET_ENV)
)
;;; ------------ DEGREES TO RADIANS SUB ROUTINE
(defun SECTION_DTR (NumberOfDegrees)
(* pi (/ NumberOfDegrees 180.0))
)
;;; ------------ GET CORNER POINTS FROM CENTER POINT
(defun SECTION_GET_POINTS (InsPoint Width Length / DLength DWidth )
(setq DLength (* 0.5 Width))
(setq DWidth (* 0.5 Length))
(setq InsPoint (trans InsPoint 1 0))
(setq DPoint1 (list (- (car InsPoint) DLength)(- (cadr InsPoint) DWidth)(caddr I
nsPoint)))
(setq DPoint2 (list (+ (car InsPoint) DLength)(+ (cadr InsPoint) DWidth)(caddr I
nsPoint)))
(setq DPoint3 (list (car DPoint2)(cadr DPoint1)(caddr InsPoint)))
(setq DPoint4 (list (car DPoint1)(cadr DPoint2)(caddr InsPoint)))
(list DPoint1 DPoint3 DPoint2 DPoint4)
)
;;; ------------ INSCRIBE A SQUARE IN A CIRCLE
(defun SECTION_INSCRIBE_SQUARE (Diameter / A SinA SinB Sidelength)
(setq A Diameter)
(setq SinA (sin (SECTION_DTR 90)))
(setq SinB (sin (SECTION_DTR 45)))
(setq SideLength (RND (/ (* A SinB) SinA)4))
Sidelength
)
;;; ------------ RESET SYSEM VARIABLES
(defun SECTION_RESET_ENV (/)
(setvar "CMDECHO" OldCmdEcho)
(setvar "CLAYER" OldClayer)
(princ)
)
;;;
;;; Echos to the command line
(princ "\n CreateSection v1.1 Timothy Spangler, \n January, 2007....loaded.")
(terpri)
(princ "C:SECT")
(print)
;;; End echo

;;; ------------------------------------------------------------------------
;;; CreateReducer.lsp v1.1
;;;
;;; Copyright January, 2007
;;; Timothy G. Spangler
;;;
;;; Permission to use, copy, modify, and distribute this software
;;; for any purpose and without fee is hereby granted, provided
;;; that the above copyright notice appears in all copies and
;;; that both that copyright notice and the limited warranty and
;;; restricted rights notice below appear in all supporting
;;; documentation.
;;;
;;; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;; WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;; PURPOSE AND OF MERCHANTIBILITY ARE HEREBY DISCLAIMED BY THE
;;; PROGRAMMER.
;;;
;;; -----------------------------------------------------------------------
;;; ------------ COMMAND LINE FUNCTIONS
(defun c:REDUCER (/)(REDUCER_START))
;;; ------------ MAIN FUNCTION
(defun REDUCER_START (/ *error* ActiveDoc Space OldClayer OldCmdEcho OldOsmode L
ineStart LineEnd
LineAngle TrunkSize ReducerStart SidePoint TrunkDirection FlatSidePoint ReducerA
ngle ReducerOutlet
ReducerInsul ReducerLength ReducerPt01 ReducerPt02 ReducerPt03 ReducerPt04 Reduc
erOutCenter
ReducerInsPt01 ReducerInsPt02 ReducerInsPt03 ReducerInsPt04 ReducerInsPt05
ReducerInsPt06 ReducerInsPt07 ReducerInsPt08 )
;;; Begin Error Handler -------------------------------------------------
(defun *error* (MSG)
(if (not (member MSG '("Function cancelled" "quit / exit abort")))
(princ (strcat "\n*** Program Error: " (strcase MSG) " ***"))
(princ "\n... Program Cancelled ...")
)
(while (< 0 (getvar "cmdactive"))
(command)
)
(REDUCER_RESET_ENV)
)
;;; End Error Handler ---------------------------------------------------
(REDUCER_SET_ENV)
)
;;; ------------ SET ENVIROMENT BEFORE LAUNCH
(defun REDUCER_SET_ENV(/)
(setq OldClayer (getvar "CLAYER"))
(setq OldCmdEcho (getvar "CMDECHO"))
(setq OldOsmode (getvar "OSMODE"))
(setvar "CMDECHO" 0)
(command "_undo" "begin")
(vl-load-com)
(setq ActiveDoc (vla-get-activedocument (vlax-get-acad-object)))
(setq Space
(if (= (getvar "cvport") 1)
(vla-get-paperspace ActiveDoc)
(vla-get-modelspace ActiveDoc)
)
)
;; Setup layer for centerline
(REDUCER_CREATE_LAYER "M-HVAC-CNTR" "Mechanical Plan - Ductwork centerline" "CEN
TER2" "25" "12" "0")
;; Setup layer for insulation
(REDUCER_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HID
DEN2" "15" "201" "1")
;; Run elbow
(REDUCER_RUN)
)
;;; ------------ RUN OFFSET SUB ROUTINE - GET VARIABLES
(defun REDUCER_RUN (/ TrunkLine EntList ReducerLayer ReducerTemp)
;; Get properties from current trunk line
(while (null (setq TrunkLine (car(nentsel "\n Select trunk to add offset to: "))
))
(princ "\n Duct not selected")
)
(setq EntList (entget TrunkLine))
(setq ReducerLayer (cdr (assoc 8 EntList)))
;; Set layer
(setvar "CLAYER" ReducerLayer)
;; Set reducer properties
(if (equal (cdr (assoc 0 EntList)) "LINE")
(progn
(setq LineStart (cdr (assoc 10 EntList)))
(setq LineEnd (cdr (assoc 11 EntList)))
(setq LineAngle (angle LineStart LineEnd))
(setq TrunkSize (distance LineStart LineEnd))
(setq ReducerStart (polar LineStart LineAngle (/ (distance LineStart LineEnd) 2)
))
)
(progn
(princ " Trunk must be a line. ")
(REDUCER_RUN)
)
)
;; Get reducer direction
(setq SidePoint (getpoint ReducerStart "\n Define reducer direction "))
(setq TrunkDirection (REDUCER_GET_PERP LineStart LineEnd SidePoint))
;; Get flat side
(setq ReducerTemp (polar ReducerStart TrunkDirection 12))
(setq FlatSidePoint (getpoint ReducerTemp "\n Define reducer flat side "))
(setq ReducerAngle(REDUCER_GET_PERP ReducerStart ReducerTemp FlatSidePoint))
;; Get reducer outlet size
(setq ReducerOutlet (- TrunkSize 2.0))
(initget 6)
(if (not(setq ReducerOutlet (getreal (strcat "\n Enter reducer outlet size: " ""
))))
(setq ReducerOutlet (- TrunkSize 2.0))
)
;; Get reducer insulation
(initget 1 "None Inside Outside Both")
(setq ReducerInsul (getkword "\n Insulation options: (None/Inside/Oustside/Both)
"))
;; Get reducer length
(setq ReducerLength (REDUCER_LAWOFSINE 15.0 75.0 (- TrunkSize ReducerOutlet) 0))
;; Create reducer
(REDUCER_CREATE ReducerInsul)
)
;;; ------------ CREATE REDUCER SUB ROUTINE
(defun REDUCER_CREATE (ReducerInsul / ReducerCntrLine01)
;; Create outside points
(setq ReducerPt01 (polar ReducerStart ReducerAngle (/ TrunkSize 2.0)))
(setq ReducerPt02 (polar ReducerStart (REDUCER_ADD_ANGLE ReducerAngle 180.0) (/
TrunkSize 2.0)))
(setq ReducerPt03 (polar ReducerPt01 TrunkDirection ReducerLength))
(setq ReducerPt04 (polar ReducerPt03 (REDUCER_ADD_ANGLE ReducerAngle 180.0) Redu
cerOutlet))
(setq ReducerOutCenter (polar ReducerPt03 (REDUCER_ADD_ANGLE ReducerAngle 180.0)
(/ ReducerOutlet 2.0)))
;; Create reducer
(vlax-invoke space 'addline ReducerPt01 ReducerPt02)
(vlax-invoke space 'addline ReducerPt01 ReducerPt03)
(vlax-invoke space 'addline ReducerPt03 ReducerPt04)
(vlax-invoke space 'addline ReducerPt02 ReducerPt04)
(setq ReducerCntrLine01 (vlax-invoke space 'addline ReducerStart ReducerOutCente
r))
;; Set reducer properties
(vlax-put ReducerCntrLine01 'Layer "M-HVAC-CNTR")
;; Set inside insulation points
(setq ReducerInsPt01 (polar ReducerPt01 (REDUCER_ADD_ANGLE ReducerAngle 180.0) 1
.0))
(setq ReducerInsPt02 (polar ReducerPt03 (REDUCER_ADD_ANGLE ReducerAngle 180.0) 1
.0))
(setq ReducerInsPt03 (polar ReducerPt02 ReducerAngle 1.0))
(setq ReducerInsPt04 (polar ReducerPt04 ReducerAngle 1.0))
;; Set inside insulation points
(setq ReducerInsPt05 (polar ReducerPt01 ReducerAngle 1.0))
(setq ReducerInsPt06 (polar ReducerPt03 ReducerAngle 1.0))
(setq ReducerInsPt07 (polar ReducerPt02 (REDUCER_ADD_ANGLE ReducerAngle 180.0) 1
.0))
(setq ReducerInsPt08 (polar ReducerPt04 (REDUCER_ADD_ANGLE ReducerAngle 180.0) 1
.0))
;; Set insulation layer
(setvar "CLAYER" "M-HVAC-INSL")
(cond
((= ReducerInsul "Inside")
(vlax-invoke space 'addline ReducerInsPt01 ReducerInsPt02)
(vlax-invoke space 'addline ReducerInsPt03 ReducerInsPt04)
)
((= ReducerInsul "Outside")
(vlax-invoke space 'addline ReducerInsPt05 ReducerInsPt06)
(vlax-invoke space 'addline ReducerInsPt07 ReducerInsPt08)
)
((= ReducerInsul "Both")
(vlax-invoke space 'addline ReducerInsPt01 ReducerInsPt02)
(vlax-invoke space 'addline ReducerInsPt03 ReducerInsPt04)
(vlax-invoke space 'addline ReducerInsPt05 ReducerInsPt06)
(vlax-invoke space 'addline ReducerInsPt07 ReducerInsPt08)
)
)
;; Reset environment
(REDUCER_RESET_ENV)
)
;;; ------------ LAYER CREATION ROUINE
(defun REDUCER_CREATE_LAYER (Layer Descpition Linetype Thickness Color Plot / Tm
pList VLA-Obj)
;; Check to see if linetype exsists
(if (= (tblsearch "ltype" Linetype) nil)
(if (REDUCER_CHECK_LINETYPE (findfile "acad.lin") Linetype)
(command "linetype" "load" Linetype "acad.lin" "")
(setq Linetype "Continuous")
)
)
;;; ------------ CREATE A LIST FOR ENTMAKE
(setq TmpList
(list
(cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 70 0)
)
)
;; Create layer name list
(setq TmpList (append TmpList (list (cons 2 Layer))))
;; Create layer color list
(setq TmpList (append TmpList (list (cons 62 (atoi Color)))))
;; Create layer linetype list
(setq TmpList (append TmpList (list (cons 6 Linetype))))
;; Create layer lineweight list
(setq TmpList (append TmpList (list (cons 370 (atoi Thickness)))))
;; Create layer plot list
(setq TmpList (append TmpList (list (cons 290 (atoi Plot)))))
;; Create layer from first item in the list
(entmake TmpList)
;; Create layer description
(if(or(= 16.1 (atof(getvar "acadver")))(< 16.1 (atof(getvar "acadver"))))
(progn
(setq VLA-Obj(vla-Add (vla-Get-Layers ActiveDoc)Layer))
(vla-Put-Description VLA-Obj Descpition)
(vlax-release-object VLA-Obj)
)
)
)
;;; ------------ CHECKS TO SEE IF A LINETYPE IS AVAILIBLE
(defun REDUCER_CHECK_LINETYPE (LINFile Linetype / OpenFile LineNumber CurrentLin
e Result)
(setq OpenFile (open LINFile "r"))
(while (setq CurrentLine (read-line OpenFile))
(if (wcmatch CurrentLine "`**")
(progn
(setq LinetypeName (substr(car(REDUCER_STRING_TO_LIST CurrentLine ","))2))
(if (= (strcase Linetype) LinetypeName)
(setq Result T)
)
)
)
)
(close OpenFile)
Result
)
;;; ------------ STRING TO LIST SUB ROUTINE
(defun REDUCER_STRING_TO_LIST (Stg Del / CurChr PosCnt TmpLst TmpStr)
(setq PosCnt 1
TmpStr ""
)
(repeat (1+ (strlen Stg))
(setq CurChr (substr Stg PosCnt 1))
(if (= CurChr Del)
(progn
(setq TmpLst (cons TmpStr TmpLst))
(setq TmpStr "")
)
(setq TmpStr (strcat TmpStr CurChr))
)
(setq PosCnt (1+ PosCnt))
)
(setq TmpLst (reverse TmpLst))
)
;;; ------------ ADD / SUBTRACT ANGLE SUB ROUTINES
(defun REDUCER_ADD_ANGLE (Radians AddAngle / )
(REDUCER_DTR(+ (REDUCER_RTD Radians) AddAngle))
)
(defun REDUCER_SUBTRACT_ANGLE (Radians AddAngle / )
(REDUCER_DTR(- (REDUCER_RTD Radians) AddAngle))
)
;;; ------------ LAW OF SINS (2 ANGLES & 1 SIDE)
(defun REDUCER_LAWOFSINE (SinAngle1 SinAngle2 Side1 Round / A SinA SinB Sideleng
th)
(setq SinA (sin (REDUCER_DTR SinAngle1)))
(setq SinB (sin (REDUCER_DTR SinAngle2)))
(if (= Round 1)
(setq SideLength (REDUCER_RND (/ (* Side1 SinB) SinA)4))
(setq SideLength (/ (* Side1 SinB) SinA))
)
Sidelength
)
;;; ------------ GET PERPENDICULAR POINT
(defun REDUCER_GET_PERP (StartPoint EndPoint Point / EntList LineStart LineEnd L
ineAngle PerpAngle)
(setq PerpStart (trans StartPoint 0 1))
(setq PerpEnd (trans EndPoint 0 1))
(setq PerpAngle (angle PerpStart PerpEnd))
(if (minusp (sin (- (angle PerpStart Point) PerpAngle))) ;determine direction
(setq NewAngle (- PerpAngle (/ pi 2))) ;if "below" -90 deg
(setq NewAngle (+ PerpAngle (/ pi 2))) ;or "above" +90 deg
)
NewAngle
)
;;; ------------ ROUND NUMBER
(defun REDUCER_RND (Number Precision)
(setq Number(distof (rtos Number 4 Precision)4))
)
;; ------------ DEGREES / RADIANS SUB ROUTINES
(defun REDUCER_DTR (NumberOfDegrees)
(* pi (/ NumberOfDegrees 180.0))
)
(defun REDUCER_RTD (NumberOfRadians)
(* 180.0 (/ NumberOfRadians pi))
)
;;; ------------ RESET SYSEM VARIABLES
(defun REDUCER_RESET_ENV (/)
(setvar "CMDECHO" OldCmdEcho)
(setvar "CLAYER" OldClayer)
(setvar "OSMODE" OldOsmode)
(command "_undo" "end")
(princ)
)
;;;
;;; Echos to the command line
(princ "\n CreateReducer v1.1 Timothy Spangler, \n January, 2007....loaded.")
(terpri)
(princ "C:REDUCER")
(print)
;;; End echo

;;; ------------------------------------------------------------------------
;;; CreateElbow.lsp v1.1
;;;
;;; Copyright January, 2007
;;; Timothy G. Spangler
;;;
;;; Permission to use, copy, modify, and distribute this software
;;; for any purpose and without fee is hereby granted, provided
;;; that the above copyright notice appears in all copies and
;;; that both that copyright notice and the limited warranty and
;;; restricted rights notice below appear in all supporting
;;; documentation.
;;;
;;; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;; WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;; PURPOSE AND OF MERCHANTIBILITY ARE HEREBY DISCLAIMED BY THE
;;; PROGRAMMER.
;;;
;;; -----------------------------------------------------------------------
;;; ------------ COMMAND LINE FUNCTIONS
(defun c:ELBOW (/)(ELBOW_START))
;;; ------------ MAIN FUNCTION
(defun ELBOW_START (/ *error* TrunkLine ElbowStart SidePoint EntList ElbowLayer
LineStart LineEnd LineAngle TrunkSize
TrunkDirection ElbowCorner MidPoint SidePoint2 ElbowDirection ElbowEnd ElbowCent
er ConnAngle MidAngle ElbowMid
ElbowChord ElbowRadius OldClayer OldCmdEcho OldOsmode)
;;; Begin Error Handler -------------------------------------------------
(defun *error* (MSG)
(if (not (member MSG '("Function cancelled" "quit / exit abort")))
(princ (strcat "\n*** Program Error: " (strcase MSG) " ***"))
(princ "\n... Program Cancelled ...")
)
(while (vla-object(entlast)))
;; Add centerline
(setq ElbowArc3 (car (vlax-invoke ElbowArc1 'offset (/ TrunkSize 2.0))))
(setq ElbowLine8 (vlax-invoke Space 'addline ElbowStart ElbowPoint11))
(setq ElbowLine9 (vlax-invoke Space 'addline ElbowEnd ElbowPoint12))
(vlax-put ElbowArc3 'Layer "M-HVAC-CNTR")
(vlax-put ElbowLine8 'Layer "M-HVAC-CNTR")
(vlax-put ElbowLine9 'Layer "M-HVAC-CNTR")
;; Add "vane" to elbow
(command "_measure" (vlax-vla-object->ename ElbowLine7) "block" BlockName "y" 2.
0)
;; Set properties for insulation
(vlax-put ElbowLine7 'Color 9)
(cond
((= (strcase ElbowInsul) "INSIDE")
(setq ElbowLine10
(vlax-invoke Space 'addline
(polar ElbowPoint2 ElbowDirection 1.0)
(polar (polar ElbowPoint6 ElbowDirection 1.0)(ELBOW_ADD_ANGLE TrunkDirection 180
) 1.0)
)
)
(setq ElbowLine11
(vlax-invoke Space 'addline
(polar ElbowPoint3 (ELBOW_ADD_ANGLE TrunkDirection 180) 1.0)
(polar (polar ElbowPoint6 (ELBOW_ADD_ANGLE TrunkDirection 180) 1.0)(ELBOW_ADD_AN
GLE ElbowDirection 180) -1.0)
)
)
(setq ElbowLine12
(vlax-invoke Space 'addline
(polar ElbowPoint1 (ELBOW_ADD_ANGLE ElbowDirection 180) 1.0)
(polar ElbowPoint7 (ELBOW_ADD_ANGLE ElbowDirection 180) 1.0)
)
)
(setq ElbowLine13
(vlax-invoke Space 'addline
(polar ElbowPoint4 TrunkDirection 1.0)
(polar ElbowPoint8 TrunkDirection 1.0)
)
)
(setq ElbowArc2 (car (vlax-invoke ElbowArc1 'offset 1)))
;; Set properties for insulation
(vlax-put ElbowLine10 'Layer "M-HVAC-INSL")
(vlax-put ElbowLine11 'Layer "M-HVAC-INSL")
(vlax-put ElbowLine12 'Layer "M-HVAC-INSL")
(vlax-put ElbowLine13 'Layer "M-HVAC-INSL")
(vlax-put ElbowArc2 'Layer "M-HVAC-INSL")
)
((= (strcase ElbowInsul) "OUTSIDE")
(setq ElbowLine14
(vlax-invoke Space 'addline
(polar ElbowPoint2 (ELBOW_ADD_ANGLE ElbowDirection 180) 1.0)
(polar (polar ElbowPoint6 (ELBOW_ADD_ANGLE ElbowDirection 180) 1.0)TrunkDirectio
n 1.0)
)
)
(setq ElbowLine15
(vlax-invoke Space 'addline
(polar ElbowPoint3 TrunkDirection 1.0)
(polar (polar ElbowPoint6 TrunkDirection 1.0)(ELBOW_ADD_ANGLE ElbowDirection 180
) 1.0)
)
)
(setq ElbowLine16
(vlax-invoke Space 'addline
(polar ElbowPoint1 ElbowDirection 1.0)
(polar ElbowPoint7 ElbowDirection 1.0)
)
)
(setq ElbowLine17
(vlax-invoke Space 'addline
(polar ElbowPoint4 (ELBOW_ADD_ANGLE TrunkDirection 180) 1.0)
(polar ElbowPoint8 (ELBOW_ADD_ANGLE TrunkDirection 180) 1.0)
)
)
(setq ElbowArc3 (car (vlax-invoke ElbowArc1 'offset -1)))
;; Set properties for insulation
(vlax-put ElbowLine14 'Layer "M-HVAC-INSL")
(vlax-put ElbowLine15 'Layer "M-HVAC-INSL")
(vlax-put ElbowLine16 'Layer "M-HVAC-INSL")
(vlax-put ElbowLine17 'Layer "M-HVAC-INSL")
(vlax-put ElbowArc3 'Layer "M-HVAC-INSL")
)
((= (strcase ElbowInsul) "BOTH")
(setq ElbowLine10
(vlax-invoke Space 'addline
(polar ElbowPoint2 ElbowDirection 1.0)
(polar (polar ElbowPoint6 ElbowDirection 1.0)(ELBOW_ADD_ANGLE TrunkDirection 180
) 1.0)
)
)
(setq ElbowLine11
(vlax-invoke Space 'addline
(polar ElbowPoint3 (ELBOW_ADD_ANGLE TrunkDirection 180) 1.0)
(polar (polar ElbowPoint6 (ELBOW_ADD_ANGLE TrunkDirection 180) 1.0)(ELBOW_ADD_AN
GLE ElbowDirection 180) -1.0)
)
)
(setq ElbowLine12
(vlax-invoke Space 'addline
(polar ElbowPoint1 (ELBOW_ADD_ANGLE ElbowDirection 180) 1.0)
(polar ElbowPoint7 (ELBOW_ADD_ANGLE ElbowDirection 180) 1.0)
)
)
(setq ElbowLine13
(vlax-invoke Space 'addline
(polar ElbowPoint4 TrunkDirection 1.0)
(polar ElbowPoint8 TrunkDirection 1.0)
)
)
(setq ElbowLine14
(vlax-invoke Space 'addline
(polar ElbowPoint2 (ELBOW_ADD_ANGLE ElbowDirection 180) 1.0)
(polar (polar ElbowPoint6 (ELBOW_ADD_ANGLE ElbowDirection 180) 1.0)TrunkDirectio
n 1.0)
)
)
(setq ElbowLine15
(vlax-invoke Space 'addline
(polar ElbowPoint3 TrunkDirection 1.0)
(polar (polar ElbowPoint6 TrunkDirection 1.0)(ELBOW_ADD_ANGLE ElbowDirection 180
) 1.0)
)
)
(setq ElbowLine16
(vlax-invoke Space 'addline
(polar ElbowPoint1 ElbowDirection 1.0)
(polar ElbowPoint7 ElbowDirection 1.0)
)
)
(setq ElbowLine17
(vlax-invoke Space 'addline
(polar ElbowPoint4 (ELBOW_ADD_ANGLE TrunkDirection 180) 1.0)
(polar ElbowPoint8 (ELBOW_ADD_ANGLE TrunkDirection 180) 1.0)
)
)
(setq ElbowArc2 (car (vlax-invoke ElbowArc1 'offset 1)))
(setq ElbowArc3 (car (vlax-invoke ElbowArc1 'offset -1)))
;; Set properties for insulation
(vlax-put ElbowLine10 'Layer "M-HVAC-INSL")
(vlax-put ElbowLine11 'Layer "M-HVAC-INSL")
(vlax-put ElbowLine12 'Layer "M-HVAC-INSL")
(vlax-put ElbowLine13 'Layer "M-HVAC-INSL")
(vlax-put ElbowArc2 'Layer "M-HVAC-INSL")
(vlax-put ElbowLine14 'Layer "M-HVAC-INSL")
(vlax-put ElbowLine15 'Layer "M-HVAC-INSL")
(vlax-put ElbowLine16 'Layer "M-HVAC-INSL")
(vlax-put ElbowLine17 'Layer "M-HVAC-INSL")
(vlax-put ElbowArc3 'Layer "M-HVAC-INSL")
)
)
;; Reset envireonment
(ELBOW_RESET_ENV)
)
;;;;;;;;;;;;
;;;;;;;;;;;;;;;;
(defun ELBOW_RAD (ElbowInsul / ElbowPoint1 ElbowPoint2 ElbowPoint3 ElbowPoint4 E
lbowLine1 ElbowLine2 ElbowLine3
ElbowLine4 ElbowLine5 ElbowLine6 ElbowLine7 ElbowLine8 ElbowCenterLine)
;; Get elbow outer points
(setq ElbowPoint1 (polar ElbowStart ElbowDirection (/ TrunkSize 2)))
(setq ElbowPoint2 (polar ElbowStart (ELBOW_ADD_ANGLE ElbowDirection 180)(/ Trunk
Size 2)))
(setq ElbowPoint3 (polar ElbowEnd TrunkDirection (/ TrunkSize 2)))
(setq ElbowPoint4 (polar ElbowEnd (ELBOW_ADD_ANGLE TrunkDirection 180)(/ TrunkSi
ze 2)))
;; Draw Elbow
(setq ElbowLine1 (vlax-invoke Space 'addline ElbowPoint1 ElbowPoint2))
(setq ElbowLine2 (vlax-invoke Space 'addline ElbowPoint3 ElbowPoint4))
(command "_arc" ElbowStart ElbowMid ElbowEnd)
(setq ElbowCenterLine (vlax-ename->vla-object(entlast)))
(setq ElbowLine3 (car (vlax-invoke ElbowCenterLine 'offset (atof(strcat "-"(rtos
(/ TrunkSize 2)5 2))))))
(setq ElbowLine4 (car (vlax-invoke ElbowCenterLine 'offset (/ TrunkSize 2))))
;; Set properties for centerline
(vlax-put ElbowCenterLine 'Layer "M-HVAC-CNTR")
(cond
((= (strcase ElbowInsul) "INSIDE")
(setq ElbowLine5 (car (vlax-invoke ElbowLine3 'offset 1)))
(setq ElbowLine6 (car (vlax-invoke ElbowLine4 'offset -1)))
;; Set properties for insulation
(vlax-put ElbowLine5 'Layer "M-HVAC-INSL")
(vlax-put ElbowLine6 'Layer "M-HVAC-INSL")
)
((= (strcase ElbowInsul) "OUTSIDE")
(setq ElbowLine7 (car (vlax-invoke ElbowLine3 'offset -1)))
(setq ElbowLine8 (car (vlax-invoke ElbowLine4 'offset 1)))
;; Set properties for insulation
(vlax-put ElbowLine7 'Layer "M-HVAC-INSL")
(vlax-put ElbowLine8 'Layer "M-HVAC-INSL")
)
((= (strcase ElbowInsul) "BOTH")
(setq ElbowLine5 (car (vlax-invoke ElbowLine3 'offset 1)))
(setq ElbowLine6 (car (vlax-invoke ElbowLine4 'offset -1)))
(setq ElbowLine7 (car (vlax-invoke ElbowLine3 'offset -1)))
(setq ElbowLine8 (car (vlax-invoke ElbowLine4 'offset 1)))
;; Set properties for insulation
(vlax-put ElbowLine5 'Layer "M-HVAC-INSL")
(vlax-put ElbowLine6 'Layer "M-HVAC-INSL")
(vlax-put ElbowLine7 'Layer "M-HVAC-INSL")
(vlax-put ElbowLine8 'Layer "M-HVAC-INSL")
)
)
;; Reset envireonment
(ELBOW_RESET_ENV)
)
;;; ------------ CREATE VANE BLOCK SUB - DOES NOT INSERT BLOCK
(defun ELBOW_VANE_BLOCK (/)
(setq OldLunits (getvar "LUNITS"))
(setq OldLuPrec (getvar "LUPREC"))
(setvar "LUNITS" 2)
(setvar "LUPREC" 1)
(setq BlockName "VANE")
(if (= (tblsearch "block" BlockName) nil)
(progn
(entmake
(list
(cons 0 "BLOCK")
(cons 2 BlockName)
(cons 70 64)
(cons 10 (list 0.0 0.0 0.0))
(cons 8 "0")
)
)
(entmake
(list
(cons 0 "ARC")
(cons 10 (list 2.0 0.0 0.0))
(cons 40 2.0)
(cons 50 2.74889)
(cons 51 3.53429)
(cons 8 "0")
(cons 62 9)
)
)
(entmake
'((0 . "ENDBLK"))
)
)
)
(setvar "LUNITS" OldLunits)
(setvar "LUPREC" OldLuPrec)
BlockName
)
;;; ------------ LAYER CREATION ROUINE
(defun ELBOW_CREATE_LAYER (Layer Descpition Linetype Thickness Color Plot / TmpL
ist VLA-Obj)
;; Check to see if linetype exsists
(if (= (tblsearch "ltype" Linetype) nil)
(if (ELBOW_CHECK_LINETYPE (findfile "acad.lin") Linetype)
(command "linetype" "load" Linetype "acad.lin" "")
(setq Linetype "Continuous")
)
)
;;; ------------ CREATE A LIST FOR ENTMAKE
(setq TmpList
(list
(cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 70 0)
)
)
;; Create layer name list
(setq TmpList (append TmpList (list (cons 2 Layer))))
;; Create layer color list
(setq TmpList (append TmpList (list (cons 62 (atoi Color)))))
;; Create layer linetype list
(setq TmpList (append TmpList (list (cons 6 Linetype))))
;; Create layer lineweight list
(setq TmpList (append TmpList (list (cons 370 (atoi Thickness)))))
;; Create layer plot list
(setq TmpList (append TmpList (list (cons 290 (atoi Plot)))))
;; Create layer from first item in the list
(entmake TmpList)
;; Create layer description
(if(or(= 16.1 (atof(getvar "acadver")))(< 16.1 (atof(getvar "acadver"))))
(progn
(setq VLA-Obj(vla-Add (vla-Get-Layers ActiveDoc)Layer))
(vla-Put-Description VLA-Obj Descpition)
(vlax-release-object VLA-Obj)
)
)
)
;;; ------------ CHECKS TO SEE IF A LINETYPE IS AVAILIBLE
(defun ELBOW_CHECK_LINETYPE (LINFile Linetype / OpenFile LineNumber CurrentLine
Result)
(setq OpenFile (open LINFile "r"))
(while (setq CurrentLine (read-line OpenFile))
(if (wcmatch CurrentLine "`**")
(progn
(setq LinetypeName (substr(car(ELBOW_STRING_TO_LSIT CurrentLine ","))2))
(if (= (strcase Linetype) LinetypeName)
(setq Result T)
)
)
)
)
(close OpenFile)
Result
)
;;; ------------ STRING TO LIST SUB ROUTINE
(defun ELBOW_STRING_TO_LSIT (Stg Del / CurChr PosCnt TmpLst TmpStr)
(setq PosCnt 1
TmpStr ""
)
(repeat (1+ (strlen Stg))
(setq CurChr (substr Stg PosCnt 1))
(if (= CurChr Del)
(progn
(setq TmpLst (cons TmpStr TmpLst))
(setq TmpStr "")
)
(setq TmpStr (strcat TmpStr CurChr))
)
(setq PosCnt (1+ PosCnt))
)
(setq TmpLst (reverse TmpLst))
)
;; ------------ DEGREES / RADIANS SUB ROUTINES
(defun ELBOW_DTR (NumberOfDegrees)
(* pi (/ NumberOfDegrees 180.0))
)
(defun ELBOW_RTD (NumberOfRadians)
(* 180.0 (/ NumberOfRadians pi))
)
;;; ------------ ROUND NUMBER
(defun ELBOW_RND (Number Precision)
(setq Number(distof (rtos Number 4 Precision)4))
)
;;; ------------ LAW OF SINS (2 ANGLES & 1 SIDE)
(defun ELBOW_LAWOFSINE (SinAngle1 SinAngle2 Side1 / A SinA SinB Sidelength)
(setq SinA (sin (ELBOW_DTR SinAngle1)))
(setq SinB (sin (ELBOW_DTR SinAngle2)))
(setq SideLength (ELBOW_RND (/ (* Side1 SinB) SinA)4))
Sidelength
)
;;; ------------ ADD / SUBTRACT ANGLE SUB ROUTINES
(defun ELBOW_ADD_ANGLE (Radians AddAngle / )
(ELBOW_DTR(+ (ELBOW_RTD Radians) AddAngle))
)
(defun ELBOW_SUBTRACT_ANGLE (Radians AddAngle / )
(ELBOW_DTR(- (ELBOW_RTD Radians) AddAngle))
)
;;; ------------ GET RADIUS OF ARC (CHORD LENGTH & CHORD HEIGHT KNOWN)
(defun ELBOW_GET_RADIUS (ChordLength ChordHeight / Radius)
(setq Radius (/(+(expt ChordHeight 2)(/ (expt ChordLength 2)4))(* ChordHeight 2)
))
Radius
)
(defun ELBOW_GET_HEIGHT (Chord Radius / Height)
(setq Height (- Radius (sqrt(-(expt Radius 2)(expt(/ Chord 2)2)))))
Height
)
;;; ------------ GET PERPENDICULAR POINT
(defun ELBOW_GET_PERP (StartPoint EndPoint Point / EntList LineStart LineEnd Lin
eAngle PerpAngle)
(setq PerpStart (trans StartPoint 0 1))
(setq PerpEnd (trans EndPoint 0 1))
(setq PerpAngle (angle PerpStart PerpEnd))
(if (minusp (sin (- (angle PerpStart Point) PerpAngle))) ;determine direction
(setq NewAngle (- PerpAngle (/ pi 2))) ;if "below" -90 deg
(setq NewAngle (+ PerpAngle (/ pi 2))) ;or "above" +90 deg
)
NewAngle
)
;;; ------------ RESET SYSEM VARIABLES
(defun ELBOW_RESET_ENV (/)
(setvar "CMDECHO" OldCmdEcho)
(setvar "CLAYER" OldClayer)
(setvar "OSMODE" OldOsmode)
(command "_undo" "end")
(princ)
)
;;;
;;; Echos to the command line
(princ "\n CreateElbow v1.1 Timothy Spangler, \n January, 2007....loaded.")
(terpri)
(princ "C:ELBOW")
(print)
;;; End echo

;;; ------------------------------------------------------------------------
;;; CreateDiffuser.lsp v1.1
;;;
;;; Copyright January, 2007
;;; Timothy G. Spangler
;;;
;;; Permission to use, copy, modify, and distribute this software
;;; for any purpose and without fee is hereby granted, provided
;;; that the above copyright notice appears in all copies and
;;; that both that copyright notice and the limited warranty and
;;; restricted rights notice below appear in all supporting
;;; documentation.
;;;
;;; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;; WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;; PURPOSE AND OF MERCHANTIBILITY ARE HEREBY DISCLAIMED BY THE
;;; PROGRAMMER.
;;;
;;; -----------------------------------------------------------------------
;;; ------------ COMMAND LINE FUNCTIONS
(defun c:DIFF (/) (DIFF_START))
;;; ------------ MAIN FUNCTION
(defun DIFF_START ( / *error* Angle+90 Angle-90 ActiveDoc TransAlign DuctAgnle D
uctHeight DuctWidth DuctStyle TransType OldClayer OldCmdEcho Space)
;;; Begin Error Handler -------------------------------------------------
(defun *error* (MSG)
(if (not (member MSG '("Function cancelled" "quit / exit abort")))
(princ (strcat "\n*** Program Error: " (strcase MSG) " ***"))
(princ "\n... Program Cancelled ...")
)
(while (< 0 (getvar "cmdactive"))
(command)
)
(princ)
)
;;; End Error Handler ---------------------------------------------------
(DIFF_SET_ENV)
)
;;; ------------ GET VARIABLES FOR DIFFUSER CREATION
(defun DIFF_RUN (/)
(initget "Supply s S Return r R Exhaust e E")
(setq DiffStyle (getkword "Enter diffuser style: (Supply/Return/Exhaust)"))
(initget "Lay-In l L Mounted m M")
(setq DiffType (getkword "Enter diffuser type: (Lay-In/Mounted)"))
(initget "Square s S Round r R")
(setq DiffShape (getkword "Enter diffuser Shape: (Square/Round)"))
(if (= (strcase DiffShape) "SQUARE")
(progn
(setq DiffWidth (getreal "\n Enter diffuser width: (12\")"))
(if (not DiffWidth)
(setq DiffWidth 12.0)
)
(if (< DiffWidth 12)
(setq DiffWidth (getreal "\n Enter diffuser width: \n -Must be greater than 12\"
- "))
)
(setq DiffLength (getreal "\n Enter diffuser length: (12\")"))
(if (not DiffLength)
(setq DiffLength 12.0)
)
(if (< DiffLength 12)
(setq DiffLength (getreal "\n Enter diffuser length: \n -Must be greater than 12
\"- "))
)
)
(progn
(setq DiffWidth (getreal "\n Enter diffuser diameter: (12\")"))
(if (not DiffWidth)
(setq DiffWidth 12.0)
)
(if (< DiffWidth 12)
(setq DiffWidth (getreal "\n Enter diffuser diameter: \n -Must be greater than 1
2\"- "))
)
)
)
(if(not(setq DiffInlet (getreal "Enter diffuser inlet size: (6\")")))
(setq DiffInlet 6.0)
)
(while(null(setq InsPoint (getpoint " Define insertion point: ")))
(princ "-Point not defined-")
)
(cond
((= (strcase DiffType) "LAY-IN")
(if(= (strcase DiffShape) "SQUARE")
(DIFF_LAYIN_SQUARE InsPoint DiffWidth DiffLength DiffInlet)
(DIFF_LAYIN_ROUND InsPoint DiffWidth DiffInlet)
)
)
((= (strcase DiffType) "MOUNTED")
(if(= (strcase DiffShape) "SQUARE")
(DIFF_MOUNTED_SQUARE InsPoint DiffWidth DiffLength DiffInlet)
(DIFF_MOUNTED_ROUND InsPoint DiffWidth DiffInlet)
)
)
)
(princ)
)
;;; ------------ LAYER CREATION ROUINE
(defun DIFF_CREATE_LAYER (Layer Descpition Linetype Thickness Color Plot / TmpLi
st VLA-Obj)
;; Check to see if linetype exsists
(if (= (tblsearch "ltype" Linetype) nil)
(if (DIFF_CHECK_LINETYPE (findfile "acad.lin") Linetype)
(command "linetype" "load" Linetype "acad.lin" "")
(setq Linetype "Continuous")
)
)
;;; ------------ CREATE A LIST FOR ENTMAKE
(setq TmpList
(list
(cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 70 0)
)
)
;; Create layer name list
(setq TmpList (append TmpList (list (cons 2 Layer))))
;; Create layer color list
(setq TmpList (append TmpList (list (cons 62 (atoi Color)))))
;; Create layer linetype list
(setq TmpList (append TmpList (list (cons 6 Linetype))))
;; Create layer lineweight list
(setq TmpList (append TmpList (list (cons 370 (atoi Thickness)))))
;; Create layer plot list
(setq TmpList (append TmpList (list (cons 290 (atoi Plot)))))
;; Create layer from first item in the list
(entmake TmpList)
;; Create layer description
(if(or(= 16.1 (atof(getvar "acadver")))(< 16.1 (atof(getvar "acadver"))))
(progn
(setq VLA-Obj(vla-Add (vla-Get-Layers ActiveDoc)Layer))
(vla-Put-Description VLA-Obj Descpition)
(vlax-release-object VLA-Obj)
)
)
)
;;; ------------ CHECKS TO SEE IF A LINETYPE IS AVAILIBLE
(defun DIFF_CHECK_LINETYPE (LINFile Linetype / OpenFile LineNumber CurrentLine R
esult)
(setq OpenFile (open LINFile "r"))
(while (setq CurrentLine (read-line OpenFile))
(if (wcmatch CurrentLine "`**")
(progn
(setq LinetypeName (substr(car(DIFF_STRING_TO_LIST CurrentLine ","))2))
(if (= (strcase Linetype) LinetypeName)
(setq Result T)
)
)
)
)
(close OpenFile)
Result
)
;;; ------------ STRING TO LIST SUB ROUTINE
(defun DIFF_STRING_TO_LIST (Stg Del / CurChr PosCnt TmpLst TmpStr)
(setq PosCnt 1
TmpStr ""
)
(repeat (1+ (strlen Stg))
(setq CurChr (substr Stg PosCnt 1))
(if (= CurChr Del)
(progn
(setq TmpLst (cons TmpStr TmpLst))
(setq TmpStr "")
)
(setq TmpStr (strcat TmpStr CurChr))
)
(setq PosCnt (1+ PosCnt))
)
(setq TmpLst (reverse TmpLst))
)
;;; ------------ CREATE LAY-IN SQUARE DIFFUSER
(defun DIFF_LAYIN_SQUARE(InsPoint DiffWidth DiffLength DiffInlet /
DiffPointList DiffPoints ExhsPointList RtrnPointList Stop Counter TempPoint vlaD
iffuser Ang StopPoint VlaLine VlaCircle)
(cond
((= (strcase DiffStyle)"SUPPLY")
;; Create the layer for the diffuser
(DIFF_CREATE_LAYER "M-DIFF-SUPP" "Mechanical Plan - Supply diffusers, register a
nd grilles" "Continuous" "35" "133" "1")
;; Get the outside points from the insertion point
(setq DiffPointList(DIFF_GET_POINTS InsPoint DiffWidth DiffLength))
;; Create list of 2D point from DiffPointList
(setq Stop (length DiffPointList))
(setq Counter 0)
(while (/= Counter Stop)
(setq TempPoint(reverse(cdr(reverse (nth Counter DiffPointList)))))
(setq DiffPoints (append TempPoint DiffPoints))
(setq Counter (1+ Counter))
)
;; Draw the outside of the diffuser from the 2D points
(setq vlaDiffuser (vla-addLightweightPolyline Space
(vlax-safearray-fill
(vlax-make-safearray vlax-vbDouble (cons 0 (- (length DiffPoints) 1)))
DiffPoints))
)
;; Close the polyline
(vla-put-closed vlaDiffuser :vlax-true)
;; Offset the polyline for the layin edge
(setq DiffLayIn (car(vlax-invoke vlaDiffuser 'Offset 1)))
;; Draw line to show it is a supply diffuser
(foreach X DiffPointList
(setq Ang (angle InsPoint X))
(setq StopPoint (polar X Ang (-(/ DiffInlet 2)(distance InsPoint X))))
(setq VlaLine (vlax-invoke space 'AddLine X StopPoint))
;; Set properties
(vlax-put VlaLine 'Layer "M-DIFF-SUPP")
)
;; Draw the center inlet
(setq VlaCircle (vlax-invoke space 'AddCircle InsPoint (/ DiffInlet 2)))
;; Set the properties on the newly created objects
(vlax-put vlaDiffuser 'Layer "M-DIFF-SUPP")
(vlax-put VlaCircle 'Layer "M-DIFF-SUPP")
(vlax-put DiffLayIn 'Layer "M-DIFF-SUPP")
(vlax-put DiffLayIn 'Color "8")
;; Silent exit
(princ)
)
((= (strcase DiffStyle)"RETURN")
;; Create the layer for the diffuser
(DIFF_CREATE_LAYER "M-DIFF-RETN" "Mechanical Plan - Return diffusers, register a
nd grilles" "Continuous" "35" "23" "1")
;; Get the outside points from the insertion point
(setq DiffPointList(DIFF_GET_POINTS InsPoint DiffWidth DiffLength))
(setq RtrnPointList (list (nth 0 DiffPointList)(nth 2 DiffPointList)))
;; Create list of 2D point from DiffPointList
(setq Stop (length DiffPointList))
(setq Counter 0)
(while (/= Counter Stop)
(setq TempPoint(reverse(cdr(reverse (nth Counter DiffPointList)))))
(setq DiffPoints (append TempPoint DiffPoints))
(setq Counter (1+ Counter))
)
;; Draw the outside of the diffuser from the 2D points
(setq vlaDiffuser (vla-addLightweightPolyline Space
(vlax-safearray-fill
(vlax-make-safearray vlax-vbDouble (cons 0 (- (length DiffPoints) 1)))
DiffPoints))
)
;; Close the polyline
(vla-put-closed vlaDiffuser :vlax-true)
;; Offset the polyline for the layin edge
(setq DiffLayIn (car(vlax-invoke vlaDiffuser 'Offset 1)))
;; Draw line to show it is a return diffuser
(foreach X RtrnPointList
(setq Ang (angle InsPoint X))
(setq StopPoint (polar X Ang (-(/ DiffInlet 2)(distance InsPoint X))))
(setq VlaLine (vlax-invoke space 'AddLine X StopPoint))
;; Set properties
(vlax-put VlaLine 'Layer "M-DIFF-RETN")
)
;; Draw the center inlet
(setq VlaCircle (vlax-invoke space 'AddCircle InsPoint (/ DiffInlet 2)))
;; Set the properties on the newly created objects
(vlax-put vlaDiffuser 'Layer "M-DIFF-RETN")
(vlax-put VlaCircle 'Layer "M-DIFF-RETN")
(vlax-put DiffLayIn 'Layer "M-DIFF-RETN")
(vlax-put DiffLayIn 'Color "8")
;; Silent exit
(princ)
)
((= (strcase DiffStyle)"EXHAUST")
;; Create the layer for the diffuser
(DIFF_CREATE_LAYER "M-DIFF-EXHS" "Mechanical Plan - Exhaust diffusers, register
and grilles" "Continuous" "35" "83" "1")
;; Get the outside points from the insertion point
(setq DiffPointList(DIFF_GET_POINTS InsPoint DiffWidth DiffLength))
(setq ExhsPointList (list (nth 0 DiffPointList)(nth 1 DiffPointList)(nth 2 DiffP
ointList)))
;; Create list of 2D point from DiffPointList
(setq Stop (length DiffPointList))
(setq Counter 0)
(while (/= Counter Stop)
(setq TempPoint(reverse(cdr(reverse (nth Counter DiffPointList)))))
(setq DiffPoints (append TempPoint DiffPoints))
(setq Counter (1+ Counter))
)
;; Draw the outside of the diffuser from the 2D points
(setq vlaDiffuser (vla-addLightweightPolyline Space
(vlax-safearray-fill
(vlax-make-safearray vlax-vbDouble (cons 0 (- (length DiffPoints) 1)))
DiffPoints))
)
;; Close the polyline
(vla-put-closed vlaDiffuser :vlax-true)
;; Offset the polyline for the layin edge
(setq DiffLayIn (car(vlax-invoke vlaDiffuser 'Offset 1)))
;; Draw line to show it is a supply diffuser
(foreach X ExhsPointList
(setq Ang (angle InsPoint X))
(setq StopPoint (polar X Ang (-(/ DiffInlet 2)(distance InsPoint X))))
(setq VlaLine (vlax-invoke space 'AddLine X StopPoint))
;; Set properties
(vlax-put VlaLine 'Layer "M-DIFF-EXHS")
)
;; Draw the center inlet
(setq VlaCircle (vlax-invoke space 'AddCircle InsPoint (/ DiffInlet 2)))
;; Set the properties on the newly created objects
(vlax-put vlaDiffuser 'Layer "M-DIFF-EXHS")
(vlax-put VlaCircle 'Layer "M-DIFF-EXHS")
(vlax-put DiffLayIn 'Layer "M-DIFF-EXHS")
(vlax-put DiffLayIn 'Color "8")
;; Silent exit
(princ)
)
)
(DIFF_RESET_ENV)
)
;;; ------------ CREATE LAY-IN SQUARE ROUND
(defun DIFF_LAYIN_ROUND(InsPoint DiffWidth DiffInlet /
DiffPointList DiffPoints ExhsPointList RtrnPointList Stop Counter TempPoint vlaD
iffuser Ang StopPoint VlaLine VlaCircle)
(cond
((= (strcase DiffStyle)"SUPPLY")
;; Create the layer for the diffuser
(DIFF_CREATE_LAYER "M-DIFF-SUPP" "Mechanical Plan - Supply diffusers, register a
nd grilles" "Continuous" "35" "133" "1")
;; Get the outside points from the insertion point
(setq DiffPointList(DIFF_GET_POINTS InsPoint (DIFF_INSCRIBE_SQUARE DiffWidth)(DI
FF_INSCRIBE_SQUARE DiffWidth)))
;; Create list of 2D point from DiffPointList
(setq Stop (length DiffPointList))
(setq Counter 0)
(while (/= Counter Stop)
(setq TempPoint(reverse(cdr(reverse (nth Counter DiffPointList)))))
(setq DiffPoints (append TempPoint DiffPoints))
(setq Counter (1+ Counter))
)
;; Draw the center inlet
(setq vlaDiffuser (vlax-invoke space 'AddCircle InsPoint (/ DiffWidth 2)))
;; Offset the polyline for the layin edge
(setq DiffLayIn (car(vlax-invoke vlaDiffuser 'Offset -1)))
;; Draw line to show it is a supply diffuser
(foreach X DiffPointList
(setq Ang (angle InsPoint X))
(setq StopPoint (polar X Ang (-(/ DiffInlet 2)(distance InsPoint X))))
(setq VlaLine (vlax-invoke space 'AddLine X StopPoint))
;; Set properties
(vlax-put VlaLine 'Layer "M-DIFF-SUPP")
)
;; Draw the center inlet
(setq VlaCircle (vlax-invoke space 'AddCircle InsPoint (/ DiffInlet 2)))
;; Set the properties on the newly created objects
(vlax-put vlaDiffuser 'Layer "M-DIFF-SUPP")
(vlax-put VlaCircle 'Layer "M-DIFF-SUPP")
(vlax-put DiffLayIn 'Layer "M-DIFF-SUPP")
(vlax-put DiffLayIn 'Color "8")
;; Silent exit
(princ)
)
((= (strcase DiffStyle)"RETURN")
;; Create the layer for the diffuser
(DIFF_CREATE_LAYER "M-DIFF-RETN" "Mechanical Plan - Return diffusers, register a
nd grilles" "Continuous" "35" "23" "1")
;; Get the outside points from the insertion point
(setq DiffPointList(DIFF_GET_POINTS InsPoint (DIFF_INSCRIBE_SQUARE DiffWidth)(DI
FF_INSCRIBE_SQUARE DiffWidth)))
(setq RtrnPointList (list (nth 0 DiffPointList)(nth 2 DiffPointList)))
;; Create list of 2D point from DiffPointList
(setq Stop (length DiffPointList))
(setq Counter 0)
(while (/= Counter Stop)
(setq TempPoint(reverse(cdr(reverse (nth Counter DiffPointList)))))
(setq DiffPoints (append TempPoint DiffPoints))
(setq Counter (1+ Counter))
)
;; Draw the outside of the diffuser from the 2D points
(setq vlaDiffuser (vlax-invoke space 'AddCircle InsPoint (/ DiffWidth 2)))
;; Offset the polyline for the layin edge
(setq DiffLayIn (car(vlax-invoke vlaDiffuser 'Offset -1)))
;; Draw line to show it is a return diffuser
(foreach X RtrnPointList
(setq Ang (angle InsPoint X))
(setq StopPoint (polar X Ang (-(/ DiffInlet 2)(distance InsPoint X))))
(setq VlaLine (vlax-invoke space 'AddLine X StopPoint))
;; Set properties
(vlax-put VlaLine 'Layer "M-DIFF-RETN")
)
;; Draw the center inlet
(setq VlaCircle (vlax-invoke space 'AddCircle InsPoint (/ DiffInlet 2)))
;; Set the properties on the newly created objects
(vlax-put vlaDiffuser 'Layer "M-DIFF-RETN")
(vlax-put VlaCircle 'Layer "M-DIFF-RETN")
(vlax-put DiffLayIn 'Layer "M-DIFF-RETN")
(vlax-put DiffLayIn 'Color "8")
;; Silent exit
(princ)
)
((= (strcase DiffStyle)"EXHAUST")
;; Create the layer for the diffuser
(DIFF_CREATE_LAYER "M-DIFF-EXHS" "Mechanical Plan - Exhaust diffusers, register
and grilles" "Continuous" "35" "83" "1")
;; Get the outside points from the insertion point
(setq DiffPointList (DIFF_GET_POINTS InsPoint (DIFF_INSCRIBE_SQUARE DiffWidth)(D
IFF_INSCRIBE_SQUARE DiffWidth)))
(setq ExhsPointList (list (nth 0 DiffPointList)(nth 1 DiffPointList)(nth 2 DiffP
ointList)))
;; Create list of 2D point from DiffPointList
(setq Stop (length DiffPointList))
(setq Counter 0)
(while (/= Counter Stop)
(setq TempPoint(reverse(cdr(reverse (nth Counter DiffPointList)))))
(setq DiffPoints (append TempPoint DiffPoints))
(setq Counter (1+ Counter))
)
;; Draw the outside of the diffuser from the 2D points
(setq vlaDiffuser (vlax-invoke space 'AddCircle InsPoint (/ DiffWidth 2)))
;; Offset the polyline for the layin edge
(setq DiffLayIn (car(vlax-invoke vlaDiffuser 'Offset -1)))
;; Draw line to show it is a supply diffuser
(foreach X ExhsPointList
(setq Ang (angle InsPoint X))
(setq StopPoint (polar X Ang (-(/ DiffInlet 2)(distance InsPoint X))))
(setq VlaLine (vlax-invoke space 'AddLine X StopPoint))
;; Set properties
(vlax-put VlaLine 'Layer "M-DIFF-EXHS")
)
;; Draw the center inlet
(setq VlaCircle (vlax-invoke space 'AddCircle InsPoint (/ DiffInlet 2)))
;; Set the properties on the newly created objects
(vlax-put vlaDiffuser 'Layer "M-DIFF-EXHS")
(vlax-put VlaCircle 'Layer "M-DIFF-EXHS")
(vlax-put DiffLayIn 'Layer "M-DIFF-EXHS")
(vlax-put DiffLayIn 'Color "8")
;; Silent exit
(princ)
)
)
(DIFF_RESET_ENV)
)
;;; ------------ CREATE MOUNTED SQUARE DIFFUSER
(defun DIFF_MOUNTED_SQUARE(InsPoint DiffWidth DiffLength DiffInlet /
DiffPointList DiffPoints ExhsPointList RtrnPointList Stop Counter TempPoint vlaD
iffuser Ang StopPoint VlaLine VlaCircle)
(cond
((= (strcase DiffStyle)"SUPPLY")
;; Create the layer for the diffuser
(DIFF_CREATE_LAYER "M-DIFF-SUPP" "Mechanical Plan - Supply diffusers, register a
nd grilles" "Continuous" "35" "133" "1")
;; Get the outside points from the insertion point
(setq DiffPointList(DIFF_GET_POINTS InsPoint DiffWidth DiffLength))
;; Create list of 2D point from DiffPointList
(setq Stop (length DiffPointList))
(setq Counter 0)
(while (/= Counter Stop)
(setq TempPoint(reverse(cdr(reverse (nth Counter DiffPointList)))))
(setq DiffPoints (append TempPoint DiffPoints))
(setq Counter (1+ Counter))
)
;; Draw the outside of the diffuser from the 2D points
(setq vlaDiffuser (vla-addLightweightPolyline Space
(vlax-safearray-fill
(vlax-make-safearray vlax-vbDouble (cons 0 (- (length DiffPoints) 1)))
DiffPoints))
)
;; Close the polyline
(vla-put-closed vlaDiffuser :vlax-true)
;; Draw line to show it is a supply diffuser
(foreach X DiffPointList
(setq Ang (angle InsPoint X))
(setq StopPoint (polar X Ang (-(/ DiffInlet 2)(distance InsPoint X))))
(setq VlaLine (vlax-invoke space 'AddLine X StopPoint))
;; Set properties
(vlax-put VlaLine 'Layer "M-DIFF-SUPP")
)
;; Draw the center inlet
(setq VlaCircle (vlax-invoke space 'AddCircle InsPoint (/ DiffInlet 2)))
;; Set the properties on the newly created objects
(vlax-put vlaDiffuser 'Layer "M-DIFF-SUPP")
(vlax-put VlaCircle 'Layer "M-DIFF-SUPP")
;; Silent exit
(princ)
)
((= (strcase DiffStyle)"RETURN")
;; Create the layer for the diffuser
(DIFF_CREATE_LAYER "M-DIFF-RETN" "Mechanical Plan - Return diffusers, register a
nd grilles" "Continuous" "35" "23" "1")
;; Get the outside points from the insertion point
(setq DiffPointList(DIFF_GET_POINTS InsPoint DiffWidth DiffLength))
(setq RtrnPointList (list (nth 0 DiffPointList)(nth 2 DiffPointList)))
;; Create list of 2D point from DiffPointList
(setq Stop (length DiffPointList))
(setq Counter 0)
(while (/= Counter Stop)
(setq TempPoint(reverse(cdr(reverse (nth Counter DiffPointList)))))
(setq DiffPoints (append TempPoint DiffPoints))
(setq Counter (1+ Counter))
)
;; Draw the outside of the diffuser from the 2D points
(setq vlaDiffuser (vla-addLightweightPolyline Space
(vlax-safearray-fill
(vlax-make-safearray vlax-vbDouble (cons 0 (- (length DiffPoints) 1)))
DiffPoints))
)
;; Close the polyline
(vla-put-closed vlaDiffuser :vlax-true)
;; Draw line to show it is a supply diffuser
(foreach X RtrnPointList
(setq Ang (angle InsPoint X))
(setq StopPoint (polar X Ang (-(/ DiffInlet 2)(distance InsPoint X))))
(setq VlaLine (vlax-invoke space 'AddLine X StopPoint))
;; Set properties
(vlax-put VlaLine 'Layer "M-DIFF-RETN")
)
;; Draw the center inlet
(setq VlaCircle (vlax-invoke space 'AddCircle InsPoint (/ DiffInlet 2)))
;; Set the properties on the newly created objects
(vlax-put vlaDiffuser 'Layer "M-DIFF-RETN")
(vlax-put VlaCircle 'Layer "M-DIFF-RETN")
;; Silent exit
(princ)
)
((= (strcase DiffStyle)"EXHAUST")
;; Create the layer for the diffuser
(DIFF_CREATE_LAYER "M-DIFF-EXHS" "Mechanical Plan - Exhaust diffusers, register
and grilles" "Continuous" "35" "83" "1")
;; Get the outside points from the insertion point
(setq DiffPointList(DIFF_GET_POINTS InsPoint DiffWidth DiffLength))
(setq ExhsPointList (list (nth 0 DiffPointList)(nth 1 DiffPointList)(nth 2 DiffP
ointList)))
;; Create list of 2D point from DiffPointList
(setq Stop (length DiffPointList))
(setq Counter 0)
(while (/= Counter Stop)
(setq TempPoint(reverse(cdr(reverse (nth Counter DiffPointList)))))
(setq DiffPoints (append TempPoint DiffPoints))
(setq Counter (1+ Counter))
)
;; Draw the outside of the diffuser from the 2D points
(setq vlaDiffuser (vla-addLightweightPolyline Space
(vlax-safearray-fill
(vlax-make-safearray vlax-vbDouble (cons 0 (- (length DiffPoints) 1)))
DiffPoints))
)
;; Close the polyline
(vla-put-closed vlaDiffuser :vlax-true)
;; Draw line to show it is a supply diffuser
(foreach X ExhsPointList
(setq Ang (angle InsPoint X))
(setq StopPoint (polar X Ang (-(/ DiffInlet 2)(distance InsPoint X))))
(setq VlaLine (vlax-invoke space 'AddLine X StopPoint))
;; Set properties
(vlax-put VlaLine 'Layer "M-DIFF-EXHS")
)
;; Draw the center inlet
(setq VlaCircle (vlax-invoke space 'AddCircle InsPoint (/ DiffInlet 2)))
;; Set the properties on the newly created objects
(vlax-put vlaDiffuser 'Layer "M-DIFF-EXHS")
(vlax-put VlaCircle 'Layer "M-DIFF-EXHS")
;; Silent exit
(princ)
)
)
(DIFF_RESET_ENV)
)
;;; ------------ CREATE MOUNTED ROUND DIFFUSER
(defun DIFF_MOUNTED_ROUND(InsPoint DiffWidth DiffInlet /
DiffPointList DiffPoints ExhsPointList RtrnPointList Stop Counter TempPoint vlaD
iffuser Ang StopPoint VlaLine VlaCircle)
(cond
((= (strcase DiffStyle)"SUPPLY")
;; Create the layer for the diffuser
(DIFF_CREATE_LAYER "M-DIFF-SUPP" "Mechanical Plan - Supply diffusers, register a
nd grilles" "Continuous" "35" "133" "1")
;; Get the outside points from the insertion point
(setq DiffPointList(DIFF_GET_POINTS InsPoint (DIFF_INSCRIBE_SQUARE DiffWidth)(DI
FF_INSCRIBE_SQUARE DiffWidth)))
;; Create list of 2D point from DiffPointList
(setq Stop (length DiffPointList))
(setq Counter 0)
(while (/= Counter Stop)
(setq TempPoint(reverse(cdr(reverse (nth Counter DiffPointList)))))
(setq DiffPoints (append TempPoint DiffPoints))
(setq Counter (1+ Counter))
)
;; Draw the center inlet
(setq vlaDiffuser (vlax-invoke space 'AddCircle InsPoint (/ DiffWidth 2)))
;; Draw line to show it is a supply diffuser
(foreach X DiffPointList
(setq Ang (angle InsPoint X))
(setq StopPoint (polar X Ang (-(/ DiffInlet 2)(distance InsPoint X))))
(setq VlaLine (vlax-invoke space 'AddLine X StopPoint))
;; Set properties
(vlax-put VlaLine 'Layer "M-DIFF-SUPP")
)
;; Draw the center inlet
(setq VlaCircle (vlax-invoke space 'AddCircle InsPoint (/ DiffInlet 2)))
;; Set the properties on the newly created objects
(vlax-put vlaDiffuser 'Layer "M-DIFF-SUPP")
(vlax-put VlaCircle 'Layer "M-DIFF-SUPP")
;; Silent exit
(princ)
)
((= (strcase DiffStyle)"RETURN")
;; Create the layer for the diffuser
(DIFF_CREATE_LAYER "M-DIFF-RETN" "Mechanical Plan - Return diffusers, register a
nd grilles" "Continuous" "35" "23" "1")
;; Get the outside points from the insertion point
(setq DiffPointList(DIFF_GET_POINTS InsPoint (DIFF_INSCRIBE_SQUARE DiffWidth)(DI
FF_INSCRIBE_SQUARE DiffWidth)))
(setq RtrnPointList (list (nth 0 DiffPointList)(nth 2 DiffPointList)))
;; Create list of 2D point from DiffPointList
(setq Stop (length DiffPointList))
(setq Counter 0)
(while (/= Counter Stop)
(setq TempPoint(reverse(cdr(reverse (nth Counter DiffPointList)))))
(setq DiffPoints (append TempPoint DiffPoints))
(setq Counter (1+ Counter))
)
;; Draw the outside of the diffuser from the 2D points
(setq vlaDiffuser (vlax-invoke space 'AddCircle InsPoint (/ DiffWidth 2)))
;; Draw line to show it is a return diffuser
(foreach X RtrnPointList
(setq Ang (angle InsPoint X))
(setq StopPoint (polar X Ang (-(/ DiffInlet 2)(distance InsPoint X))))
(setq VlaLine (vlax-invoke space 'AddLine X StopPoint))
;; Set properties
(vlax-put VlaLine 'Layer "M-DIFF-RETN")
)
;; Draw the center inlet
(setq VlaCircle (vlax-invoke space 'AddCircle InsPoint (/ DiffInlet 2)))
;; Set the properties on the newly created objects
(vlax-put vlaDiffuser 'Layer "M-DIFF-RETN")
(vlax-put VlaCircle 'Layer "M-DIFF-RETN")
;; Silent exit
(princ)
)
((= (strcase DiffStyle)"EXHAUST")
;; Create the layer for the diffuser
(DIFF_CREATE_LAYER "M-DIFF-EXHS" "Mechanical Plan - Exhaust diffusers, register
and grilles" "Continuous" "35" "83" "1")
;; Get the outside points from the insertion point
(setq DiffPointList (DIFF_GET_POINTS InsPoint (DIFF_INSCRIBE_SQUARE DiffWidth)(D
IFF_INSCRIBE_SQUARE DiffWidth)))
(setq ExhsPointList (list (nth 0 DiffPointList)(nth 1 DiffPointList)(nth 2 DiffP
ointList)))
;; Create list of 2D point from DiffPointList
(setq Stop (length DiffPointList))
(setq Counter 0)
(while (/= Counter Stop)
(setq TempPoint(reverse(cdr(reverse (nth Counter DiffPointList)))))
(setq DiffPoints (append TempPoint DiffPoints))
(setq Counter (1+ Counter))
)
;; Draw the outside of the diffuser from the 2D points
(setq vlaDiffuser (vlax-invoke space 'AddCircle InsPoint (/ DiffWidth 2)))
;; Draw line to show it is a supply diffuser
(foreach X ExhsPointList
(setq Ang (angle InsPoint X))
(setq StopPoint (polar X Ang (-(/ DiffInlet 2)(distance InsPoint X))))
(setq VlaLine (vlax-invoke space 'AddLine X StopPoint))
;; Set properties
(vlax-put VlaLine 'Layer "M-DIFF-EXHS")
)
;; Draw the center inlet
(setq VlaCircle (vlax-invoke space 'AddCircle InsPoint (/ DiffInlet 2)))
;; Set the properties on the newly created objects
(vlax-put vlaDiffuser 'Layer "M-DIFF-EXHS")
(vlax-put VlaCircle 'Layer "M-DIFF-EXHS")
;; Silent exit
(princ)
)
)
(DIFF_RESET_ENV)
)
;;; ------------ GET CORNER POINTS FROM CENTER POINT
(defun DIFF_GET_POINTS (InsPoint DiffWidth DiffLength / DLength DWidth )
(setq DLength (* 0.5 DiffWidth))
(setq DWidth (* 0.5 DiffLength))
(setq InsPoint (trans InsPoint 1 0))
(setq DPoint1 (list (- (car InsPoint) DLength)(- (cadr InsPoint) DWidth)(caddr I
nsPoint)))
(setq DPoint2 (list (+ (car InsPoint) DLength)(+ (cadr InsPoint) DWidth)(caddr I
nsPoint)))
(setq DPoint3 (list (car DPoint2)(cadr DPoint1)(caddr InsPoint)))
(setq DPoint4 (list (car DPoint1)(cadr DPoint2)(caddr InsPoint)))
(list DPoint1 DPoint3 DPoint2 DPoint4)
)
;;; ------------ DEGREES TO RADIANS SUB ROUTINE
(defun DIFF_DTR (NumberOfDegrees)
(* pi (/ NumberOfDegrees 180.0))
)
;;; ------------ ROUND NUMBER
(defun DIFF_RND (Number Precision)
(setq Number(distof (rtos Number 4 Precision)4))
)
;;; ------------ INSCRIBE A SQUARE IN A CIRCLE
(defun DIFF_INSCRIBE_SQUARE (Diameter / A SinA SinB Sidelength)
(setq A Diameter)
(setq SinA (sin (DIFF_DTR 90)))
(setq SinB (sin (DIFF_DTR 45)))
(setq SideLength (DIFF_RND (/ (* A SinB) SinA)4))
Sidelength
)
;;; ------------ SET ENVIROMENT BEFORE LAUNCH
(defun DIFF_SET_ENV(/)
(setq OldClayer (getvar "CLAYER"))
(setq OldCmdEcho (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(vl-load-com)
(setq ActiveDoc (vla-get-activedocument (vlax-get-acad-object)))
(setq Space
(if (= (getvar "cvport") 1)
(vla-get-paperspace ActiveDoc)
(vla-get-modelspace ActiveDoc)
)
)
;; Run duct
(DIFF_RUN)
)
;;; ------------ RESET SYSEM VARIABLES
(defun DIFF_RESET_ENV (/)
(setvar "CMDECHO" OldCmdEcho)
(setvar "CLAYER" OldClayer)
(princ)
)
;;;
;;; Echos to the command line
(princ "\n CreateDiffuser v1.1 Timothy Spangler, \n January, 2007....loaded.")
(terpri)
(princ "C:DIFF")
(print)
;;; End echo

;;; ------------------------------------------------------------------------
;;; CreateCap.lsp v1.1
;;;
;;; Copyright January, 2007
;;; Timothy G. Spangler
;;;
;;; Permission to use, copy, modify, and distribute this software
;;; for any purpose and without fee is hereby granted, provided
;;; that the above copyright notice appears in all copies and
;;; that both that copyright notice and the limited warranty and
;;; restricted rights notice below appear in all supporting
;;; documentation.
;;;
;;; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;; WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;; PURPOSE AND OF MERCHANTIBILITY ARE HEREBY DISCLAIMED BY THE
;;; PROGRAMMER.
;;;
;;; -----------------------------------------------------------------------
;;; ------------ COMMAND LINE FUNCTIONS
(defun c:CAP (/ TrunkLine CapInsul)(CAP_START))
;;; ------------ MAIN FUNCTION
(defun CAP_START (/ *error* ActiveDoc Space OldClayer OldCmdEcho OldOsmode LineS
tart
LineEnd LineAngle TrunkSize CapStart SidePoint CapLayer EntList )
;;; Begin Error Handler -------------------------------------------------
(defun *error* (MSG)
(if (not (member MSG '("Function cancelled" "quit / exit abort")))
(princ (strcat "\n*** Program Error: " (strcase MSG) " ***"))
(princ "\n... Program Cancelled ...")
)
(while (< 0 (getvar "cmdactive"))
(command)
)
(CAP_RESET_ENV)
(princ)
)
;;; End Error Handler ---------------------------------------------------
(CAP_SET_ENV)
)
;;; ------------ SET ENVIROMENT BEFORE LAUNCH
(defun CAP_SET_ENV(/)
;; Set system variables
(setq OldClayer (getvar "CLAYER"))
(setq OldCmdEcho (getvar "CMDECHO"))
(setq OldOsmode (getvar "OSMODE"))
(setvar "CMDECHO" 0)
;; Set undo marker
(command "_undo" "begin")
;; Load vlisp com
(vl-load-com)
(setq ActiveDoc (vla-get-activedocument (vlax-get-acad-object)))
(setq Space
(if (= (getvar "cvport") 1)
(vla-get-paperspace ActiveDoc)
(vla-get-modelspace ActiveDoc)
)
)
;; Setup layer for insulation
(CAP_CREATE_LAYER "M-HVAC-INSL" "Mechanical Plan - Ductwork Insulation" "HIDDEN2
" "15" "201" "1")
;; Run cap
(CAP_RUN)
)
;;; ------------ RUN TEE SUB ROUTINE - GET VARIABLES
(defun CAP_RUN (/ TrunkLine EntList TeeLayer)
;; Get properties from current trunk line
(while (null (setq TrunkLine (car (nentsel "\n Select duct to add cap to: "))))
(princ "\n Duct not selected")
)
(setq EntList (entget TrunkLine))
(setq CapLayer (cdr (assoc 8 EntList)))
;; Set cap layer
(setvar "CLAYER" CapLayer)
;; Set cap properties
(if (equal (cdr (assoc 0 EntList)) "LINE")
(progn
(setq LineStart (cdr (assoc 10 EntList)))
(setq LineEnd (cdr (assoc 11 EntList)))
(setq LineAngle (angle LineStart LineEnd))
(setq TrunkSize (distance LineStart LineEnd))
(setq CapStart (polar LineStart LineAngle (/ (distance LineStart LineEnd) 2)))
)
(progn
(princ "\n Trunk must be a line. ")
(CAP_RUN)
)
)
;; Get cap side
(setq SidePoint (getpoint CapStart "\n Define end to cap: "))
(setq TrunkDirection (CAP_GET_PERP LineStart LineEnd SidePoint))
;; Get cap insulation
(initget 1 "None Inside Outside Both")
(setq CapInsul (getkword "\n Insulation options: (None/Inside/Oustside/Both)"))
(CAP_CREATE CapInsul)
)
;;; ------------ CREATE SYMETRICAL TEE SUB ROUTINE
(defun CAP_CREATE (CapInsul / CapPoint01 CapPoint02 CapPoint03 CapPoint04 CapPoi
nt05
CapInsulPoint01 CapInsulPoint02 CapInsulPoint03 CapInsulPoint04 CapInsulPoint05
CapInsulPoint06)
;; Create cap outside points
(setq CapPoint01 (polar CapStart TrunkDirection 1.0))
(setq CapPoint02 (polar CapPoint01 (CAP_ADD_ANGLE TrunkDirection 90.0) (+ 1.0 (/
TrunkSize 2))))
(setq CapPoint03 (polar CapPoint01 (CAP_SUBTRACT_ANGLE TrunkDirection 90.0) (+ 1
.0 (/ TrunkSize 2))))
(setq CapPoint04 (polar CapPoint02 (CAP_ADD_ANGLE TrunkDirection 180.0) 2.0))
(setq CapPoint05 (polar CapPoint03 (CAP_ADD_ANGLE TrunkDirection 180.0) 2.0))
;; Create cap insulation points
(setq CapInsulPoint01 (polar LineStart (CAP_ADD_ANGLE TrunkDirection 180.0) 1.0)
)
(setq CapInsulPoint02 (polar LineEnd (CAP_ADD_ANGLE TrunkDirection 180.0) 1.0))
(setq CapInsulPoint03 (polar CapPoint04 (CAP_ADD_ANGLE TrunkDirection 90.0) 1.0)
)
(setq CapInsulPoint04 (polar CapPoint05 (CAP_SUBTRACT_ANGLE TrunkDirection 90.0)
1.0))
(setq CapInsulPoint05 (polar CapInsulPoint03 TrunkDirection 3.0))
(setq CapInsulPoint06 (polar CapInsulPoint04 TrunkDirection 3.0))
;; Create cap
(vlax-invoke space 'addline CapPoint04 CapPoint02)
(vlax-invoke space 'addline CapPoint02 CapPoint03)
(vlax-invoke space 'addline CapPoint05 CapPoint03)
;; Set insulation layer
(setvar "CLAYER" "M-HVAC-INSL")
;; Create insulation
(cond
((= CapInsul "Inside")
(vlax-invoke space 'addline CapInsulPoint01 CapInsulPoint02)
)
((= CapInsul "Outside")
(vlax-invoke space 'addline CapInsulPoint03 CapInsulPoint05)
(vlax-invoke space 'addline CapInsulPoint05 CapInsulPoint06)
(vlax-invoke space 'addline CapInsulPoint04 CapInsulPoint06)
)
((= CapInsul "Both")
(vlax-invoke space 'addline CapInsulPoint01 CapInsulPoint02)
(vlax-invoke space 'addline CapInsulPoint03 CapInsulPoint05)
(vlax-invoke space 'addline CapInsulPoint05 CapInsulPoint06)
(vlax-invoke space 'addline CapInsulPoint04 CapInsulPoint06)
)
)
;; Reset environment
(CAP_RESET_ENV)
)
;;; ------------ LAYER CREATION ROUINE
(defun CAP_CREATE_LAYER (Layer Descpition Linetype Thickness Color Plot / Linety
pe TmpList VLA-Obj)
;; Check to see if linetype exsists
(if (= (tblsearch "ltype" Linetype) nil)
(if (CAP_CHECK_LINETYPE (findfile "acad.lin") Linetype)
(command "linetype" "load" Linetype "acad.lin" "")
(setq Linetype "Continuous")
)
)
;;; ------------ CREATE A LIST FOR ENTMAKE
(setq TmpList
(list
(cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 70 0)
)
)
;; Create layer name list
(setq TmpList (append TmpList (list (cons 2 Layer))))
;; Create layer color list
(setq TmpList (append TmpList (list (cons 62 (atoi Color)))))
;; Create layer linetype list
(setq TmpList (append TmpList (list (cons 6 Linetype))))
;; Create layer lineweight list
(setq TmpList (append TmpList (list (cons 370 (atoi Thickness)))))
;; Create layer plot list
(setq TmpList (append TmpList (list (cons 290 (atoi Plot)))))
;; Create layer from first item in the list
(entmake TmpList)
;; Create layer description
(if(or(= 16.1 (atof(getvar "acadver")))(< 16.1 (atof(getvar "acadver"))))
(progn
(setq VLA-Obj(vla-Add (vla-Get-Layers ActiveDoc)Layer))
(vla-Put-Description VLA-Obj Descpition)
(vlax-release-object VLA-Obj)
)
)
)
;;; ------------ CHECKS TO SEE IF A LINETYPE IS AVAILIBLE
(defun CAP_CHECK_LINETYPE (LINFile Linetype / OpenFile LineNumber CurrentLine Re
sult)
(setq OpenFile (open LINFile "r"))
(while (setq CurrentLine (read-line OpenFile))
(if (wcmatch CurrentLine "`**")
(progn
(setq LinetypeName (substr(car(CAP_STRING_TO_LIST CurrentLine ","))2))
(if (= (strcase Linetype) LinetypeName)
(setq Result T)
)
)
)
)
(close OpenFile)
Result
)
;;; ------------ STRING TO LIST SUB ROUTINE
(defun CAP_STRING_TO_LIST (Stg Del / CurChr PosCnt TmpLst TmpStr)
(setq PosCnt 1
TmpStr ""
)
(repeat (1+ (strlen Stg))
(setq CurChr (substr Stg PosCnt 1))
(if (= CurChr Del)
(progn
(setq TmpLst (cons TmpStr TmpLst))
(setq TmpStr "")
)
(setq TmpStr (strcat TmpStr CurChr))
)
(setq PosCnt (1+ PosCnt))
)
(setq TmpLst (reverse TmpLst))
)
;;; ------------ ADD / SUBTRACT ANGLE SUB ROUTINES
(defun CAP_ADD_ANGLE (Radians AddAngle / )
(CAP_DTR(+ (CAP_RTD Radians) AddAngle))
)
(defun CAP_SUBTRACT_ANGLE (Radians AddAngle / )
(CAP_DTR(- (CAP_RTD Radians) AddAngle))
)
;;; ------------ GET PERPENDICULAR POINT
(defun CAP_GET_PERP (StartPoint EndPoint Point / EntList LineStart LineEnd LineA
ngle NewAngle PerpAngle)
(setq PerpStart (trans StartPoint 0 1))
(setq PerpEnd (trans EndPoint 0 1))
(setq PerpAngle (angle PerpStart PerpEnd))
(if (minusp (sin (- (angle PerpStart Point) PerpAngle))) ;determine direction
(setq NewAngle (- PerpAngle (/ pi 2))) ;if "below" -90 deg
(setq NewAngle (+ PerpAngle (/ pi 2))) ;or "above" +90 deg
)
NewAngle
)
;; ------------ DEGREES / RADIANS SUB ROUTINES
(defun CAP_DTR (NumberOfDegrees)
(* pi (/ NumberOfDegrees 180.0))
)
(defun CAP_RTD (NumberOfRadians)
(* 180.0 (/ NumberOfRadians pi))
)
;;; ------------ RESET SYSEM VARIABLES
(defun CAP_RESET_ENV (/)
(setvar "CMDECHO" OldCmdEcho)
(setvar "CLAYER" OldClayer)
(setvar "OSMODE" OldOsmode)
(command "_undo" "end")
(princ)
)
;;;
;;; Echos to the command line
(princ "\n CreateCap v1.1 Timothy Spangler, \n January, 2007....loaded.")
(terpri)
(princ "C:CAP")
(print)
;;; End echo

;;; ------------------------------------------------------------------------
;;; CreateFlex.lsp v1.2
;;;
;;; Copyright May, 2008
;;; Timothy G. Spangler
;;;
;;; Permission to use, copy, modify, and distribute this software
;;; for any purpose and without fee is hereby granted, provided
;;; that the above copyright notice appears in all copies and
;;; that both that copyright notice and the limited warranty and
;;; restricted rights notice below appear in all supporting
;;; documentation.
;;;
;;; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;; WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;; PURPOSE AND OF MERCHANTIBILITY ARE HEREBY DISCLAIMED BY THE
;;; PROGRAMMER.
;;;
;;; -----------------------------------------------------------------------
;;; ------------ COMMAND LINE FUNCTIONS
(defun c:FX (/)(FLEX_START))
;;; ------------ MAIN FUNCTION
(defun FLEX_START (/ *error* OldCmdEcho OldOrthoMode OldOsmode OldLunits OldLuni
ts OldFillMode
ActiveDoc Space FlexSize FlexStart TrunkLine BlockName FlexEnd)
;;; Begin Error Handler -------------------------------------------------
(defun *error* (MSG)
(if (not (member MSG '("Function cancelled" "quit / exit abort")))
(princ (strcat "\n*** Program Error: " (strcase MSG) " ***"))
(princ "\n... Program Cancelled ...")
)
(while (< 0 (getvar "cmdactive"))
(command)
)
(FLEX_RESET_ENV)
)
;;; End Error Handler ---------------------------------------------------
(FLEX_SET_ENV)
)
;;; ------------ SETUP FLEXDUCT ENVIRONMENT SUB
(defun FLEX_SET_ENV (/)
;; Set sysetm variable
(setq OldCmdEcho (getvar "CMDECHO"))
(setq OldOrthoMode (getvar "ORTHOMODE"))
(setq OldOsmode (getvar "OSMODE"))
(setq OldLunits (getvar "LUNITS"))
(setq OldLuPrec (getvar "LUPREC"))
(setq OldFillMode (getvar "FILLMODE"))
(setvar "CMDECHO" 0)
;; Set undo marker
(command "undo" "Begin")
(setvar "ORTHOMODE" 0)
(setvar "OSMODE" 514)
(setvar "LUNITS" 2)
(setvar "LUPREC" 4)
(setvar "FILLMODE" 0)
;; Load VLISP funtionality
(vl-load-com)
;; Set Vlisp Environment variables
(setq ActiveDoc (vla-get-activedocument (vlax-get-acad-object)))
(setq Space
(if (= (getvar "cvport") 1)
(vla-get-paperspace ActiveDoc)
(vla-get-modelspace ActiveDoc)
)
)
;; Run flex duct program
(FLEX_RUN)
)
;;; ------------ GET USER VARIABLES SUB
(defun FLEX_RUN (/ FlexStart EndPoint FlexSize PlineEnt VLPlineObj VLPlineLength
FlexDuct1 FlexDuct2
FlexDuct1Pts FlexDuct2Pts FlexDuct3Pts FlexDuct4Pts FlexDuct5Pts FlexCap1 FlexCa
p2 CloseOpt)
(if (not (setq FlexSize (getreal "\n Enter flex size: ")))
(setq FlexSize 6.0)
)
(FLEX_BLOCK FlexSize)
(setq FlexStart (getpoint "\n Define flex start point: "))
(setq FlexEnd (getpoint FlexStart "\n Define flex direction: "))
(setq FlexEnd (polar FlexStart (angle FlexStart FlexEnd) 3.0))
(command "_pline" FlexStart "width" FlexSize FlexSize FlexEnd "arc")
(while (> (getvar "cmdactive") 0)
(command PAUSE)
)
(setq PlineEnt (entget(entlast)))
(setq VLPlineObj (vlax-ename->vla-object (cdr(assoc -1 PlineEnt))))
(setq VLPlineLength (fix (vlax-get VLPlineObj 'length)))
;; Change width to 0 (all for astetics)
(vlax-put VLPlineObj 'ConstantWidth 0.0)
(setvar "FILLMODE" OldFillMode)
;; Add "flex" to duct
(command "divide" (entlast) "block" BlockName "y" VLPlineLength)
;; Create flex duct sides
(setq FlexDuct1 (car (vlax-invoke VLPlineObj 'offset (/ FlexSize 2))))
(setq FlexDuct2 (car (vlax-invoke VLPlineObj 'offset (-(/ FlexSize 2)FlexSize)))
)
;; Get the end points of the sides
(setq FlexDuct1Pts (vlax-curve-getEndPoint FlexDuct1))
(setq FlexDuct2Pts (vlax-curve-getEndPoint FlexDuct2))
(setq FlexDuct3Pts (vlax-curve-getStartPoint FlexDuct1))
(setq FlexDuct4Pts (vlax-curve-getStartPoint FlexDuct2))
(setq FlexDuct5Pts (vlax-curve-getEndPoint VLPlineObj))
;; Create caps
(setq FlexCap2 (vlax-invoke space 'addline FlexDuct3Pts FlexDuct4Pts))
;; Check for losing option
(initget 1 "Blunt Arched")
(setq CloseOpt (getkword "\n Enter end condition: [Arched/Blunt]"))
(if (= "Blunt" CloseOpt)
(setq FlexCap1 (vlax-invoke space 'addline FlexDuct1Pts FlexDuct2Pts))
(progn
(vlax-invoke space
'addarc
FlexDuct5Pts
(/ FlexSize 2)
(angle FlexDuct2Pts FlexDuct1Pts)
(angle FlexDuct1Pts FlexDuct2Pts)
)
)
)
;; Delete centerline
(vla-delete VLPlineObj)
(FLEX_RESET_ENV)
)
;;; ------------ CREATE FLEX LINE BLOCK SUB - DOES NOT INSERT BLOCK
(defun FLEX_BLOCK (FlexSize /)
(setq OldLunits (getvar "LUNITS"))
(setq OldLuPrec (getvar "LUPREC"))
(setvar "LUNITS" 2)
(setvar "LUPREC" 1)
(setq BlockName (strcat "FLEX-" (rtos FlexSize 5 2)))
(if (= (tblsearch "block" BlockName) nil)
(progn
(entmake
(list
(cons 0 "BLOCK")
(cons 2 BlockName)
(cons 70 64)
(cons 10 (list 0.0 0.0 0.0))
(cons 8 "0")
)
)
(entmake
(list
(cons 0 "LINE")
(cons 10 (list 0.0 (- (/ FlexSize 2) FlexSize) 0.0))
(cons 11 (list 0.0 (/ FlexSize 2) 0.0))
(cons 8 "0")
(cons 62 9)
)
)
(entmake
'((0 . "ENDBLK"))
)
)
)
(setvar "LUNITS" OldLunits)
(setvar "LUPREC" OldLuPrec)
BlockName
)
;;; ------------ RESET SYSEM VARIABLES
(defun FLEX_RESET_ENV (/)
;; Release ActiveX objects
(vlax-release-object ActiveDoc)
(vlax-release-object Space)
;; Reset system variables
(setvar "ORTHOMODE" OldOrthoMode)
(setvar "OSMODE" OldOsmode)
(setvar "LUNITS" OldLunits)
(setvar "LUPREC" OldLuPrec)
;; Reset undo marker
(command "undo" "End")
(setvar "CMDECHO" OldCmdEcho)
(princ)
)
;;;
;;; Echos to the command line
(princ "\n CreateFlex v1.2 \n Timothy Spangler, \n May, 2008....loaded.")
(terpri)
(princ "C:FX")
(print)
(c:fx)

;;;; Duct Draw Program from Turkish developers


;;;; Translated to English by Igal Averbuh 2016
;** MAIN **
(defun c:kk (/ sys layer rad gen yuk p1 nesne)
(if (= sys nil)
(progn
(setq sys "SA")
)
)
(if (= layer nil)
(progn
(setq layer "MEC-DUCT-SA")
)
)
(setq e_ang nil)
(if (= ins nil)
(progn
(setq ins 25)
)
)
(if (= rad nil)
(progn
(setq rad 150)
)
)
(if (= gen nil)
(progn
(setq gen 200)
)
)
(if (= yuk nil)
(progn
(setq yuk 200)
)
)
(princ (strcat "\nCurent Settings: Width="
(rtos gen 2 0)
", Width="
(rtos yuk 2 0)
", Radius="
(rtos rad 2 0)
", System="
sys
)
)
(setq p1 (getpoint "\nStarting point of duct:"))
(setq nesne (ssget p1))
(if (/= nesne nil)
(progn
(if (/= nil
(setq xdata_list
(cdr
(assoc -3
(entget (ssname nesne 0) '("DuctData"))
)
)
)
)
(progn
(setq sys (cdr (nth 3 (car xdata_list))))
(setq gen (cdr (nth 4 (car xdata_list))))
(setq yuk (cdr (nth 5 (car xdata_list))))
(setq ins (cdr (nth 6 (car xdata_list))))
(setq layer (strcat "MEC-DUCT-" sys))
)
(progn
(setq layer (cdr (assoc 8 (entget (ssname nesne 0)))))
)
)
(setq ps (cdr (assoc 10 (entget (ssname nesne 0))))
pf (cdr (assoc 11 (entget (ssname nesne 0))))
)
(setq gen (distance ps pf)
ang (angle ps pf)
)
(setq p1 (polar ps ang (/ gen 2)))
)
)
(initget 1024 "Section / Insulation / Radius / System")
(while (/= nil
(setq p2
(getpoint
p1
(strcat
"\nNext point or [Section / Insulation / Radius / System] in mm:"
)
)
)
)
(if (= p2 "Undo")
(progn
(command "_.undo" "")
)
(progn
(command "undo" "group")
(cond
((= p2 "System")
(system_gir)
)
((= p2 "Radius")
(radius_gir)
)
((= p2 "Section")
(kesit_gir)
)
((= p2 "Insulation")
(ins_gir)
)
((/= nil e_ang)
(dirsek_ciz)
(setq p1 p2)
(setq e_l1 l1
e_l2 l2
)
(if (/= ins 0)
(progn
(setq e_li1 li1
e_li2 li2
)
)
)
)
((and (/= p2 "Section")
(/= p2 "Insulation")
(/= p2 "System")
)
(kanal_ciz)
(setq p1 p2)
(setq e_l1 l1
e_l2 l2
)
(if (/= ins 0)
(progn
(setq e_li1 li1
e_li2 li2
)
)
)
)
)
)
)
(initget 1024 "Section / Insulation / Radius / System")
(command "_.undo" "end")
)
)
;** **
;*******************************************************************************
*******************
;*******************************************************************************
*******************
;** INSULATION GIRISI **
(defun ins_gir ()
(setq e_ins ins)
(setq ins (getreal (strcat "\nEnter the new insulation thickness:"
)
)
)
(if (= nil ins)
(progn
(setq ins e_ins)
)
)
)
;** **
;*******************************************************************************
*******************
;*******************************************************************************
*******************
;** KESIT GIRISI **
(defun kesit_gir ()
(setq e_gen gen
e_yuk yuk
)
(setq
gen (getreal
(strcat "\nEnter duct width :")
)
)
(if (= gen nil)
(progn
(setq gen e_gen)
)
)
(setq
yuk (getreal
(strcat "\nEnter duct height :")
)
)
(if (= yuk nil)
(progn
(setq yuk e_yuk)
)
)
(if (and (/= e_ang nil)(or (/= yuk e_yuk) (/= gen e_gen)))
(progn
(red_ciz)
)
)
)
;** **
;*******************************************************************************
*******************
;*******************************************************************************
*******************
;** KANAL PARAMETRE **
(defun kanal_ciz ()
(setq e_ang ang)
(setq ang (angle p1 p2))
(setq pl1s (polar p1 (+ ang (dtr 90)) (/ gen 2))
pl1f (polar p2 (+ ang (dtr 90)) (/ gen 2))
pl2s (polar p1 (- ang (dtr 90)) (/ gen 2))
pl2f (polar p2 (- ang (dtr 90)) (/ gen 2))
)
(if (/= ins 0)
(progn
(setq pi1s (polar p1 (+ ang (dtr 90)) (+ ins (/ gen 2)))
pi1f (polar p2 (+ ang (dtr 90)) (+ ins (/ gen 2)))
pi2s (polar p1 (- ang (dtr 90)) (+ ins (/ gen 2)))
pi2f (polar p2 (- ang (dtr 90)) (+ ins (/ gen 2)))
)
)
)
(line_ciz layer pl1s pl1f)
(setq l1 (entlast))
(line_ciz layer pl2s pl2f)
(setq l2 (entlast))
(if (/= ins 0)
(progn
(if (< ins 0)
(progn
(setq lay (strcat layer "_AKUSTIK_INSULATION"))
)
(progn
(setq lay (strcat layer "-INSULATION"))
)
)
(line_ciz lay pi1s pi1f)
(setq li1 (entlast))
(line_ciz lay pi2s pi2f)
(setq li2 (entlast))
)
)
)
;** **
;*******************************************************************************
*******************
;*******************************************************************************
*******************
;** KANAL CIZDIRME **
(defun line_ciz (#l8 #l10 #l11)
(entmake (list
(cons 0 "LINE")
(cons 8 #l8)
(cons 10 #l10)
(cons 11 #l11)
)
)
)
;** **
;*******************************************************************************
*******************
;*******************************************************************************
*******************
;** DERECEDEN RADYANA GECIS **
(defun dtr (#aci)
(* pi (/ #aci 180.0))
)
;** **
;*******************************************************************************
*******************
;*******************************************************************************
*******************
;** DIRSEK CIZ **
(defun dirsek_ciz ()
(setq e_pl1s pl1s
e_pl2s pl2s
e_pl1f pl1f
e_pl2f pl2f
)
(kanal_ciz)
(setq n1 (list (nth 0 pl1s) (nth 1 pl1s)))
(setq n2 (list (nth 0 pl1f) (nth 1 pl1f)))
(setq n3 (list (nth 0 e_pl1s) (nth 1 e_pl1s)))
(setq n4 (list (nth 0 e_pl1f) (nth 1 e_pl1f)))
(setq p1x (inters n1 n2 n3 n4 t))
(setq n1 (list (nth 0 e_pl2s) (nth 1 e_pl2s)))
(setq n2 (list (nth 0 e_pl2f) (nth 1 e_pl2f)))
(setq n3 (list (nth 0 pl2s) (nth 1 pl2s)))
(setq n4 (list (nth 0 pl2f) (nth 1 pl2f)))
(setq p2x (inters n1 n2 n3 n4 t))
(setq e_rad (getvar "filletrad"))
(if (< p2x p1x)
(progn
(setvar "filletrad" rad)
(command "FILLET" l1 e_l1)
(x_arc (setq arc (entlast)))
(setq pa1s pas
pa1f paf
)
(setvar "filletrad" (+ gen rad))
(command "FILLET" l2 e_l2)
(x_arc (entlast))
(setq pa2s pas
pa2f paf
)
(if (/= ins 0)
(progn
(setvar "filletrad" (- rad ins))
(command "FILLET" li1 e_li1)
(setvar "filletrad" (+ ins gen rad))
(command "FILLET" li2 e_li2)
)
)
)
)
(if (< p1x p2x)
(progn
(setvar "filletrad" rad)
(command "FILLET" l2 e_l2)
(x_arc (setq arc (entlast)))
(setq pa2s pas
pa2f paf
)
(setvar "filletrad" (+ gen rad))
(command "FILLET" l1 e_l1)
(x_arc (entlast))
(setq pa1s pas
pa1f paf
)
(if (/= ins 0)
(progn
(setvar "filletrad" (- rad ins))
(command "FILLET" li2 e_li2)
(setvar "filletrad" (+ ins gen rad))
(command "FILLET" li1 e_li1)
)
)
)
)
(line_ciz layer pa1s pa2s)
(setq l- (entlast))
(if (< e_ang ang)
(progn
(setq ang_fark (- ang e_ang)))
(progn
(setq ang_fark (- e_ang ang))))
(setq d_ang (rtd ang_fark))
(cond
((< d_ang 90)
(setq d_ang d_ang))
((< d_ang 180)
(setq d_ang (- 180 d_ang)))
((< d_ang 270)
(setq d_ang (- 270 d_ang)))
((vla-object nent))
(setq pas (vlax-curve-getEndPoint data))
(setq paf (vlax-curve-getstartPoint data))
)
;** **
;*******************************************************************************
*******************
;*******************************************************************************
*******************
;** RADIUS GIRISI **
(defun radius_gir ()
(setq e_rad rad)
(setq rad (getreal (strcat "\nEnter the new insulation thickness:"
)
)
)
(if (= nil rad)
(progn
(setq rad e_rad)
)
)
)
;** **
;*******************************************************************************
*******************
;*******************************************************************************
*******************
;** REDUKSIYON CIZ **
(defun red_ciz ()
(if (= nil red_len)
(progn
(setq red_len 300)
)
)
(setq e_red_len red_len)
(setq red_len (getreal (strcat "\nEnter reduction size :"
)
)
)
(if (= red_len nil)
(progn
(setq red_len e_red_len)
)
)
(prompt "\nChoose Your:")
(while (or (= (car (setq #grread (grread t 5 0))) 5)
(= (car (setq #grread (grread t 5 0))) 2)
)
(redraw)
(setq pin (cadr #grread))
(setq pp1 (polar pin ang 100))
(setq ppx (inters pl1f pl2f pin pp1 nil))
(setq fark (distance p1 ppx))
(if (< fark (/ e_gen 4))
(progn
(setq p2 (polar p1 ang red_len))
(setq pr1f (polar p2 (+ ang (dtr 90)) (/ gen 2)))
(setq pr2f (polar p2 (- ang (dtr 90)) (/ gen 2)))
(if (/= ins 0)
(progn
(setq pri1f (polar p2 (+ ang (dtr 90)) (+ ins (/ gen 2))))
(setq pri2f (polar p2 (- ang (dtr 90)) (+ ins (/ gen 2))))
)
)
)
(progn
(setq fark1 (distance ppx pl1f))
(setq fark2 (distance ppx pl2f))
(setq ang_1 (angle pl1f ppx))
(setq ang_2 (angle pl2f ppx))
(if (< fark1 fark2)
(progn
(setq pr1f (polar pl1f ang red_len))
(setq pr2f (polar pr1f ang_1 gen))
(setq p2 (polar pr1f ang_1 (/ gen 2)))
(if (/= ins 0)
(progn
(setq pri1f (polar pi1f ang red_len))
(setq pri2f (polar pr1f ang_1 (+ ins gen)))
)
)
)
(progn
(setq pr2f (polar pl2f ang red_len))
(setq pr1f (polar pr2f ang_2 gen))
(setq p2 (polar pr2f ang_2 (/ gen 2)))
(if (/= ins 0)
(progn
(setq pri2f (polar pi2f ang red_len))
(setq pri1f (polar pr2f ang_2 (+ ins gen)))
)
)
)
)
)
)
(grdraw pl1f pr1f 1 1)
(grdraw pl2f pr2f 1 1)
(grdraw pr1f pr2f 1 1)
(if (/= ins 0)
(progn
(grdraw pi1f pri1f 1 1)
(grdraw pi2f pri2f 1 1)
)
)
)
(line_ciz layer pl1f pr1f)
(setq l1 (entlast))
(line_ciz layer pl2f pr2f)
(setq l- (entlast))
(line_ciz layer pr1f pr2f)
(setq l- (entlast))
(line_ciz layer pl1f pl2f)
(setq l- (entlast))
(setq pl1f pr1f
pl2f pr2f
p1 p2
)
(if (/= ins 0)
(progn
(line_ciz lay pi1f pri1f)
(line_ciz lay pi2f pri2f)
(setq pi1f pri1f
pi2f pri2f
)
)
)
)
;** **
;*******************************************************************************
*******************
;*******************************************************************************
*******************
;** SYSTEM GIRISI **
(defun system_gir ()
(setq e_sys sys)
(setq sys (getstring (strcat "\nEnter System name:"
)
T)
)
(if (= "" sys)
(progn
(setq sys e_sys)
)
)
(setq layer (strcat "MEC-DUCT-"(strcase sys)))
)
;** **
;*******************************************************************************
*******************
(c:kk)

;| ;;
TAPER TRANSITION - 2008-10-18 ;;
Par Andrea Andreetti ;;
|;
;;
(defun c:taper ()
(setq gdc2 (getreal "Grandeur de la conduite : "))
(setq gdc2demi (/ gdc2 2.0))
(setq l1 (nentsel "premiere ligne..."))
(setq l2 (nentsel "ligne Oppos?..."))
(setq entl1 (entget (car l1)))
(setq entl2 (entget (car l2)))
(setq l1a (cdr (assoc 10 (entget (car l1)))))
(setq l1b (cdr (assoc 11 (entget (car l1)))))
(setq l2a (cdr (assoc 10 (entget (car l2)))))
(setq l2b (cdr (assoc 11 (entget (car l2)))))
(if (< (distance (cadr l1) l1a) (distance (cadr l1) l1b))
(progn (setq l1 l1a) (setq ductway (angle l1b l1a)))
(progn (setq l1 l1b) (setq ductway (angle l1a l1b)))
)
(setq l2 (polar l1 (+ (dtr 90) (angle l1a l1b)) 5))
(setq il1 (inters l1 l2 l1a l1b nil))
(setq il2 (inters l1 l2 l2a l2b nil))
(if (< (distance il2 (cdr (assoc 10 entl2)))
(distance il2 (cdr (assoc 11 entl2)))
)
(progn (setq toreplace (assoc 10 entl2))
(setq bythis (cons 10 il2))
)
(progn (setq toreplace (assoc 11 entl2))
(setq bythis (cons 11 il2))
)
)
(entmod (subst bythis toreplace entl2))
(setq lunit (getvar "lunits"))
(if (< lunit 3)
(setq 6po 150)
(setq 6po 3)
)
(setq gdc1 (distance il1 il2))
(if (< (abs (* 3.0 (- gdc1 gdc2))) 6po)
(setq len 6po)
(setq len (abs (* 3.0 (- gdc1 gdc2))))
)
(setq mid1 (polar il1 (angle il1 il2) (/ (distance il1 il2) 2.0)))
(setq mid2 (polar mid1 ductway len))
(setq midl2 (polar mid2 (angle il1 il2) gdc2demi))
(setq midl1 (polar mid2 (angle il2 il1) gdc2demi))
(setq fixmid2 mid2)
(setq midlist (list mid2 midl2 midl1))
(setq midl1 (polar il1 ductway len))
(setq midl2 (polar midl1 (angle il1 il2) gdc2))
(setq mid2 (polar midl1 (angle il1 il2) gdc2demi))
(setq fixmidl2 midl2)
(setq l1list (list mid2 midl2 midl1))
(setq midl2 (polar il2 ductway len))
(setq midl1 (polar midl2 (angle il2 il1) gdc2))
(setq mid2 (polar midl2 (angle il2 il1) gdc2demi))
(setq fixmidl1 midl1)
(setq l2list (list mid2 midl2 midl1))
(while (or (= (car (setq grr (grread t 5 0))) 5)
(= (car (setq grr (grread t 5 0))) 2)
)
(redraw)
(if (< (distance (cadr grr) fixmid2)
(distance (cadr grr) fixmidl2)
)
(setq goodlist midlist)
)
(if (< (distance (cadr grr) fixmidl2)
(distance (cadr grr) fixmid2)
)
(setq goodlist l2list)
)
(if (< (distance (cadr grr) fixmidl1)
(distance (cadr grr) fixmid2)
)
(setq goodlist l1list)
)
(grdraw (nth 1 goodlist) (nth 2 goodlist) 147 0)
(grdraw (nth 1 goodlist) il2 147 0)
(grdraw (nth 2 goodlist) il1 147 0)
(grdraw il1 il2 147 0)
(setq intp2t (polar (nth 0 goodlist)
ductway
(distance fixmid2 (cadr grr))
)
)
(setq intp2z (polar (cadr grr) (angle midl1 midl2) gdc2demi))
(setq p2 (inters (nth 0 goodlist) intp2t (cadr grr) intp2z nil))
(setq p21 (polar p2 (angle midl2 midl1) gdc2demi))
(setq p22 (polar p2 (angle midl1 midl2) gdc2demi))
(grdraw (nth 1 goodlist) p22 147 0)
(grdraw (nth 2 goodlist) p21 147 0)
(if S2RT
(progn
(grdraw il1 (nth 0 goodlist) 1 1)
(grdraw il2 (nth 0 goodlist) 1 1)
(setq Jonc1 (polar (nth 1 goodlist) ductway 6po))
(setq Jonc2 (polar (nth 2 goodlist) ductway 6po))
(grdraw jonc1 jonc2 8 1)
)
)
(if R2ST
(progn
(grdraw mid1 (nth 1 goodlist) 1 1)
(grdraw mid1 (nth 2 goodlist) 1 1)
(setq Jonc1 (polar il1 (+ (dtr 180) ductway) 6po))
(setq Jonc2 (polar il2 (+ (dtr 180) ductway) 6po))
(grdraw jonc1 jonc2 8 1)
)
)
)
(taperentmake (cons 10 (nth 1 goodlist))
(cons 11 (nth 2 goodlist))
nil
nil
)
(taperentmake (cons 10 il2)
(cons 11 (nth 1 goodlist))
nil
nil
)
(taperentmake (cons 10 il1)
(cons 11 (nth 2 goodlist))
nil
nil
)
(taperentmake (cons 10 il1) (cons 11 il2) nil nil)
(taperentmake (cons 10 (nth 1 goodlist))
(cons 11 p22)
nil
nil
)
(taperentmake (cons 10 (nth 2 goodlist))
(cons 11 p21)
nil
nil
)
(redraw)
)
;;
;| |;
;| ;;
Degre To Radian ;;
|;
;;
(defun dtr (a)
(* pi (/ a 180.0))
)
;;
;| |;
;| ;;
Square To Round TRANSITION ;;
|;
;;
(defun c:s2r (/ Jonc1 Jonc2 S2RT)
(setq S2RT T)
(c:taper)
(setq Jonc1 (polar (nth 1 goodlist) ductway 6po))
(setq Jonc2 (polar (nth 2 goodlist) ductway 6po))
(Jonction_create Jonc1 Jonc2)
(taperentmake (cons 10 il1)
(cons 11 (nth 0 goodlist))
1
nil
)
(taperentmake (cons 10 il2)
(cons 11 (nth 0 goodlist))
1
nil
)
)
;;
;| |;
;| ;;
Round To Square TRANSITION ;;
|;
;;
(defun c:r2s (/ jonc1 jonc2 R2ST)
(setq R2ST T)
(c:taper)
(setq Jonc1 (polar il1 (+ (dtr 180) ductway) 6po))
(setq Jonc2 (polar il2 (+ (dtr 180) ductway) 6po))
(Jonction_create Jonc1 Jonc2)
(taperentmake (cons 10 mid1)
(cons 11 (nth 1 goodlist))
1
nil
)
(taperentmake (cons 10 mid1)
(cons 11 (nth 2 goodlist))
1
nil
)
)
;;
;| |;
;| ;;
ENTMAKE FUNCTION ;;
|;
;;
(defun jonction_create (J1 J2)
;; Assuming that ACAD.LIN Exist and contain "ACAD_ISO03W100" Linetype
(if (not (member "ACAD_ISO03W100" (mapcar 'strcase (ai_table "LTYPE" 0))))
(if (findfile "acad.lin")
(vl-cmdf "._-linetype" "_L" "ACAD_ISO03W100" "" "")
))
(taperentmake (cons 10 J1)
(cons 11 J2)
8
"ACAD_ISO03W100"
)
)
;;
;| |;
;| ;;
ENTMAKE FUNCTION ;;
|;
;;
(defun taperentmake (start end color linetype / lllist)
(setq lllist (list '(0 . "LINE") start end))
(if color
(setq lllist (append lllist (list (cons 62 color))))
)
(if linetype
(setq lllist (append lllist (list (cons 6 linetype))))
)
(entmake lllist)
)
;;
;| |;

HVAC Draw Branch Duct

(defun C:BD(/ ang1 ang2 ent1 ent2 ent3 ep1 ep3 ipt1 ipt2 ipt21
mp1 mp3 obj1 obj2 obj3 pt1 pt2 pt3 sp1 sp3)
(setq ent1 (entsel "\nSelect first branch line >>")
ent2 (entsel "\nSelect second branch line >>")
ent3 (entsel "\nSelect main duct connection line >>")
obj1 (vlax-ename->vla-object (car ent1))
obj2 (vlax-ename->vla-object (car ent2))
obj3 (vlax-ename->vla-object (car ent3))
)
(setq sp1 (vlax-curve-getstartpoint obj1)
ep1 (vlax-curve-getendpoint obj1)
mp1 (mapcar (function (lambda (a b) (/ (+ a b) 2))) sp1 ep1)
sp3 (vlax-curve-getstartpoint obj3)
ep3 (vlax-curve-getendpoint obj3)
mp3 (mapcar (function (lambda (a b) (/ (+ a b) 2))) sp3 ep3)
ipt1 (vlax-invoke obj1 'intersectwith obj3 0)
ipt2 (vlax-invoke obj2 'intersectwith obj3 0)
ang1 (angle ipt1 mp1)
ang2 (angle ipt2 ipt1)
wid (getdist "\nEnter reduction distance...\n ")
pt1 (polar ipt1 ang1 wid)
pt2 (polar ipt2 ang1 wid)
pt3 (polar ipt1 ang2 wid)
)
(command "_.break" ent1 "f" "_non" pt1 "_non" ipt1)
(command "line" "_non" pt1 "_non" pt2 "")
(command "line" "_non" pt1 "_non" pt3 "")
(princ)
)
(c:bd)

HVAC Rectangular Duct Break Draw


31
Sunday
Jul 2016
Posted by danglar71 in HVAC, Lisp Collection 2014
Leave a comment
(defun tan (xx)
(/ (sin xx) (cos xx))
)
(defun c:db (/ a b d1 d2 u1 u2 u3 p1 p2)
(setq oerr *error*)
(defun *error* (msg)
(setvar "osmode" osn)
(setq *error* oerr)
(command)
(princ)
)
(setq osn (getvar "osmode"))
(setvar "osmode" 512)
(setq a (getpoint "\n Point on the duct: "))
(setvar "osmode" 128)
(setq b (getpoint a "\n Point on opposite wall of duct: "))
(setq d1 (distance a b))
(setvar "osmode" 512)
(setq u1 (angle a b))
(setq u2 (+ u1 (* pi 0.5)))
(setq u3 (+ u2 (/ pi 3)))
(setq p1 (polar b u2 (* d1 (tan (/ pi 6)))))
(setq d2 (/ (distance a p1) 2))
(setq p2 (polar b u3 d2))
(setvar "osmode" 0)
(command "_.line" a p1 "")
(command "_.line" b p2 "")
(setvar "osmode" osn)
(princ)
)
(prompt "\n Type > db < to draw HVAC duct break: ")
(c:db)
Draws pipes by length of selected lines

;| DP.LSP JD HENMAN 20090818


DP - draws pipe the length of selected lines (centerlines)
(use along with pull-down menu for all Std pipe sizes
|;
(defun c:DP (/ olayer lay_name A B C D E N1 N2 pnt11 pnt12 mssg dist dist2 entit
y count total)
; load the vla command set
(vl-load-com)
; accessing the graphic screen as opposed to the text screen
(graphscr)
; remember the current layer
(setq olayer (getvar "clayer"))
; define the layers addressed in the program
(command "layer" "m" "Center" "c" "2" "" "lt" "Center2" "" "")
(command "layer" "m" "Hidden" "c" "142" "" "lt" "Hidden2" "" "")
(command "layer" "m" "Object" "c" "3" "" "lt" "Continuous" "" "")
(setvar "clayer" olayer)
; let user specify OD & ID
(setq P-OD (getreal "\n Enter External.Diametr. of Pipe: "))
(setq P-ID (getreal "\n Enter Internal.Diametr. of Pipe: "))
(setq P-OD_2 (/ P-OD 2))
(setq P-ID_2 (/ P-ID 2))
;| SECTION BLOCKED
; this portion filters only lines on layer PC
(setq lay_name "PC")
; note: ssget "X" even selects objects on layers turned off, locked or frozen!
(setq A (ssget "X"
(list (cons 0 "LINE") (cons 8 lay_name))
)
);setq A
; END SECTION BLOCKED
|;
(princ "\n Warning! Arc/Splines CL's Return Incorrect Length.\nSelect Centerline
s to Construct Pipe: ")
(setq A (ssget))
;variable B knows how many objects were found in variable A
(setq B (sslength A))
(setq C 0); counter
; the loop ends when C = B
(while (vla-object D))
; D is offset in both directions everything to be on Pipe layer
(vla-offset D idist)
(setq entity (entlast)
entity (entget entity)
entity (subst (cons 8 "Hidden")
(assoc 8 entity) entity)
);setq
(entmod entity)
(vla-offset D (* idist -1))
(setq entity (entlast)
entity (entget entity)
entity (subst (cons 8 "Hidden")
(assoc 8 entity) entity)
);setq
(entmod entity)
(vla-offset D odist)
(setq entity (entlast)
entity (entget entity)
entity (subst (cons 8 "Object")
(assoc 8 entity) entity)
);setq
(entmod entity)
(vla-offset D (* odist -1))
(setq entity (entlast)
entity (entget entity)
entity (subst (cons 8 "Object")
(assoc 8 entity) entity)
);setq
(entmod entity)
(setq C (1+ C));add one to counter before testing while loop again
) ;while
; Now to calculate the same selection sets total length in Feet & Inches.
(setq E (ssget "P"))
(setq total 0)
(setq count (sslength E))
(while (/= count 0)
(setq N1 (ssname E 0))
(setq N2 (entget N1)
N2 (subst (cons 8 "Center")
(assoc 8 N2) N2)
);setq
(setq pnt10 (cdr (assoc 10 N2)))
(setq pnt11 (cdr (assoc 11 N2)))
(setq dist2 (distance pnt10 pnt11))
(setq total (+ dist2 total))
(ssdel N1 E)
(entmod N2)
(setq count (1- count))
);end while
(setq mssg (strcat " Finished! " "\n Length of Pipe = " (rtos total 4 2)))
(prompt mssg)
(princ)
);defun DP
(c:DP)

;-----------------------------------------------------------------------------;
; Fichier: Pipe.lsp ;
; Objet : Permet de dessiner un tuyaux de diametre X avec un # de schedule Y ;
; 'utilisateur doit fournir un point de depart et un point d'arrivee ;
;-----------------------------------------------------------------------------;
(setq pipeversion "V3.0")
(pragma '((unprotect-assign 2pi pi/2 3pi/2 inf dtr rtd tan)))
(setq 2pi (+ pi pi)
pi/2 (/ pi 2)
3pi/2 (/ (+ pi pi pi) 2)
inf 1.7e308
)
; Degree to Radian Conversion & Radian to Degree ;
(defun dtr (a) (* pi (/ a 180.0)))
(defun rtd (a) (* 180.0 (/ a pi)))
(defun tan (a / cosa)
(cond ((zerop (rem a pi)) 0.0)
((zerop (rem a pi/2)) inf)
((zerop (setq cosa (cos a))) inf)
(t (/ (sin a) cosa))))
(pragma '((protect-assign 2pi pi/2 3pi/2 inf dtr rtd tan)))
; ;
; Layers Settings ;
; ;
(setq center (list "Pipe CENTER LINE" 3 "CENTER")
outside (list "Pipe EXTERIOR" 7 "CONTINUOUS")
inside (list "Pipe WALL" 6 "HIDDEN")
)
(setq pipe
(list
(list "1/2" (list "OD" 0.840)(list "5S" 0.065 )(list "5" 0.065)
(list "10S" 0.83)(list "10" 0.083)(list "STD" 0.109)
(list "40" 0.109)(list "XS" 0.147)(list "80" 0.147)
(list "160" 0.187)(list "XXS" 0.294)(list "A" 1.5)
(list "B" 0.625)(list "E" 1.0))
(list "3/4" (list "OD" 1.050)(list "5S"0.065)(list "5" 0.065)
(list "10S" 0.83)(list "10" 0.083)(list "STD" 0.113)
(list "40" 0.113)(list "XS" 0.154)(list "80" 0.154)
(list "160" 0.218)(list "XXS" 0.308)(list "A" 1.125)
(list "B" 0.4375)(list "E" 1.5) (list "C" 1.125))
(list "1" (list "OD" 1.315)(list "5S" 0.065)(list "5" 0.065)
(list "10S" 0.109)(list "10" 0.109)(list "STD" 0.133)
(list "40" 0.133)(list "XS" 0.179)(list "80" 0.179)
(list "160" 0.250)(list "XXS" 0.358)(list "A" 1.5)
(list "B" 0.875)(list "D" 1.0)(list "E" 1.5)
(list "C" 1.5))
(list "1 1/4" (list "OD" 1.66)(list "5S" 0.065)(list "5" 0.065)
(list "10S" 0.109)(list "10" 0.109)(list "STD" 0.140)
(list "40" 0.140)(list "XS" 0.191)(list "80" 0.191)
(list "160" 0.250)(list "XXS" 0.382)(list "A" 1.875)
(list "B" 1.0)(list "D" 1.25)(list "E" 1.5)
(list "C" 1.875))
(list "1 1/2" (list "OD" 1.90)(list "5S" 0.065)(list "5" 0.065)
(list "10S" 0.109)(list "10" 0.109)(list "STD" 0.145)
(list "40" 0.145)(list "XS" 0.20)(list "80" 0.20)
(list "160" 0.281)(list "XXS" 0.4)(list "A" 2.25)
(list "B" 1.125)(list "D" 1.5)(list "E" 1.5)
(list "C" 2.25))
(list "2" (list "OD" 2.375)(list "5S" 0.065)(list "5" 0.065)
(list "10S" 0.109)(list "10" 0.109)(list "STD" 0.154)
(list "40" 0.154)(list "XS" 0.218)(list "80" 0.218)
(list "160" 0.343)(list "XXS" 0.436)(list "A" 3.0)
(list "B" 1.375)(list "D" 2.0)(list "E" 1.5)
(list "C" 2.5))
(list "2 1/2" (list "OD" 2.875)(list "5S" 0.083)(list "5" 0.083)
(list "10S" 0.120)(list "10" 0.120)(list "STD" 0.203)
(list "40" 0.203)(list "XS" 0.276)(list "80" 0.276)
(list "160" 0.375)(list "XXS" 0.375)(list "A" 3.75)
(list "B" 1.75)(list "D" 2.5)(list "E" 1.5)
(list "C" 3))
(list "3" (list "OD" 3.500)(list "5S" 0.083)(list "5" 0.083)
(list "10S" 0.120)(list "10" 0.120)(list "STD" 0.216)
(list "40" 0.216)(list "XS" 0.3)(list "80" 0.3)
(list "160" 0.437)(list "XXS" 0.6)(list "A" 4.5)
(list "B" 2.0)(list "D" 3.0)(list "E" 2.0)
(list "C" 3.375))
(list "3 1/2" (list "OD" 4.0)(list "5S" 0.083)(list "5" 0.083)
(list "10S" 0.120)(list "10" 0.120)(list "STD" 0.226)
(list "40" 0.226)(list "XS" 0.318)(list "80" 0.318)
(list "XXS" 0.636)(list "A" 5.25)(list "B" 2.25)
(list "D" 3.5)(list "E" 2.5)(list "C" 3.75))
(list "4" (list "OD" 4.5)(list "5S" 0.083)(list "5" 0.083)
(list "10S" 0.120)(list "10" 0.120)(list "STD" 0.237)
(list "40" 0.237)(list "60" 0.281)(list "XS" 0.337)
(list "80" 0.337)(list "120" 0.437)(list "160" 0.531)
(list "XXS" 0.674)(list "A" 6.0)(list "B" 2.5)
(list "D" 4.0)(list "E" 2.5)(list "C" 4.125))
(list "4 1/2" (list "OD" 5.0)(list "STD" 0.247)(list "XS" 0.355)
(list "XXS" 0.710))
(list "5" (list "OD" 5.563)(list "5S" 0.109)(list "5" 0.109)
(list "10S" 0.134)(list "10" 0.134)(list "STD" 0.258)
(list "40" 0.258)(list "XS" 0.375)(list "80" 0.375)
(list "120" 0.5)(list "160" 0.625)(list "XXS" 0.750)
(list "A" 7.5)(list "B" 3.125)(list "D" 5.0)
(list "E" 3.0)(LIST "C" 4.875))
(list "6" (list "OD" 6.625)(list "5S" 0.109)(list "5" 0.109)
(list "10S" 0.134)(list "10" 0.134)(list "STD" 0.280)
(list "40" 0.280)(list "XS" 0.432)(list "80" 0.432)
(list "120" 0.562)(list "160" 0.718)(list "XXS" 0.864)
(list "A" 9.0)(list "B" 3.75)(list "D" 6.0)
(list "E" 3.5)(list "C" 5.625))
(list "7" (list "OD" 7.625)(list "STD" 0.301)(list "XS" 0.5)
(list "XXS" 0.875))
(list "8" (list "OD" 8.625)(list "5S" 0.109)(list "5" 0.109)
(list "10S" 0.148)(list "10" 0.148)(list "20" 0.250)
(list "30" 0.277)(list "STD" 0.322)(list "40" 0.322)
(list "60" 0.406)(list "XS" 0.5)(list "80" 0.5)
(list "100" 0.593)(list "120" 0.718)(list "140" 0.812)
(list "160" 0.906)(list "XXS" 0.875)(list "A" 12.0)
(list "B" 5.0)(list "D" 8.0)(list "E" 4.0)(list "C" 7.0))
(list "9" (list "OD" 9.625)(list "STD" 0.342)(list "XS" 0.5)(list "A" nil))
(list "10" (list "OD" 10.75)(list "5S" 0.134)(list "5" 0.134)
(list "10S" 0.165)(list "10" 0.165)(list "20" 0.250)
(list "30" 0.307)(list "STD" 0.365)(list "40" 0.365)
(list "60" 0.5)(list "XS" 0.5)(list "80" 0.593)
(list "100" 0.718)(list "120" 0.843)(list "140" 1.0)
(list "160" 1.125)(list "A" 15.0)(list "B" 6.25)
(list "D" 10.0)(list "E" 5.0)(list "C" 8.5))
(list "11" (list "OD" 11.75)(list "STD" 0.375)(list "XS" 0.5)(list "A" nil))
(list "12" (list "OD" 12.75)(list "5S" 0.156)(list "5" 0.165)
(list "10S" 0.180)(list "10" 0.180)(list "20" 0.250)
(list "30" 0.330)(list "STD" 0.375)(list "40" 0.406)
(list "60" 0.562)(list "XS" 0.5)(list "80" 0.687)
(list "100" 0.843)(list "120" 1.0)(list "140" 1.125)
(list "160" 1.312)(list "A" 18.0)(list "B" 7.5)
(list "D" 12.0)(list "E" 6.0)(list "C" 10.0))
(list "14" (list "OD" 14.0)(list "5S" 0.156)(list "10S" 0.188)
(list "10" 0.250)(list "20" 0.312)(list "30" 0.375)
(list "STD" 0.375)(list "40" 0.437)(list "60" 0.593)
(list "XS" 0.500)(list "80" 0.750)(list "100" 0.937)
(list "120" 1.093)(list "140" 1.25)(list "160" 1.406)
(list "A" 21.0)(list "B" 8.75)(list "D" 14.0)
(list "E" 6.5)(list "C" 11.0))
(list "16" (list "OD" 16.0)(list "5S" 0.165)(list "10S" 0.188)
(list "10" 0.250)(list "20" 0.312)(list "30" 0.375)
(list "STD" 0.375)(list "40" 0.50)(list "60" 0.656)
(list "XS" 0.5)(list "80" 0.843)(list "100" 1.031)
(list "120" 1.218)(list "140" 1.437)(list "160" 1.593)
(list "A" 24.0)(list "B" 10.0)(list "D" 16.0)
(list "E" 7.0)(list "C" 12.0))
(list "18" (list "OD" 18.0)(list "5S" 0.165)(list "10S" 0.188)
(list "10" 0.250)(list "20" 0.312)(list "30" 0.437)
(list "STD" 0.375)(list "40" 0.562)(list "60" 0.75)
(list "XS" 0.5)(list "80" 0.937)(list "100" 1.156)
(list "120" 1.375)(list "140" 1.562)(list "160" 1.781)
(list "A" 27.0)(list "B" 11.25)(list "D" 18.0)
(list "E" 8.0)(list "C" 13.5))
(list "20" (list "OD" 20.0)(list "5S" 0.188)(list "10S" 0.218)
(list "10" 0.250)(list "20" 0.375)(list "30" 0.5)
(list "STD" 0.375)(list "40" 0.593)(list "60" 0.812)
(list "XS" 0.5)(list "80" 1.031)(list "100" 1.28)
(list "120" 1.5)(list "140" 1.75)(list "160" 1.968)
(list "A" 30.0)(list "B" 12.5)(list "D" 20.0)
(list "E" 9.0)(list "C" 15.0))
(list "24" (list "OD" 24.0)(list "5S" 0.218)(list "10S" 0.250)
(list "10" 0.250)(list "20" 0.375)(list "30" 0.562)
(list "STD" 0.375)(list "40" 0.687)(list "60" 0.968)
(list "XS" 0.5)(list "80" 1.218)(list "100" 1.531)
(list "120" 1.812)(list "140" 2.062)(list "160" 2.343)
(list "A" 36.0)(list "B" 15.0)(list "D" 24.0)
(list "E" 10.5)(list "C" 17.0))
)
)
(setq avatar
'( 8 253 253 253 253 9 252 253 253 252 252 252 254 253 253 253 253 253 253 252 2
53 252 252 253 252 253 9 253 254 253 253 252
8 253 8 252 253 9 253 9 253 253 253 253 9 253 9 253 253 253 253 253 253 253 253
253 253 9 253 253 253 252 9 253
253 9 253 9 9 253 252 253 253 253 253 253 253 253 9 253 253 9 253 9 252 9 253 9
253 253 9 253 9 253 253 9
252 253 9 9 253 9 253 253 252 253 253 253 17 16 14 16 16 16 18 16 39 9 253 9 253
253 253 8 9 9 9 254
9 253 9 253 252 253 253 253 253 9 9 254 17 12 14 14 14 14 14 14 17 9 252 253 252
253 253 252 9 253 253 253
9 253 9 253 253 9 253 253 252 253 253 253 17 12 14 14 14 14 12 12 17 9 253 9 253
253 9 252 253 252 253 9
253 253 253 252 8 253 253 253 253 9 253 9 39 14 12 14 14 12 14 14 27 9 253 253 2
52 253 253 252 9 253 9 9
9 253 252 252 252 253 253 253 253 253 253 9 17 12 12 14 12 12 12 12 17 9 253 9 2
53 253 253 253 253 253 9 254
253 253 253 9 9 254 254 9 253 253 253 9 17 12 14 14 14 12 12 14 17 9 252 253 9 2
53 253 9 253 253 253 253
253 253 253 253 253 253 253 252 253 253 253 253 39 14 12 12 12 12 12 14 17 253 2
52 253 253 253 9 9 253 253 253 253
252 252 251 251 8 252 251 251 8 8 252 8 29 16 16 16 16 16 18 16 29 9 9 253 253 2
53 253 9 253 253 253 252
9 8 54 52 52 52 54 54 54 54 54 54 59 251 8 251 251 8 8 8 96 97 253 253 253 253 2
53 253 253 253 252 253
252 251 54 54 54 54 52 52 52 54 52 54 59 251 251 251 251 251 251 96 94 94 88 8 2
52 253 253 253 9 252 253 253
8 8 54 54 54 54 54 54 54 54 52 56 59 251 251 8 251 251 99 96 94 94 94 94 75 253
9 253 253 252 253 254
252 8 54 52 52 52 52 52 52 54 54 46 59 8 8 8 8 109 94 94 92 94 94 92 94 97 252 9
9 252 253 9
252 252 54 54 54 54 52 54 54 54 52 54 67 8 8 251 251 94 94 94 92 94 92 92 94 94
96 252 253 252 253 9
253 8 54 52 54 54 52 52 54 52 52 54 67 8 8 251 96 94 94 92 92 94 92 92 94 94 94
96 87 252 253 253
254 252 52 52 52 54 52 54 54 62 52 52 67 8 251 86 92 94 94 94 94 96 96 92 94 94
94 92 94 86 253 253
253 251 54 54 52 54 52 54 54 54 54 54 59 251 99 94 92 94 92 94 92 92 92 94 96 94
94 92 92 92 96 252
9 8 54 52 54 54 52 54 52 54 42 52 66 251 94 94 94 94 92 94 94 92 94 92 92 92 94
92 94 94 97 9
253 251 54 52 52 54 52 54 52 54 54 52 58 96 94 94 94 94 92 94 92 92 92 92 94 94
94 94 94 99 253 253
8 252 251 8 251 8 251 8 8 8 251 251 251 86 94 94 94 94 92 94 94 92 94 94 94 92 9
4 94 96 253 253 9
253 253 253 253 253 253 253 254 253 252 253 253 253 253 99 94 94 92 92 94 94 94
94 94 94 94 94 96 252 9 253 253
252 253 9 253 253 9 253 253 8 253 253 253 252 253 253 77 94 92 92 94 94 94 96 94
94 94 96 85 253 9 252 253
252 253 9 253 253 253 253 253 253 253 254 253 252 9 253 253 253 86 94 94 94 92 9
2 94 92 92 97 254 9 9 252 8
254 253 253 253 253 253 253 9 253 252 9 253 253 254 252 253 253 252 89 94 94 94
92 94 92 86 253 253 252 252 253 252
253 253 253 9 252 253 253 253 253 253 9 253 9 253 8 9 254 9 9 8 84 92 92 94 86 8
253 253 253 252 253 253
252 253 252 253 252 9 253 253 252 253 253 9 253 252 252 253 253 253 252 253 253
97 94 94 8 253 253 253 253 253 254 252
253 253 253 253 253 9 9 254 253 9 253 253 252 253 9 253 9 9 253 253 9 253 87 97
9 253 253 9 253 9 9 8
252 253 253 9 253 253 253 253 253 9 252 9 253 9 253 253 9 9 253 253 253 252 253
252 253 253 252 253 252 253 253 253
252 253 252 253 252 253 253 253 253 8 252 9 253 253 253 253 9 253 8 253 9 252 25
3 252 9 9 252 253 253 253 253 252
8 253 254 9 253 253 253 253 253 252 253 254 252 9 253 253 253 253 253 254 253 25
3 253 9 9 9 252 253 253 253 253 9)
)
;; ;
;; If the current Version of the DCL is not found in the TEMP directory, ;
;; then the file is generated. ;
;; ;
;; Previous version of the DCL are not erased, User is expected to maintain ;
;; his temp directory manually. ;
;; ;
(defun generatedcl (/ fn f)
(setq fn (strcat (getvar 'TEMPPREFIX) "Pipe" pipeversion ".dcl"))
(if (not (findfile fn)) (make_dcl fn))
(load_dialog fn)
)
(defun make_dcl (fn)
(setq f (open fn "w"))
(write-line "pipe : dialog { "f)
(write-line (strcat "label = \"Pipe " pipeversion " by R.P.\"; ")f)
(write-line " : boxed_column { "f)
(write-line " label = \"Settings\"; "f)
(write-line " : row { "f)
(write-line " : text { "f)
(write-line " label = \"Pipe Size : \"; "f)
(write-line " } "f)
(write-line " : popup_list { "f)
(write-line " horizontal_margin= none; "f)
(write-line " width = 8; "f)
(write-line " fixed_width = true; "f)
(write-line " key = \"siz\"; "f)
(write-line " } "f)
(write-line " } "f)
(write-line " : row { "f)
(write-line " : text { "f)
(write-line " label = \"Pipe Schedule : \"; "f)
(write-line " } "f)
(write-line " : popup_list { "f)
(write-line " horizontal_margin = none; "f)
(write-line " width = 8; "f)
(write-line " fixed_width = true; "f)
(write-line " key = \"sch\"; "f)
(write-line " } "f)
(write-line " } "f)
(write-line " } "f)
(write-line " : boxed_column { "f)
(write-line " label = \"Commands\"; "f)
(write-line " : button { "f)
(write-line " label = \"Elbow &90 Long\"; "f)
(write-line " key = \"elbow90l\"; "f)
(write-line " alignment = centered; "f)
(write-line " width =22; "f)
(write-line " fixed_width = true; "f)
(write-line " } "f)
(write-line " : button { "f)
(write-line " label = \"Elbow 9&0 Short\"; "f)
(write-line " key = \"elbow90s\"; "f)
(write-line " alignment = centered; "f)
(write-line " width = 22; "f)
(write-line " fixed_width = true; "f)
(write-line " } "f)
(write-line " : button { "f)
(write-line " label = \"Elbow &180 Long\"; "f)
(write-line " key = \"elbow180l\"; "f)
(write-line " alignment = centered; "f)
(write-line " width = 22; "f)
(write-line " fixed_width = true; "f)
(write-line " } "f)
(write-line " : button { "f)
(write-line " label = \"Elbow 1&80 Short\"; "f)
(write-line " key = \"elbow180s\"; "f)
(write-line " alignment = centered; "f)
(write-line " width = 22; "f)
(write-line " fixed_width = true; "f)
(write-line " } "f)
(write-line " : button { "f)
(write-line " label = \"&Tee\"; "f)
(write-line " key = \"tee\"; "f)
(write-line " alignment = centered; "f)
(write-line " width = 22; "f)
(write-line " fixed_width = true; "f)
(write-line " } "f)
(write-line " : button { "f)
(write-line " label = \" Straight &Pipe \"; "f)
(write-line " key = \"pipe\"; "f)
(write-line " alignment = centered; "f)
(write-line " width = 22; "f)
(write-line " fixed_width = true; "f)
(write-line " } "f)
(write-line " } "f)
(write-line " : row { "f)
(write-line " : column { "f)
(write-line " spacer; "f)
(write-line " : button { "f)
(write-line " label = \"Cancel\"; "f)
(write-line " key = \"cancel\"; "f)
(write-line " alignment = right; "f)
(write-line " width = 12; "f)
(write-line " fixed_width = true; "f)
(write-line " is_default = true; "f)
(write-line " } "f)
(write-line " } "f)
(write-line " : column { "f)
(write-line " : image_button { "f)
(write-line " key = \"avatar\"; "f)
(write-line " aspect_ratio = 1; "f)
(write-line " width = 5.3; "f)
(write-line " fixed_width = true; "f)
(write-line " fixed_height = true; "f)
(write-line " alignment = right; "f)
(write-line " color = -15; "f)
(write-line " } "f)
(write-line " } "f)
(write-line " } "f)
(write-line "} "f)
(close f)
)
;; ;
;; onleft_p by ymg ;
;; ;
;; Returns t if point is strictly on left of vector. ;
;; ;
;; Arguments: p, Point ;
;; v1, First point of vector. ;
;; v2, Second point of vector v1->v2 ;
;; ;
;; ;
(defun onleft_p (p v1 v2 / xp yp)
(setq xp (car p) yp (cadr p))
(minusp
(- (* (- (cadr v1) yp) (- (car v2) xp)) (* (- (car v1) xp) (- (cadr v2) yp)))
)
)
;; ;
;; signum from std-lib ;
;; ;
;; Returns -1, 0 or 1 if the argument is negative zero or positive ;
;; ;
(defun signum (x) (cond ((minusp x) -1) ((zerop x) 0) (t 1)))
;; ;
;; midpoint ;
;; ;
;; Returns The Midpoint Between Point a and Point b ;
;; ;
(defun midpoint (a b) (mapcar (function (lambda (a b) (* (+ a b) 0.5))) a b))
;; ;
;; trunc by Gille Chanteau ;
;; Retourne la liste tronqu?e ? partir de la premi?re occurrence ;
;; de l'expression (liste compl?mentaire de celle retourn?e par MEMBER) ;
;; ;
;; Arguments ;
;; expr : l'expression recherch?e ;
;; lst : la liste ;
;; ;
(defun trunc (expr lst)
(if (and lst (not (equal (car lst) expr)))
(cons (car lst) (trunc expr (cdr lst)))
)
)
;; ;
;; mk_lin by ymg ;
;; ;
;; Given p1 and p2 (2 points) creates a line on current layer ;
;; Returns the entity name of the line ;
;; ;
(defun mk_lin (p1 p2)
(entmakex (list '(0 . "LINE") (cons 10 p1) (cons 11 p2)))
)
;; ;
;; mk_lwp by Alan J Thompson (Modified by ymg for closed poly) ;
;; ;
;; Argument: pl, A list of points (2d or 3d) ;
;; Create an LWPolyline at Elevation 0, on Current Layer. ;
;; Return: Entity Name ;
;; ;
(defun mk_lwp (pl / isclosed)
(setq isclosed 0)
(if (equal (car pl) (last pl) 0.001)
(setq isclosed 1 pl (cdr pl))
)
(entmakex
(append (list '(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
(cons 90 (length pl))
(cons 70 isclosed)
)
(mapcar '(lambda (p) (cons 10 (trans (list (car p) (cadr p)) 1 0))) pl)
)
)
)
;; ;
;; mk_arc by ymg ;
;; ;
;; Argument: c, Center Point of Arc ;
;; r, Radius of Arc ;
;; a1, Orientation at Start ;
;; a2, Orientation at End ;
;; ;
;; Return: Entity Name ;
;; ;
(defun mk_arc (c r a1 a2)
(entmakex
(list (cons 0 "ARC")
(cons 10 c)
(cons 40 r)
(cons 50 a1)
(cons 51 a2)
)
)
)
;; ;
;; mk_layer by CAB at TheSwamp.org ;
;; Optionnal Arguments by ymg. ;
;; Routine to ENTAKE a Layer entity. ;
;; ;
;; If the layer already exist, it will be: thawed ;
;; set on ;
;; unlocked ;
;; set as the current layer. ;
;; ;
(defun mk_layer (argl / ent lay Color ltype)
(setq lay (car argl) color (cadr argl) ltype (caddr argl))
(if (tblsearch "LAYER" lay)
(progn
(if color (setq ent (entget (tblobjname "LAYER" lay))
ent (subst (cons 62 color) (assoc 62 ent) ent)
ent (entmod ent)
)
)
(if ltype (setq ent (entget (tblobjname "LAYER" lay))
ent (subst (cons 6 ltype) (assoc 6 ent) ent)
ent (entmod ent)
)
)
(vl-cmdf "._Layer" "_Thaw" lay "_On" lay "_UnLock" lay "_Set" lay "" )
)
(entmakex
(list (cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 2 lay)
(cons 70 0)
(cons 62 (if (or (null color)(= Color "")) 7 Color))
(cons 6 (if (or (null ltype)(= ltype "")) "Continuous" ltype))
(cons 290 1)
(cons 370 -3)
)
)
)
(setvar 'CLAYER lay)
)
;; delvertex -Gilles Chanteau- gile@TheSwamp 2007-04-23 ;
;; Delete the selected vertex of a polyline (lw, 2d or 3d) ;
;; ;
;; 2007-10_05 widths behavior corrected ;
;; Modified into a callable subroutine by ymg ;
(defun delvertex (pt en / obj os pt en typ plst par blst n wlst)
;; SPLIT-LIST Split a list into sub-lists (gile) ;
;; Arguments ;
;; - lst : the list to be splited ;
;; - num : an integer, the number of items of sub-lists ;
(defun split-list (lst n)
(if lst
(cons (sublist lst 0 n)
(split-list (sublist lst n nil) n)
)
)
)
;; SUBLIST Return a sub-list (gile) ;
;; ;
;; Arguments ;
;; lst : a list ;
;; start : start index for the sub-list (first item = 0) ;
;; leng : sub-list length (or nil) ;
;; ;
(defun sublist (lst start leng / n r)
(if (or (not leng) (vla-object en))
(setq typ (vla-get-ObjectName obj))
(if (and (setq plst (if (= typ "AcDbPolyline")
(split-list (vlax-get obj 'Coordinates) 2)
(split-list (vlax-get obj 'Coordinates) 3)
)
)
(> (length plst) 2)
)
(progn
(setq pt (trans pt 1 0)
par (cond
((equal pt (vlax-curve-getStartPoint en) 1e-9) 0)
((equal pt (vlax-curve-getEndPoint en) 1e-9) (1- (length plst)))
(t (atoi (rtos (vlax-curve-getParamAtPoint en pt) 2)))
)
blst nil
wlst nil
n 0
)
(if (/= typ "AcDb3dPolyline")
(progn
(repeat (length plst)
(if (/= n par)
(setq blst (cons (cons (length blst) (vla-getBulge obj n)) blst))
)
(setq n (1+ n))
)
(if (/= 0 par)
(progn
(vla-getWidth obj (1- par) 'swid1 'ewid1)
(vla-getWidth obj par 'swid2 'ewid2)
(setq wlst (cons (list (1- par) swid1 ewid2) wlst))
)
)
(repeat (- (setq n (1- (fix (vlax-curve-getEndParam en)))) par)
(vla-getWidth obj n 'swid 'ewid)
(setq wlst (cons (list (setq n (1- n)) swid ewid) wlst))
)
)
)
(vlax-put obj 'Coordinates (apply 'append (vl-remove (nth par plst) plst)))
(or (= typ "AcDb3dPolyline")
(and (mapcar '(lambda (x) (vla-setBulge obj (car x) (cdr x))) blst)
(mapcar '(lambda (x) (vla-setWidth obj (car x) (cadr x) (caddr x))) wlst)
)
)
)
(if (> (length plst) 2)
(alert "\nInvalid Entity")
(alert "\nThe polyline had only two vertices.")
)
)
(entget en)
)
;; ;
;; LoadLineType by MICHAEL PUCKETT ;
;; ;
(defun LoadLineTypes ( lineTypeSpec lineTypeFileName / result )
(if (findfile lineTypeFileName)
(vl-catch-all-apply
'(lambda ( )
(vla-load
(vla-get-linetypes
(vla-get-activedocument
(vlax-get-acad-object)
)
)
lineTypeSpec
lineTypeFileName
)
(setq result t)
)
)
)
result
)
;; ;
;; tolayer by Vovka ;
;; ;
;; Given a Layer Name and a Selection Set, ;
;; Will change the layer of all entities in Set to the new one. ;
;; ;
(defun tolayer (lay ss / i ent )
(repeat (setq i (sslength ss))
(entmod
(subst
(cons 8 lay)
(assoc 8 (setq ent (entget (ssname ss (setq i (1- i))))))
ent
)
)
)
)
; ;
; mk_elbow by ymg ;
; ;
; This routine Draws All Elbows ;
;; ;
;; Parameters: ip, Insertion Point ;
;; rc, Dimension A or D from pipe data list ;
;; od, Outside Diameter of Elbow ;
;; thk, Wall Thickness ;
;; sta, Start Angle ;
;; ena, End Angle ;
;; ;
;; Returns: Selection Set of All Entities Created. ;
;; ;
;; Notes: Requires mk_arc, mk_lin and mk_layer ;
;; Variables outside, inside and center are defined in Main Program ;
;; ;
(defun mk_elbow (elbang ipdir rc od thk / ** a1 a2 ang cp dir ena i ip l1 l2
od/2 od/4 p3 p4 r1 r2 r3 r4 rda ss sta tmp)
(setq ip (car ipdir)
dir (cadr ipdir)
ang (dtr elbang)
rda (+ dir (* pi/2 (signum ang)))
sta (+ rda pi)
ena (+ sta ang)
)
(if (minusp ang)
(setq tmp sta sta ena ena tmp)
)
(setq ip (car ipdir)
ss (ssadd)
od/2 (/ od 2)
od/4 (/ od 4)
cp (polar ip rda rc)
r1 (- rc od/2) r2 (+ rc od/2)
r3 (+ r1 thk) r4 (- r2 thk)
** (mk_layer outside)
a1 (mk_arc cp r1 sta ena)
a2 (mk_arc cp r2 sta ena)
l1 (mk_lin (vlax-curve-getStartPoint a1) (vlax-curve-getStartPoint a2))
l2 (mk_lin (vlax-curve-getEndPoint a1) (vlax-curve-getEndPoint a2))
)
(setvar 'PEDITACCEPT 1)
(command "_PEDIT" "_M" a1 a2 l1 l2 "" "_J" "" "")
(ssadd (setq entr (entlast)) ss)
(mk_layer inside)
(ssadd (mk_arc cp r3 sta ena) ss)
(ssadd (mk_arc cp r4 sta ena) ss)
(mk_layer center)
(setq a1 (mk_arc cp rc sta ena)
l1 (if (not (caddr ipdir)) (mk_lin ip (polar ip dir (- od/4))))
p3 (if (minusp ang) (vlax-curve-getstartPoint a1) (vlax-curve-getEndPoint a1))
p4 (if (minusp ang) (polar p3 (- sta pi/2) od/4) (polar p3 (+ ena pi/2) od/4))
l2 (mk_lin p3 p4)
)
(if (caddr ipdir)
(command "_PEDIT" "_M" a1 l2 "" "_J" "" "")
(command "_PEDIT" "_M" a1 l1 l2 "" "_J" "" "")
)
(ssadd (entlast) ss)
(setq pdir (polar ip dir 100)
loop t
)
(while loop
(setq code (grread t 8))
(cond
((= (car code) 5) (cond
((minusp ang) (if (onleft_p (cadr code) ip pdir)
(progn
(repeat (setq i (sslength ss))
(entdel (ssname ss (setq i (1- i))))
)
(mk_elbow (- (rtd ang)) ipdir rc od thk)
)
))
(t (if (not (onleft_p (cadr code) ip pdir))
(progn
(repeat (setq i (sslength ss))
(entdel (ssname ss (setq i (1- i))))
)
(mk_elbow (- (rtd ang)) ipdir rc od thk)
)
))
))
((= (car code) 3) (setq loop nil)) ; Left Click, Exit the loop ;
((= (car code) 25) (setq loop nil)) ; Right Click, Exit the loop ;
((equal code '(2 13)) (setq loop nil)) ; Enter, Exit the loop. ;
((equal code '(2 32)) (setq loop nil)) ; Space, Exit the loop. ;
)
)
)
;; ;
;; get_ip-dir by ymg ;
;; ;
;; On picking an insertion point, the routine computes the direction of ;
;; the nearest endpoint on the Center line on a fitting or oipe length. ;
;; ;
;; Returns: A list of 3 items: (Insertion point, Direction to Endpoint ;
;; Ename of Pickked center line) ;
(defun get_ip-dir (/ ang en ep ip ll sp ss sz ur)
(setq ip (getpoint "\nPick Insertion Point: ")
od/4 (/ od 4)
ll (list (- (car ip) od/4) (- (cadr ip) od/4))
ur (list (+ (car ip) od/4) (+ (cadr ip) od/4))
ss (ssget "_C" ll ur (list (cons 8 (car center))))
)
(cond
((not ss) (setq ang 0))
(t (setq en (ssname ss 0)
pl (listpol en)
sp (vlax-curve-getstartpoint en)
ep (vlax-curve-getendpoint en)
)
(if (< (distance ip sp) (distance ip ep))
(setq ang (angle ip sp) ent (delvertex sp en))
(setq ang (angle ip ep) ent (delvertex ep en))
))
)
(list ip ang en)
)
(defun spipe (/ ang ep ipdir len od/2 os p1 p2 p3 p4 sp ss)
(vla-startundomark *acdoc*)
(setq ipdir (get_ip-dir)
sp (car ipdir)
ep (if (not (caddr ipdir))
(getpoint sp "\n Pick End point of Pipe: ")
(getpoint sp "\n Pick End point of Pipe: ")
)
od/2 (/ od 2)
os (- od/2 thk)
len (* (distance sp ep) fac)
ang (angle sp ep)
ss (ssadd)
)
;drawout of center line
(setq p1 (polar sp ang (- od/2)))
(setq p2 (polar ep ang od/2))
(mk_layer center)
(if (caddr ipdir)
(ssadd (mk_lwp (list sp ep p2)) ss)
(ssadd (mk_lwp (list p1 sp ep p2)) ss)
)
(mk_layer outside)
(setq p1 (polar sp (+ ang pi/2) od/2)
p2 (polar ep (+ ang pi/2) od/2)
p3 (polar sp (- ang pi/2) od/2)
p4 (polar ep (- ang pi/2) od/2)
)
(ssadd (mk_lwp (list p3 p1 p2 p4 p3)) ss)
(mk_layer inside)
(setq p1 (polar sp (- ang pi/2) os)
p2 (polar ep (- ang pi/2) os)
)
(ssadd (mk_lin p1 p2) ss)
(setq p1 (polar sp (+ ang pi/2) os)
p2 (polar ep (+ ang pi/2) os)
)
(ssadd (mk_lin p1 p2) ss)
(vla-endundomark *acdoc*)
)
;-----------------------------------------------------------------------------;
(defun elbow90l () (vla-startundomark *acdoc*) (mk_elbow 90 (get_ip-dir) A od th
k) (vla-endundomark *acdoc*))
(defun elbow90s () (vla-startundomark *acdoc*)(mk_elbow 90 (get_ip-dir) D od thk
) (vla-endundomark *acdoc*))
(defun elbow180l () (vla-startundomark *acdoc*)(mk_elbow 180 (get_ip-dir) A od t
hk) (vla-endundomark *acdoc*))
(defun elbow180s () (vla-startundomark *acdoc*)(mk_elbow 180 (get_ip-dir) D od t
hk) (vla-endundomark *acdoc*))
(defun tee () (vla-startundomark *acdoc*) (mk_tee (get_ip-dir))(vla-endundomark
*acdoc*))
(defun mk_tee (ipdir / a1 a2 am code ctr ctra dd dir dm ip ipa ipb l1 l2 l3 l4 l
oop
od/2 od/4 p1 p10 p11 p12 p2 p3 p4 p5 p6 p7 p8 p9 pdir pm ss up)
(mk_layer outside)
(setvar 'FILLETRAD thk)
(setq ip (car ipdir)
dir (cadr ipdir)
ss (ssadd)
od/2 (/ od 2)
od/4 (/ od 4)
dd (- C od/2)
p1 (polar ip (+ dir pi/2) od/2)
p2 (polar p1 dir dd)
p3 (polar p2 (+ dir pi/2) dd)
p4 (polar p3 dir od)
p5 (polar p4 (+ dir 3pi/2) dd)
p6 (polar p5 dir dd)
p7 (polar p6 (+ dir 3pi/2) od)
p8 (polar p7 (+ dir pi) (+ dd od dd))
a1 (mk_lwp (list p1 p2 p3))
l1 (mk_lin p3 p4)
a2 (mk_lwp (list p4 p5 p6))
l2 (mk_lin p6 p7)
l3 (mk_lin p7 p8)
l4 (mk_lin p8 p1)
ipa (midpoint p3 p4)
ipb (midpoint p6 p7)
pm (midpoint ip ipb)
am (angle pm ipa)
dm (distance pm ipa)
p9 (polar ip (+ dir pi) od/4)
p10 (polar ipb (+ dir 0) od/4)
p11 (polar ipa (+ dir pi/2) od/4)
p12 (polar ipa (+ dir 3pi/2) (+ dd od od/4))
)
(command "_FILLET" "_P" a1)
(command "_FILLET" "_P" a2)
(command "_OFFSET" thk a1 ip "") (ssadd (entlast) ss)
(command "_OFFSET" thk a2 ip "") (ssadd (entlast) ss)
(command "_OFFSET" thk l3 ip "") (ssadd (entlast) ss)
(tolayer (car inside) ss)
(setvar 'PEDITACCEPT 1)
(command "_PEDIT" "_M" a1 l1 a2 l2 l3 l4 "" "_J" "" "")
(ssadd a1 ss)
(mk_layer center)
(ssadd (setq ctr (mk_lwp (list p9 ip ipb p10))) ss)
(ssadd (setq ctra (mk_lwp (list p11 ipa p12))) ss)
(setq pdir (polar ip dir 100)
loop t
up t
)
(while loop
(setq code (grread t 8))
(cond
((= (car code) 5) (if (and up (not (onleft_p (cadr code) ip pdir)))
(progn
(command "_mirror" ss "" ip pdir "_Y")
(setq up nil ipa (polar pm (+ am pi) dm))
)
)
(if (and (not up) (onleft_p (cadr code) ip pdir))
(progn
(command "_mirror" ss "" ip pdir "_Y")
(setq up t ipa (polar pm am dm))
)
))
((= (car code) 3) (if (caddr ipdir) (delvertex p9 ctr)) ; Left Click, Exit the l
oop ;
(setq loop nil))
((= (car code) 25) (vl-cmdf "_MOVE" ss "" ipa ip) ; Right Click, Insert Tee at C
enter Outlet, ;
(vl-cmdf "_ROTATE" ss "" ip (if up 90 -90)) ; and Exit the loop ;
(if (caddr ipdir) (delvertex p9 ctra))
(setq loop nil))
((equal code '(2 13)) (setq loop nil)) ; Enter, Exit the loop. ;
((equal code '(2 32)) (setq loop nil)) ; Space, Exit the loop. ;
)
)
)
(defun c:pp () (c:pipe))
(defun c:pipe (/ DDIAG)
(vl-load-com)
;;; Error Handler by ElpanovEvgenyi ;
(defun *error* (msg)
(mapcar 'eval varl)
(if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")))
(princ (strcat "\nError: " msg))
)
(princ)
)
(setq varl '("CLAYER" "OSMODE" "CMDECHO" "PEDITACCEPT" "PICKBOX" "ORTHOMODE")
varl (mapcar (function (lambda (a) (list 'setvar a (getvar a)))) varl)
)
(or *acdoc* (setq *acdoc* (vla-get-activedocument (vlax-get-acad-object))))
(setvar 'CMDECHO 0)
(LoadlineTypes "HIDDEN" "ACAD.LIN")
(LoadlineTypes "CENTER" "ACAD.LIN")
(if (= (getvar "LUNITS") 2) (setq fac 25.4) (setq fac 1.0))
(setq sizl (mapcar 'car pipe))
(setq ddiag nil)
(while (not (equal ddiag "cancel"))
(setvar 'ORTHOMODE 1)
(setvar 'OSMODE 32)
(princ "\n!!Choose Command in Dialog Box!! ")
(princ)
(setq dcl_id (generatedcl))
(if (not (new_dialog "pipe" dcl_id "3" (if dlgpos dlgpos '(-1 -1)))) (exit))
(start_list "siz" )
(mapcar 'add_list sizl)
(end_list)
(if (not sizn) (setq sizn "4" sizp (itoa (vl-position sizn sizl)) sch "40"))
(setq size (cdr (assoc sizn pipe))
sizp (itoa (vl-position sizn sizl))
schl (mapcar 'car (cdr (trunc (car (member (assoc "A" size) size)) size)))
schp (if (setq pos (vl-position sch schl)) (itoa pos) "0")
thk (* (cadr (assoc sch size)) fac)
od (* (cadr (assoc "OD" size)) fac)
A (cadr (assoc "A" size))
D (cadr (assoc "D" size))
C (cadr (assoc "C" size))
)
(if A
(progn (setq A (* A fac)) (mode_tile "elbow90l" 0) (mode_tile "elbow180l" 0))
(progn (mode_tile "elbow90l" 1) (mode_tile "elbow180l" 1))
)
(if D
(progn (setq D (* D fac)) (mode_tile "elbow90s" 0) (mode_tile "elbow180s" 0))
(progn (mode_tile "elbow90s" 1) (mode_tile "elbow180s" 1))
)
(if C (progn (setq C (* C fac))(mode_tile "tee" 0)) (mode_tile "tee" 1))
(set_tile "siz" sizp)
(start_list "sch" )
(mapcar 'add_list schl)
(end_list)
(set_tile "sch" schp)
(action_tile "siz" "(setq sizp $value
sizn (nth (atoi sizp) sizl)
size (cdr (assoc sizn pipe))
schl (mapcar 'car (cdr (trunc (car (member (assoc \"A\" size) size)) size)))
schp (if (setq pos (vl-position sch schl)) (itoa pos) \"0\")
sch (nth (atoi schp) schl)
thk (* (cadr (assoc sch size)) fac)
od (* (cadr (assoc \"OD\" size)) fac)
A (cadr (assoc \"A\" size))
D (cadr (assoc \"D\" size))
C (cadr (assoc \"C\" size))
)
(if A
(progn (setq A (* A fac)) (mode_tile \"elbow90l\" 0) (mode_tile \"elbow180l\" 0)
)
(progn (mode_tile \"elbow90l\" 1) (mode_tile \"elbow180l\" 1))
)
(if D
(progn (setq D (* D fac)) (mode_tile \"elbow90s\" 0) (mode_tile \"elbow180s\" 0)
)
(progn (mode_tile \"elbow90s\" 1) (mode_tile \"elbow180s\" 1))
)
(if C (progn (setq C (* C fac))(mode_tile \"tee\" 0)) (mode_tile \"tee\" 1))
(start_list \"sch\" )
(mapcar 'add_list schl)
(end_list)
(set_tile \"sch\" schp)"
)
(action_tile "sch" "(setq schp (get_tile \"sch\")
sch (nth (atoi schp) schl)) ")
(action_tile "elbow90l" "(setq ddiag '(elbow90l) dlgpos (done_dialog))")
(action_tile "elbow90s" "(setq ddiag '(elbow90s) dlgpos (done_dialog))")
(action_tile "elbow180l" "(setq ddiag '(elbow180l) dlgpos (done_dialog))")
(action_tile "elbow180s" "(setq ddiag '(elbow180s) dlgpos (done_dialog))")
(action_tile "tee" "(setq ddiag '(tee) dlgpos (done_dialog))")
(action_tile "pipe" "(setq ddiag '(spipe) dlgpos (done_dialog))")
(action_tile "cancel" "(setq ddiag $key dlgpos (done_dialog))")
(start_image "avatar")
(fill_image 0 0 (dimx_tile "avatar") (dimy_tile "avatar") -15)
(setq i 0)
(foreach c avatar
(setq i (1+ i) x (/ i 32) y (- i (* x 32)))
(fill_image x y 1 1 c)
)
(end_image)
(start_dialog)
(unload_dialog dcl_id)
(eval ddiag)
)
(*error* nil)
)
(princ (strcat "\nPipe.lsp " pipeversion))
(princ "\nType PIPE or PP to Start: ")
(c:pp)
;-----------------------------------------------------------------------------;
; THE END ;
;-----------------------------------------------------------------------------;
Draw Circle (Pipe Section) with user defined diameter on user defined layer with
Associative Centerlines
21
Wednesday
Dec 2016
Posted by danglar71 in draw, Pipes
? Leave a comment

;;; Draw pipe section with user defined diameter on user defined layer with Asso
ciative Centerlines
;;; Based on Lee Mac and Luca Romanini routines saved from: http://forums.autode
sk.com/t5/visual-lisp-autolisp-and-general/lisp-circle/m-p/6642280#U6642280
;;; Combined by Igal Averbuh 2016 (adapted to cm. units)
;;--------------=={ Associative Centerlines }==---------------;;
;; ;;
;; Uses reactors to update centerlines following ;;
;; modification of associated circles. Stores entity handles ;;
;; in entity xData to enable reactor rebuild upon loading, ;;
;; allowing retention of associativity between sessions. ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright ?2011 - http://www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Version 1.0 - 12-05-2011 ;;
;;------------------------------------------------------------;;
(setq cl:ratio 1.25 cl:app "LMAC_CL")
;;------------------------------------------------------------;;
(defun c:CL ( / _line ss e c r l1 l2 )
(vl-load-com)
(if (= (tblsearch "ltype" "center") nil)
(command "linetype" "l" "center" "acad.lin" "")
)
(if
(and
(setq ss
(ssget "L"
(list '(0 . "CIRCLE") '(-4 . ""))
)
)
(or (tblsearch "APPID" cl:app) (regapp cl:app))
)
(progn
(defun _line ( p1 p2 h )
(entmakex
(list (cons 0 "LINE") (cons 10 p1) (cons 11 p2) (cons 6 "center")
(list -3
(list cl:app
(cons 1002 "{") (cons 1005 h) (cons 1002 "}")
)
)
)
)
)
(repeat (setq i (sslength ss))
(setq e (entget (ssname ss (setq i (1- i))))
h (cdr (assoc 5 e))
c (cdr (assoc 10 e))
r (* cl:ratio (cdr (assoc 40 e)))
l1 (_line (polar c 0. r) (polar c pi r) h)
l2 (_line (polar c (/ pi 2.) r) (polar c (/ (* 3. pi) 2.) r) h)
)
(entmod
(list (assoc -1 e)
(list -3
(list cl:app
(cons 1002 "{")
(cons 1005 (cdr (assoc 5 (entget l1))))
(cons 1005 (cdr (assoc 5 (entget l2))))
(cons 1002 "}")
)
)
)
)
(vlr-object-reactor (list (vlax-ename->vla-object (cdr (assoc -1 e)))) (list cl:
app h)
(list
(cons :vlr-modified 'cl:circle:callback)
)
)
(vlr-object-reactor (mapcar 'vlax-ename->vla-object (list l1 l2)) (list cl:app h
)
(list
(cons :vlr-modified 'cl:line:callback)
)
)
)
)
)
(princ)
)
;;------------------------------------------------------------;;
(defun c:clremove ( / _massoc ss fl i e r d h x )
(defun _massoc ( x l )
(if (setq a (assoc x l))
(cons (cdr a) (_massoc x (cdr (member a l))))
)
)
(princ "\nSelect Circles to Remove Associativity : ")
(setq fl (list '(0 . "CIRCLE") (list -3 (list cl:app))) i -1)
(if
(setq ss
(cond
( (ssget fl) )
( (ssget "_X" fl) )
)
)
(while (setq e (ssname ss (setq i (1+ i)))) (setq e (entget e (list cl:app)))
(foreach r (cdar (vlr-reactors :vlr-object-reactor))
(if
(and
(setq d (vlr-data r))
(listp d)
(eq cl:app (car d))
(or (not (cadr d)) (eq (cdr (assoc 5 e)) (cadr d)))
)
(vlr-remove r)
)
)
(foreach h (_massoc 1005 (cdadr (assoc -3 e)))
(if (setq x (entget (handent h)))
(entmod (list (assoc -1 x) (list -3 (list cl:app))))
)
)
(entmod (list (assoc -1 e) (list -3 (list cl:app))))
)
)
(princ)
)
;;------------------------------------------------------------;;
(defun cl:circle:callback ( owner reactor params / xtyp xval c r )
(if
(and
(vlax-read-enabled-p owner)
(progn (vla-getxdata owner cl:app 'xtyp 'xval) xval)
(setq
c (vlax-get owner 'center)
r (* cl:ratio (vlax-get owner 'radius))
)
)
(mapcar
(function
(lambda ( h a )
(if (or (entget (setq h (handent h))) (entdel h))
(entmod
(list (cons -1 h) (cons 10 (polar c a r)) (cons 11 (polar c (+ a pi) r)))
)
)
)
)
(cddr (mapcar 'vlax-variant-value (vlax-safearray->list xval))) (list 0. (/ pi 2
.))
)
)
(princ)
)
;;------------------------------------------------------------;;
(defun cl:line:callback ( owner reactor params )
(setq *data (list owner reactor))
(vlr-command-reactor (list cl:app)
(list
(cons :vlr-commandended 'cl:line:modify)
(cons :vlr-commandcancelled 'cl:line:cancelled)
(cons :vlr-commandfailed 'cl:line:cancelled)
)
)
(vlr-remove reactor)
(princ)
)
;;------------------------------------------------------------;;
(defun cl:line:modify ( reactor params / xtyp xval h ) (vlr-remove reactor)
(if
(and *data (not (vlax-erased-p (car *data))) (progn (vla-getxdata (car *data) cl
:app 'xtyp 'xval) xval)
(or
(entget
(setq h
(handent
(caddr
(mapcar 'vlax-variant-value (vlax-safearray->list xval))
)
)
)
)
(entdel h)
)
)
(progn
(cl:circle:callback (vlax-ename->vla-object h) nil nil)
(vlr-add (cadr *data))
(setq *data nil)
)
)
(princ)
)
;;------------------------------------------------------------;;
(defun cl:line:cancelled ( reactor params ) (vlr-remove reactor)
(if *data
(progn
(vlr-add (cadr *data))
(setq *data nil)
)
)
(princ)
)
;;------------------------------------------------------------;;
(
(lambda ( / r d s i e o xtyp xval )
(foreach r (cdar (vlr-reactors :vlr-object-reactor))
(if (and (setq d (vlr-data r)) (listp d) (eq cl:app (car d)))
(vlr-remove r)
)
)
(if (setq s (ssget "_X" (list '(0 . "CIRCLE") (list -3 (list cl:app)))))
(repeat (setq i (sslength s))
(setq e (ssname s (setq i (1- i))))
(vlr-object-reactor (list (setq o (vlax-ename->vla-object e))) (list cl:app (cdr
(assoc 5 (entget e))))
(list
(cons :vlr-modified 'cl:circle:callback)
)
)
(vla-getxdata o cl:app 'xtyp 'xval) (setq xval (mapcar 'vlax-variant-value (vlax
-safearray->list xval)))
(vlr-object-reactor
(mapcar
(function
(lambda ( h )
(or (entget (setq h (handent h))) (entdel h)) (vlax-ename->vla-object h)
)
)
(list (caddr xval) (cadddr xval))
)
(list cl:app (cdr (assoc 5 (entget e)))) (list (cons :vlr-modified 'cl:line:call
back))
)
)
)
)
)
(vl-load-com) (princ)
;;------------------------------------------------------------;;
;; End of File ;;
;;------------------------------------------------------------;;
(DEFUN c:dia ( / CNT DIAM INCH P1)
(setq P1 (entsel "\nSelect an object to create the circle in the same layer: "))
(setq CNT (getpoint "\nSelect circle center")) ;click the center of the circle
(initget 1 "2 2.5 3 3.5 4 6 8 10 12 14 16 18 20")
(setq INCH (getkword "\nSelect Diameter: [2 / 2.5 / 3 / 3.5 / 4 / 6 / 8 / 10 / 1
2 / 14 / 16 / 18 / 20]"))
(setq DIAM (cond ((= INCH "2") 6.0325)
((= INCH "2.5") 7.3025)
((= INCH "3") 8.89)
((= INCH "3.5") 10.16)
((= INCH "4") 11.43)
((= INCH "6") 16.83)
((= INCH "8") 21.91)
((= INCH "10") 27.30)
((= INCH "12") 32.38)
((= INCH "14") 35.56)
((= INCH "16") 40.64)
((= INCH "18") 45.72)
((= INCH "20") 50.80)
);End conditional
) ;End setq DIAM
(command "laymcur" P1) ; to move in other layer with a select
(command "circle" "_non" CNT "D" DIAM) ;draw the circle
(command "layerp") ; return in the original layer
(PRINC)
)
(defun c:dc()
(c:dia)
(c:cl)
(princ)
)
(c:dc)

You might also like