;;; ------------------------------------------------------------------------
;;; 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 FlowDirection)180)) TakeoffSize))
(setq TakeOffPoint3 (polar TakeOffPoint1 TakeOffAngle (/ TakeoffSize 2)))
(setq TakeOffPoint4 (polar TakeOffPoint3 (TAKEOFF_DTR (+ (TAKEOFF_RTD FlowDirection)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" "HIDDEN2" "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" "HIDDEN2" "15" "201" "1")

;; Get takeoff insulation points - INSIDE -
(setq TakeOffPoint10 (polar (polar TakeOffPoint1 (- FlowDirection (TAKEOFF_DTR 180)) 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" "HIDDEN2" "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 180)) 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) TakeOffFlare)))
(setq TakeOffPoint2 (polar TakeOffInsPoint Angle+90 (+ (/ TakeoffSize 2) TakeOffFlare)))
(setq TakeOffPoint3 (polar (polar TakeOffInsPoint Angle-90 (/ TakeoffSize 2)) TakeOffAngle (/ TakeoffSize 2)))
(setq TakeOffPoint4 (polar (polar TakeOffInsPoint Angle+90 (/ TakeoffSize 2)) TakeOffAngle (/ 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" "HIDDEN2" "15" "201" "1")
;; Get takeoff insulation points - OUTSIDE -
(setq TakeOffPoint6 (polar (polar TakeOffPoint1 Angle-90 (TAKEOFF_LAWOFSINE 60 30 1)) TakeOffAngle 1))
(setq TakeOffPoint7 (polar (polar TakeOffPoint2 Angle+90 (TAKEOFF_LAWOFSINE 60 30 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" "HIDDEN2" "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" "HIDDEN2" "15" "201" "1")

;; Get takeoff insulation points - OUTSIDE -
(setq TakeOffPoint6 (polar (polar TakeOffPoint1 Angle-90 (TAKEOFF_LAWOFSINE 60 30 1)) TakeOffAngle 1))
(setq TakeOffPoint7 (polar (polar TakeOffPoint2 Angle+90 (TAKEOFF_LAWOFSINE 60 30 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" "CENTER2" "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 TakeOffInsul /
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 FlowDirection)180)) TakeoffSize))
(setq TakeOffPoint3 (polar TakeOffPoint1 TakeOffAngle (/ TakeoffSize 2)))
(setq TakeOffPoint4 (polar TakeOffPoint3 (TAKEOFF_DTR (+ (TAKEOFF_RTD FlowDirection)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 FlowDirection)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 TakeOffBreakPoint1))
(setq TakeOffBreakLine3 (vlax-invoke Space 'addline TakeOffPoint2 TakeOffPoint5))
(setq TakeOffBreakLine4 (vlax-invoke Space 'addline TakeOffPoint2 TakeOffBreakPoint2))

;; 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" "HIDDEN2" "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" "HIDDEN2" "15" "201" "1")

;; Get takeoff insulation points - INSIDE -
(setq TakeOffPoint10 (polar (polar TakeOffPoint1 (- FlowDirection (TAKEOFF_DTR 180)) 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" "HIDDEN2" "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 180)) 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) TakeOffFlare)))
(setq TakeOffPoint2 (polar TakeOffInsPoint Angle+90 (+ (/ TakeoffSize 2) TakeOffFlare)))
(setq TakeOffPoint3 (polar (polar TakeOffInsPoint Angle-90 (/ TakeoffSize 2)) TakeOffAngle (/ TakeoffSize 2)))
(setq TakeOffPoint4 (polar (polar TakeOffInsPoint Angle+90 (/ TakeoffSize 2)) TakeOffAngle (/ 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 TakeOffBreakPoint1))
(setq TakeOffBreakLine3 (vlax-invoke Space 'addline TakeOffPoint2 TakeOffPoint5))
(setq TakeOffBreakLine4 (vlax-invoke Space 'addline TakeOffPoint2 TakeOffBreakPoint2))

;; 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" "HIDDEN2" "15" "201" "1")
;; Get takeoff insulation points - OUTSIDE -
(setq TakeOffPoint6 (polar (polar TakeOffPoint1 Angle-90 (TAKEOFF_LAWOFSINE 60 30 1)) TakeOffAngle 1))
(setq TakeOffPoint7 (polar (polar TakeOffPoint2 Angle+90 (TAKEOFF_LAWOFSINE 60 30 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" "HIDDEN2" "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" "HIDDEN2" "15" "201" "1")

;; Get takeoff insulation points - OUTSIDE -
(setq TakeOffPoint6 (polar (polar TakeOffPoint1 Angle-90 (TAKEOFF_LAWOFSINE 60 30 1)) TakeOffAngle 1))
(setq TakeOffPoint7 (polar (polar TakeOffPoint2 Angle+90 (TAKEOFF_LAWOFSINE 60 30 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" "CENTER2" "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 FlowDirection)180)) TakeoffSize))
(setq TakeOffPoint3 (polar TakeOffPoint1 TakeOffAngle (/ TakeoffSize 2)))
(setq TakeOffPoint4 (polar TakeOffPoint3 (TAKEOFF_DTR (+ (TAKEOFF_RTD FlowDirection)180)) TakeoffSize))
(setq TakeOffMidPt1 (polar TakeOffPoint1 (TAKEOFF_DTR (+ (TAKEOFF_RTD FlowDirection)180)) (/ (distance TakeOffPoint1 TakeOffPoint2) 2)))
(setq TakeOffArcPt1 (polar TakeOffMidPt1 (TAKEOFF_DTR (+ (TAKEOFF_RTD TakeOffAngle)180))(/ TakeoffSize 4)))
(setq TakeOffArcPt2 (polar TakeOffArcPt1 TakeOffAngle (setq TakeOffRad (TAKEOFF_GET_RADIUS (distance TakeOffPoint1 TakeOffPoint2)(distance TakeOffMidPt1 TakeOffArcPt1)))))

;; 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" "HIDDEN2" "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" "HIDDEN2" "15" "201" "1")

;; Get takeoff insulation points - INSIDE -
(setq TakeOffPoint10 (polar (polar TakeOffPoint1 (- FlowDirection (TAKEOFF_DTR 180)) 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" "HIDDEN2" "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 180)) 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) TakeOffFlare)))
(setq TakeOffPoint2 (polar TakeOffInsPoint Angle+90 (+ (/ TakeoffSize 2) TakeOffFlare)))
(setq TakeOffPoint3 (polar (polar TakeOffInsPoint Angle-90 (/ TakeoffSize 2)) TakeOffAngle (/ TakeoffSize 2)))
(setq TakeOffPoint4 (polar (polar TakeOffInsPoint Angle+90 (/ TakeoffSize 2)) TakeOffAngle (/ TakeoffSize 2)))
(setq TakeOffMidPt1 (polar TakeOffPoint1 (TAKEOFF_DTR (+ (TAKEOFF_RTD FlowDirection)180)) (/ (distance TakeOffPoint1 TakeOffPoint2) 2)))
(setq TakeOffArcPt1 (polar TakeOffInsPoint (TAKEOFF_DTR (+ (TAKEOFF_RTD TakeOffAngle)180))(/ TakeoffSize 4)))
(setq TakeOffArcPt2 (polar TakeOffArcPt1 TakeOffAngle (setq TakeOffRad (TAKEOFF_GET_RADIUS (distance TakeOffPoint1 TakeOffPoint2)(distance TakeOffMidPt1 TakeOffArcPt1)))))

;; 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" "HIDDEN2" "15" "201" "1")
;; Get takeoff insulation points - OUTSIDE -
(setq TakeOffPoint6 (polar (polar TakeOffPoint1 Angle-90 (TAKEOFF_LAWOFSINE 60 30 1)) TakeOffAngle 1))
(setq TakeOffPoint7 (polar (polar TakeOffPoint2 Angle+90 (TAKEOFF_LAWOFSINE 60 30 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" "HIDDEN2" "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" "HIDDEN2" "15" "201" "1")

;; Get takeoff insulation points - OUTSIDE -
(setq TakeOffPoint6 (polar (polar TakeOffPoint1 Angle-90 (TAKEOFF_LAWOFSINE 60 30 1)) TakeOffAngle 1))
(setq TakeOffPoint7 (polar (polar TakeOffPoint2 Angle+90 (TAKEOFF_LAWOFSINE 60 30 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" "CENTER2" "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 / TmpList 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 CurrentLine 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

Advertisements