stevenw00
2009-08-03, 05:27 PM
Below is part of a lisp I have for inserting a titleblock. I will attach this file as well, so it is available for testing. I have this lisp working perfectly w/ another titleblock and this is a direct Save As of the previous lisp and titleblock. Now I am getting an error. The best I can tell, when the (If (= el (entlast)) line runs, it is coming up as =, and it shouldn't be at that point. Can someone check this thing out and help me? Any other info you need, etc. just let me know and I will get it for you ASAP.
I have 8 different titleblocks I need to modify this Lisp for, so I want to get it RIGHT this time instead of having to mess w/ it 8 different times.
Thanks in advance!
Steven
; ProESubm_FabB.lsp
;;;--------------------------------------------------------------------
;;; M A I N F U N C T I O N
;;;--------------------------------------------------------------------
(princ "\nProESubm_FabB Insert")
(Defun C:ProESubm_FabB (/ OSN LA n0 n1 n2 thei
tlen A0 A1 A2 A3 A00 ws
xscl yscl dwgscl rtio scls R0
R1 P0 P1 P2 P3 shtscl
tx txlist pmt1 edf u uprec
)
(Command "Undo" "Mark")
(Setvar "Cmdecho" 1)
(Setvar "Limcheck" 0)
(Setvar "Blipmode" 1)
(Setq
OSN (Getvar "Osmode")
u (Getvar "Lunits") ;Save Unit type
uprec (Getvar "Luprec") ;Save Unit precision
LA (Getvar "CLAYER") ;Save current layer
)
(Setvar "Osmode" 0)
(Setvar "Lunits" 2)
(Setvar "Luprec" 8)
(Setvar "Plinewid" 0)
;;;--------------------------------------------------------
;;; Set Coordinates for Working on Title Block
;;;--------------------------------------------------------
(Setq
n0 (list 0.0 0.0) ;Lower Left Node
n1 (list 0.07000000 0.90000000) ;Lower Left Bdr Pt
n2 (list 16.25000000 10.20000000) ;Upper Right Bdr Pt
A0 (/ (- (Car n2) (Car n1)) 2) ;Half of drawing width
A1 (/ (- (Cadr n2) (Cadr n1)) 2) ;Half of drawing height
A00 (list (+ (Car n1) A0) (+ (Cadr n1) A1)) ;Center of Dwg Space
)
;;; -----------------------------------------------------
;;; Fill in title block info
;;; -----------------------------------------------------
(Setq
Proc (getstring T "\nEnter Process: ")
Desc1 (getstring T "\nEnter Description Line 1: ")
Desc2 (getstring T "\nEnter Description Line 2: ")
DrwBy (getstring T "\nEnter Drawn By: ")
ChkBy (getstring T "\nEnter Checked By: ")
DwgNo (getstring T "\nEnter Drawing Number: ")
ShtNo (getstring T "\nEnter Sheet Number: ")
TotSht (getstring T "\nEnter Total Number of Sheets: ")
Rev (getstring T "\nEnter Revision: ")
RevDesc (getstring T "\nEnter Revision Description: ")
Date (getstring T "\nEnter Date: ")
)
;;;--------------------------------------------------------
;;; Window Extents, Calculate Scale,
;;; and Move to Center of Dwg Space
;;;--------------------------------------------------------
(Command "Zoom" "Extents")
(Setq
P2 (Getvar "EXTMAX")
P1 (Getvar "EXTMIN")
thei (- (Cadr P2) (Cadr P1))
tlen (- (Car P2) (Car P1))
A2 (/ thei 2)
A3 (/ tlen 2)
P0 (List (+ (Car P1) A3)
(+ (Cadr P1) A2)
)
)
;;;---------------------------------------------------------------------
;;; Calculate "xscl" - Drawing Scale Required Horizontally
;;;---------------------------------------------------------------------
(Setq xscl (/ tlen (* A0 2))) ;used A0 to control width instead of constant
;;;---------------------------------------------------------------------
;;; Calculate "yscl" - Drawing Scale Required Vertically
;;;---------------------------------------------------------------------
(Setq yscl (/ thei (* A1 2))) ;used A1 to control width instead of constant
;;;---------------------------------------------------------------------
;;; Set "dwgscl" - Overall Drawing Scale
;;;---------------------------------------------------------------------
(If (>= xscl yscl)
(Setq dwgscl xscl)
(Setq dwgscl yscl)
)
(Setq
scls (List 0.25 0.5 1 2 3 4 5 5.3333 6 8
10 12 16 20 24 30 32 40 48 50 56 60
64 72 96 100 120 128 144 160 200 240 296 320 360 400 480
560 600 640 720 960 1200 1280 1400 1920 2400 3840
)
R0 0
R1 (length scls)
)
(While (< R0 R1)
(If (And
(< (nth R0 scls) dwgscl)
(>= (nth (1+ R0) scls) dwgscl)
)
(progn
(Setq
dwgscl (nth (1+ R0) scls)
R0 R1
)
)
(progn
(Setq R0 (1+ R0))
(If (= R0 R1)
(Setq dwgscl (nth R0 scls))
)
)
)
)
;;;---------------------------------------------------------------------
;;; Calculate the Center of New Dwg Space
;;; and Move Contents to that Center
;;;---------------------------------------------------------------------
(Setq edf (rtos dwgscl 2 4)) ;set edf = dwgscl to 4 decimal places
(While (/= edf nil)
(Setq
A4 (* (- (Car n1) (Car n0)) dwgscl)
A5 (* (- (Cadr n1) (Cadr n0)) dwgscl)
n1 (List (+ (Car n0) A4) (+ (Cadr n0) A5))
A6 (* (- (Car A00) (Car n0)) dwgscl)
A7 (* (- (Cadr A00) (Cadr n0)) dwgscl)
P3 (List (+ (Car n0) A6) (+ (Cadr n0) A7))
ws (* dwgscl 5) ;Window Size for Editing Title Block
)
(Command "Move" "all" "" P0 P3)
;;;-------------------------------------------------------
;;; Place Border
;;;-------------------------------------------------------
(Setvar "ATTDIA" 0)
(Setvar "ATTREQ" 0)
(Setvar "CLAYER" "0")
(Setq el (entlast))
(Command
"Insert"
(findfile
"N:/Engineering Data/Software/AutoCAD/AutoCAD Common/Templates/Fab-B-new.dwg"
)
n0
dwgscl
""
0
)
(If (= el (entlast))
(progn
(Print "No Border Placed")
(EXIT)
) ;end progn
(Setq el (entlast))
) ;end (If (= el (entlast)
(If (Or
(/= (cdr (assoc 0 (entget (entlast)))) "INSERT")
(/= (cdr (assoc 2 (entget (entlast)))) "Fab-B-new.dwg")
)
(progn
(Print "No Border Placed")
(EXIT)
)
)
(Command "'Zoom" "Extents")
)
)
I have 8 different titleblocks I need to modify this Lisp for, so I want to get it RIGHT this time instead of having to mess w/ it 8 different times.
Thanks in advance!
Steven
; ProESubm_FabB.lsp
;;;--------------------------------------------------------------------
;;; M A I N F U N C T I O N
;;;--------------------------------------------------------------------
(princ "\nProESubm_FabB Insert")
(Defun C:ProESubm_FabB (/ OSN LA n0 n1 n2 thei
tlen A0 A1 A2 A3 A00 ws
xscl yscl dwgscl rtio scls R0
R1 P0 P1 P2 P3 shtscl
tx txlist pmt1 edf u uprec
)
(Command "Undo" "Mark")
(Setvar "Cmdecho" 1)
(Setvar "Limcheck" 0)
(Setvar "Blipmode" 1)
(Setq
OSN (Getvar "Osmode")
u (Getvar "Lunits") ;Save Unit type
uprec (Getvar "Luprec") ;Save Unit precision
LA (Getvar "CLAYER") ;Save current layer
)
(Setvar "Osmode" 0)
(Setvar "Lunits" 2)
(Setvar "Luprec" 8)
(Setvar "Plinewid" 0)
;;;--------------------------------------------------------
;;; Set Coordinates for Working on Title Block
;;;--------------------------------------------------------
(Setq
n0 (list 0.0 0.0) ;Lower Left Node
n1 (list 0.07000000 0.90000000) ;Lower Left Bdr Pt
n2 (list 16.25000000 10.20000000) ;Upper Right Bdr Pt
A0 (/ (- (Car n2) (Car n1)) 2) ;Half of drawing width
A1 (/ (- (Cadr n2) (Cadr n1)) 2) ;Half of drawing height
A00 (list (+ (Car n1) A0) (+ (Cadr n1) A1)) ;Center of Dwg Space
)
;;; -----------------------------------------------------
;;; Fill in title block info
;;; -----------------------------------------------------
(Setq
Proc (getstring T "\nEnter Process: ")
Desc1 (getstring T "\nEnter Description Line 1: ")
Desc2 (getstring T "\nEnter Description Line 2: ")
DrwBy (getstring T "\nEnter Drawn By: ")
ChkBy (getstring T "\nEnter Checked By: ")
DwgNo (getstring T "\nEnter Drawing Number: ")
ShtNo (getstring T "\nEnter Sheet Number: ")
TotSht (getstring T "\nEnter Total Number of Sheets: ")
Rev (getstring T "\nEnter Revision: ")
RevDesc (getstring T "\nEnter Revision Description: ")
Date (getstring T "\nEnter Date: ")
)
;;;--------------------------------------------------------
;;; Window Extents, Calculate Scale,
;;; and Move to Center of Dwg Space
;;;--------------------------------------------------------
(Command "Zoom" "Extents")
(Setq
P2 (Getvar "EXTMAX")
P1 (Getvar "EXTMIN")
thei (- (Cadr P2) (Cadr P1))
tlen (- (Car P2) (Car P1))
A2 (/ thei 2)
A3 (/ tlen 2)
P0 (List (+ (Car P1) A3)
(+ (Cadr P1) A2)
)
)
;;;---------------------------------------------------------------------
;;; Calculate "xscl" - Drawing Scale Required Horizontally
;;;---------------------------------------------------------------------
(Setq xscl (/ tlen (* A0 2))) ;used A0 to control width instead of constant
;;;---------------------------------------------------------------------
;;; Calculate "yscl" - Drawing Scale Required Vertically
;;;---------------------------------------------------------------------
(Setq yscl (/ thei (* A1 2))) ;used A1 to control width instead of constant
;;;---------------------------------------------------------------------
;;; Set "dwgscl" - Overall Drawing Scale
;;;---------------------------------------------------------------------
(If (>= xscl yscl)
(Setq dwgscl xscl)
(Setq dwgscl yscl)
)
(Setq
scls (List 0.25 0.5 1 2 3 4 5 5.3333 6 8
10 12 16 20 24 30 32 40 48 50 56 60
64 72 96 100 120 128 144 160 200 240 296 320 360 400 480
560 600 640 720 960 1200 1280 1400 1920 2400 3840
)
R0 0
R1 (length scls)
)
(While (< R0 R1)
(If (And
(< (nth R0 scls) dwgscl)
(>= (nth (1+ R0) scls) dwgscl)
)
(progn
(Setq
dwgscl (nth (1+ R0) scls)
R0 R1
)
)
(progn
(Setq R0 (1+ R0))
(If (= R0 R1)
(Setq dwgscl (nth R0 scls))
)
)
)
)
;;;---------------------------------------------------------------------
;;; Calculate the Center of New Dwg Space
;;; and Move Contents to that Center
;;;---------------------------------------------------------------------
(Setq edf (rtos dwgscl 2 4)) ;set edf = dwgscl to 4 decimal places
(While (/= edf nil)
(Setq
A4 (* (- (Car n1) (Car n0)) dwgscl)
A5 (* (- (Cadr n1) (Cadr n0)) dwgscl)
n1 (List (+ (Car n0) A4) (+ (Cadr n0) A5))
A6 (* (- (Car A00) (Car n0)) dwgscl)
A7 (* (- (Cadr A00) (Cadr n0)) dwgscl)
P3 (List (+ (Car n0) A6) (+ (Cadr n0) A7))
ws (* dwgscl 5) ;Window Size for Editing Title Block
)
(Command "Move" "all" "" P0 P3)
;;;-------------------------------------------------------
;;; Place Border
;;;-------------------------------------------------------
(Setvar "ATTDIA" 0)
(Setvar "ATTREQ" 0)
(Setvar "CLAYER" "0")
(Setq el (entlast))
(Command
"Insert"
(findfile
"N:/Engineering Data/Software/AutoCAD/AutoCAD Common/Templates/Fab-B-new.dwg"
)
n0
dwgscl
""
0
)
(If (= el (entlast))
(progn
(Print "No Border Placed")
(EXIT)
) ;end progn
(Setq el (entlast))
) ;end (If (= el (entlast)
(If (Or
(/= (cdr (assoc 0 (entget (entlast)))) "INSERT")
(/= (cdr (assoc 2 (entget (entlast)))) "Fab-B-new.dwg")
)
(progn
(Print "No Border Placed")
(EXIT)
)
)
(Command "'Zoom" "Extents")
)
)