pixel8er Posted July 13, 2011 Share Posted July 13, 2011 (edited) Hi all I've created a very simple LISP routine to: 1. Set the drawing tab to A0L 2. xref an A0 titleblock linework 3. insert an attribute text block ...but it's not working. The routine sets the drawing tab to A0L and then stops. My LISP knowledge is pretty basic but I'm not sure what's stopping this from working. I've tested the next part of the routine on the command line and it works. Can anyone provide any pointers on what I've done wrong? Thanks in advance for any help Regards Paul ;; Type CDA0 to insert the A0 CD Titleblock ;; (defun c:CDA0 () (setvar "cmdecho" 0) (setvar "expert" 5) ;;Sets the drawing layout tab to A0L (A0 Landscape) (command "ctab" "A0L") ;;Xrefs the A0 titleblock as overlay (command "-xref" "Overlay" "C:\Users\P8\Documents\_Library\_ABC\AutoCAD\Templates\Blocks\TB-A0-CD-PL.dwg" "0,0,0" "1" "1" "0") ;;Inserts the A0 titleblock attribute text (command "-insert" "C:\Users\P8\Documents\_Library\_ABC\AutoCAD\Templates\Blocks\MAC-TB-A0-CD-PL-ATT.dwg" "0,0,0" "1" "0") (setvar "expert" 2) (setvar "cmdecho" 1) (princ) ) Edited July 14, 2011 by SLW210 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 13, 2011 Share Posted July 13, 2011 Hi Paul, Firstly, read this with regard to formatting code in posts. Now, in LISP, the backslash is an escape character and is hence used to give subsequent characters an alternative meaning, such as the newline character '\n', or tab '\t'. To use a literal backslash, you need to prefix the backslash with another: "C:\\Users\\P8\\Documents\\_Library\\_ABC\\AutoCAD\\Templates\\Blocks\\MAC-TB-A0-CD-PL-ATT.dwg" A few other improvements could also be made: [color=green];; Type CDA0 to insert the A0 CD Titleblock[/color] (defun c:CDA0 ( / [color=red]att cmd ext[/color] ) [color=green] ;; Now that I am using some variables, these are localised in the ;; defun expression. ;; To see why this is important, see: www.lee-mac.com/localising.html[/color] [color=red] (setq cmd (getvar 'CMDECHO) ext (getvar 'EXPERT) att (getvar 'ATTREQ) )[/color] [color=green] ;; Whenever changing System Variables, store the original values ;; so that they may be reset afterwards. ;; ;; You could also consider adding an error handler to reset such ;; System Variables should the user hit Esc or there be an error in ;; the code. ;; ;; For information on how to do such, see: www.lee-mac.com/errorhandling.html [/color] (setvar 'CMDECHO 0) (setvar 'EXPERT 5) [color=red] (setvar 'ATTREQ 0)[/color] [color=green] ;; I set the ATTREQ System Variable to zero to suppress any attribute prompts ;; when the block is inserted. [/color] [color=green] ;; Using the quoted symbol instead of the string when manipulating ;; System Variables is just a habit of mine, both ways are valid. ;;Sets the drawing layout tab to A0L (A0 Landscape)[/color] [color=red] (setvar 'CTAB "A0L")[/color] [color=green] ;;Xrefs the A0 titleblock as overlay[/color] (command "[color=red]_.[/color]-xref" "_Overlay" "C:[color=red]\[/color]\Users[color=red]\[/color]\P8[color=red]\[/color]\Documents[color=red]\[/color]\_Library[color=red]\[/color]\_ABC[color=red]\[/color]\AutoCAD[color=red]\[/color]\[color=red]Templates\[/color]\Blocks[color=red]\[/color]\TB-A0-CD-PL.dwg"[color=red] "_non"[/color] "0,0,0" "1" "1" "0") [color=green] ;;Inserts the A0 titleblock attribute text[/color] (command "[color=red]_.[/color]-insert" "C:[color=red]\[/color]\Users[color=red]\[/color]\P8[color=red]\[/color]\Documents[color=red]\[/color]\_Library[color=red]\[/color]\_ABC[color=red]\[/color]\AutoCAD[color=red]\[/color]\[color=red]Templates\[/color]\Blocks[color=red]\[/color]\MAC-TB-A0-CD-PL-ATT.dwg" [color=red]"_non"[/color] "0,0,0" "1" "0") [color=green] ;; Here I use the prefix "_.-" ;; "_" : allows for all language versions of AutoCAD ;; "." : uses the default command, since the command may have been redefined ;; "-" : uses the command-line version of a command ;; I use "_non" to avoid interference with ObjectSnap.[/color] [color=red] (setvar 'ATTREQ att) (setvar 'EXPERT ext) (setvar 'CMDECHO cmd)[/color] [color=green] ;; Reset System Variables to original values.[/color] (princ) ) Quote Link to comment Share on other sites More sharing options...
pixel8er Posted July 14, 2011 Author Share Posted July 14, 2011 Hi Lee Mac WOW! Thanks for the prompt and very detailed reply. The routine works perfectly now with your wonderful additions. I'm just off to work now but I've got lots of reading to do tonight on all your tips and information to get a little better understanding of LISP. Thanks so much Regards Paul Quote Link to comment Share on other sites More sharing options...
BIGAL Posted July 14, 2011 Share Posted July 14, 2011 Another way "C:/Users/P8/Documents/_Library/_ABC/AutoCAD/Templates/Blocks/MAC-TB-A0-CD-PL-ATT.dwg" The reversing of the slash has been around since year dot on unix boxes it was the other way very confusing, probably better though to use the \\ easier to remember. Quote Link to comment Share on other sites More sharing options...
pixel8er Posted July 14, 2011 Author Share Posted July 14, 2011 I might need to implement this on Macs as well. Does anyone know what the file path separator is in Mac OS X? Is it forward slash "/" or colon ":" Quote Link to comment Share on other sites More sharing options...
SLW210 Posted July 14, 2011 Share Posted July 14, 2011 Hi Paul,Firstly, read this with regard to formatting code in posts. Please read this and edit your post. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 14, 2011 Share Posted July 14, 2011 WOW! Thanks for the prompt and very detailed reply. The routine works perfectly now with your wonderful additions. I'm just off to work now but I've got lots of reading to do tonight on all your tips and information to get a little better understanding of LISP. Thanks so much You're welcome Paul. If you have any further questions about my modifications, just ask. Quote Link to comment Share on other sites More sharing options...
irneb Posted July 14, 2011 Share Posted July 14, 2011 Another way "C:/Users/P8/Documents/_Library/_ABC/AutoCAD/Templates/Blocks/MAC-TB-A0-CD-PL-ATT.dwg" The reversing of the slash has been around since year dot on unix boxes it was the other way very confusing, probably better though to use the \\ easier to remember. I might need to implement this on Macs as well. Does anyone know what the file path separator is in Mac OS X? Is it forward slash "/" or colon ":"I'd actually go with the forward slash (even on windows). Seeing as the Mac (OSX) is actually based on BSD (which is a derivative of Unix, same as Linux is) I'd be highly surprised if they use anything else than forward slashes ... which is what all Unix based/derived OS's use. These days it's only DOS/Windows where the back-slash is used at all. Another reason to stick with forward slashes is if you place your code directly into a macro (inside the CUI editor) the backslash suddenly means: "Pause for user input". So in those cases you're forced to use the forward slash. IMO it's better for these 2 reasons to get out of the habit of using double back-slashes. If one day ACad moves to Mac/*nix (or whatever next) you won't need to change that much of your code, and you can easily copy-n-paste code direct into macros without worrying about it going wrong. Quote Link to comment Share on other sites More sharing options...
pixel8er Posted July 15, 2011 Author Share Posted July 15, 2011 SLW210 - thanks for editing my post, you got to it before me. Have read the guidelines now so know the procedure for next time. irneb - yes that seems to be the consensus from my research. Forward slash is the best bet Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.