TheSwamp

CAD Forums => CAD General => Topic started by: 42 on February 13, 2004, 06:44:57 PM

Title: Return to last layer
Post by: 42 on February 13, 2004, 06:44:57 PM
I have been following the last post with intrest and next to no lisp. You may be intrested in the following file that I have had for a while that I was able to add to enable new layer creation, collection of variables and returning to their original state once finished.
Code: [Select]
;;; INSUL.LSP by Adi Buturovic 1-2-98
;;; Insulation automation
;;; Must have access to Insul.dwg (1x1)
;;;
;;; Modified for scale (1x.38) by J. Tippit 1-2-98
;;; SPAUG President
;;; http://www.tomstreeplace.com/SPAUG
;;; Modified by Alastair Mallett 12-02-04


(defun c:insul (/              pt1            pt2            total_length
                width          horizontal     temp           number_of_blocks
                size_coefficient
               )
  (setq OS (getvar "OSMODE"))(setvar "OSMODE" 1)
  (setq OM (getvar "ORTHOMODE"))(setvar "ORTHOMODE" 0)
  (setq CE (getvar "CMDECHO"))(setvar "CMDECHO" 0)
  (setq BM (getvar "BLIPMODE"))(setvar "BLIPMODE" 0)
  (setq CLYR (getvar"CLAYER")) (command".LAYER""M""A2insulation""C""9""""")
  (setq pt1 (getpoint "Pick first point:"))
  (setq pt2 (getcorner pt1 "Pick other corner:"))
  (setq total_length (abs (- (cadr pt2) (cadr pt1))))
  (setq width (abs (- (car pt2) (car pt1))))
  (setq size_coefficient 0.38) ;_ size coefficient declaration
  (if (setq horizontal (< (cadr pt2) (cadr pt1)))
    (setq temp total_length
          total_length width
          width temp
    )
  )
  (setq number_of_blocks (fix
                           (+ 0.5
                              (/ total_length width size_coefficient)
                           )
                         )
  )
  (if (zerop number_of_blocks)
    (setq number_of_blocks 1)
  )
  (setq height (/ total_length number_of_blocks))
  (command "._minsert"
           "insul"
           pt1
           "x"
           width
           height
           ""
           (if horizontal
             270
             0
           )
           number_of_blocks
           1
           height
(setvar "OSMODE" OS)
(command ".LAYER" "S" CLYR "")
(setvar "ORTHOMODE" OM)
  (setvar "CMDECHO" CE)
  (setvar "BLIPMODE" BM)
  (command".UNDO""end")
  )
)


The lines added are
Code: [Select]
(setq OS (getvar "OSMODE"))(setvar "OSMODE" 1)
  (setq OM (getvar "ORTHOMODE"))(setvar "ORTHOMODE" 0)
  (setq CE (getvar "CMDECHO"))(setvar "CMDECHO" 0)
  (setq BM (getvar "BLIPMODE"))(setvar "BLIPMODE" 0)
  (setq CLYR (getvar"CLAYER")) (command".LAYER""M""A2insulation""C""9""""")


and to close

Code: [Select]
(setvar "OSMODE" OS)
(command ".LAYER" "S" CLYR "")
(setvar "ORTHOMODE" OM)
  (setvar "CMDECHO" CE)
  (setvar "BLIPMODE" BM)
  (command".UNDO""end")
Title: Return to last layer
Post by: 42 on February 14, 2004, 06:29:12 AM
You will need the following drawing to use the previous post

http://theswamp.org/lilly.pond/42/Insul.Dwg
Title: Return to last layer
Post by: Keith™ on February 14, 2004, 10:09:34 AM
looks interesting, I will give it a try first thing Monday morning
Title: Return to last layer
Post by: CAB on February 14, 2004, 10:50:37 AM
42,
if you are interested, here is a routine i found awhile back and altered it.
It does not require the block as the insulation is a pline.

CAB

Code: [Select]
;;Routine to draw insulation symbol into roof/ wall sections
;;written by Andrew NIELSEN Melbourne Australia - andysan1@bigpond.com
;; call as <INSUL1>
;;first pick origin of insulation ; second pick end of insulation
;;third pick height of insulation from first pick
;; draws polyline onto layer "insulation"

;; <INSUL2>
;;  Modified by Charles Alan Butler  12/15/2003
;;  Altered error checking & added mirror option

(defun C:INSUL2 (/ SP EP HT OM CE BM DX AN NX NU
             AX PX P1 P2 P3 P4 P5 P6 P7 P8 P9 XT SLST)
             
;; error function & Routine Exit
 (defun *error* (msg)
  (if (not(member msg
'("console break" "Function cancelled" "quit / exit abort" "")
      ))
     (princ (strcat "\nError: " msg))
  ) ; endif
    ;;reset all variables here
    (command".LAYER""S"CLYR"")
    (setvar"OSMODE" OS)
    (setvar"ORTHOMODE" OM)
    (setvar"CMDECHO" CE)
    (setvar"BLIPMODE" BM)
    (command".UNDO""end")
    (princ)
  ) ;end error function

  ;; start routine
  (command".UNDO""group")
  (setq OS (getvar "OSMODE"))   (setvar "OSMODE" 512)
  (setq OM (getvar "ORTHOMODE"))(setvar "ORTHOMODE" 1)
  (setq CE (getvar "CMDECHO"))  (setvar "CMDECHO" 0)
  (setq BM (getvar "BLIPMODE")) (setvar "BLIPMODE" 0)
  (while (= SP nil) (setq SP
    (getpoint "\nPick Start Point of Insulation (Ortho  ON; O/S  Near):  ")))
  (while (= EP nil) (setq EP
    (getpoint SP "\nPick Ending Point of Insulation:  ")))
  (setvar "OSMODE" 0)
  (while (= ht nil)
     (setq ht (getdist EP "\nPick or Enter Height of Insulation: ")))
  (if (and sp ep ht)
    (progn
  (setq CLYR (getvar"CLAYER"))
  (command".LAYER""M""INSULATION""C""8""""")
  (setq AN (angle SP EP)
        DX (distance SP EP)
        NX (/ HT 2)
        NU (/ DX NX)
        NX (/ HT 2)
        AX (+ AN (/ PI 2))
        PX (polar SP AX HT)
        P1 (polar SP AX (/ HT 1.25))
        P2 (polar P1 AN (/ HT 20))
        P3 (polar P1 AN (/ HT 4))
        P4 (polar P2 AN (/ HT 2.5))
        P5 (polar SP AX (/ HT 5))
        P6 (polar P5 AN (/ HT 5))
        P7 (polar P6 AN (/ HT 10))
        P8 (polar P5 AN (/ HT 2))
        P9 (polar SP AN (/ HT 2))
  )
  (setq SLST (ssadd))
  (repeat (fix NU)
    (command ".ARC" "C" P5 SP P6)
    (setq SLST (ssadd (entlast) SLST))
    (command ".LINE" P6 P2 "" )
    (setq SLST (ssadd (entlast) SLST))
    (command ".ARC" P2 "C" P3 "A" "-180" )
    (setq SLST (ssadd (entlast) SLST))
    (command ".LINE" P4 P7 "" )
    (setq SLST (ssadd (entlast) SLST))
    (command ".ARC" "C" P8 P7 P9)
    (setq SLST (ssadd (entlast) SLST))
    (setq SP (polar SP AN NX)
          P2 (polar P2 AN NX)
          P3 (polar P3 AN NX)
          P4 (polar P4 AN NX)
          P5 (polar P5 AN NX)
          P6 (polar P6 AN NX)
          P7 (polar P7 AN NX)
          P8 (polar P8 AN NX)
          P9 (polar P9 AN NX)
    )
  )

  (setq XT (distance SP EP))
  (if (>= XT (/ HT 5))
  (progn
    (command ".ARC" "C" P5 SP P6 )
    (setq SLST (ssadd (entlast) SLST))
    (command ".LINE" P6 P2 "" )
    (setq SLST (ssadd (entlast) SLST))
    (command ".ARC" P2 "C" P3 "A" "-75")
    (setq SLST (ssadd (entlast) SLST))
  )); end if
  (command ".PEDIT" "L" "Y" "J" SLST "" "")
  (initget "Yes No")
  (setq ans (getkword "Mirror Insulation? <No> "))
  (if (= ans "Yes")
    (command ".mirror" "L" "" sp ep "Y")
  )
  )); endif (and sp ep pt)
  (*error* "")
 
);end
(princ)
Title: Return to last layer
Post by: 42 on February 15, 2004, 07:09:03 AM
I use the previous version of this file witout the error checking. What I have found is pline routine increases the file size more than the block. Both have their place, the pline cane be cut to size if required. I will certainally try it out. Thanks.
Well it seems to work, I will replace insul1 with it.