eric_monceaux Posted November 9, 2009 Posted November 9, 2009 Hello All! So I am making an effort to finally begin figuring out the coding and variables for AutoCAD. My current project is creating a startup lisp that sets all of the values for new and/or pre-existing drawings. I have all of the commands correctly configured, however, is there a way to not have it output the settings it changes? Basically when you start a drawing (new/old) it implements all of the changes, but the command line doesn't show the process. Secondly, within the acaddoc.lsp, I want the final command to invoke a custom LISP before the user can proceed: (command "DWG") I keep getting an error at the end of the acaddoc.lsp: Enter new value for SPLINESEGS <20>: 20 FACETRES Enter new value for FACETRES <10.0000>: 10 ISOLINES Enter new value for ISOLINES <10>: 20 [b]DWG Unknown command "DWG". Press F1 for help.[/b] I can't figure out what I am missing to invoke the LISP at the end of acaddoc.LSP. Here is the entire acaddoc.lsp: ; ; ;North American Stone Drawing Set Up ; ; ;--------------------- ;LISP Loads ; (autoload "autoDPROP" '("autoDPROP")) (autoload "nasc_props" '("nasc_props" "dwg")) ;ENVIRONMENT (command "base" "0,0,0") (setvar "osmode" 6255) (command "-INSERT" "Z_STD_SETUP" "0,0" "1" "" "0") (command "ERASE" "L" "") (command "-STYLE" "SHEET" "tahoma.TTF" "0" "1" "0" "N" "N") (command "-LAYER" "S" "0-STONE" "") (command "-DIMSTYLE" "R" "16") (command "LTSCALE" "6") (command "PDMODE" "3") (command "PDSIZE" "0") (command "-HATCH" "P" "AR-SAND" "0.25" "0" "") (command "-UNITS" "4" "16" "1" "0" "0" "N") (command "VIEWRES" "Y""20000") (command "SPLINESEGS" "20") (command "FACETRES" "10") (command "ISOLINES" "20") (c:dwg) Am I at least on the right path??? Quote
dbroada Posted November 9, 2009 Posted November 9, 2009 it is telling you there is no command known to AutoCAD called "DWG" I assume you are trying to start a lisp file called dwg in which case you need to load it first. I'm guessing here but try (something like) (load "DWG") DWG Quote
eric_monceaux Posted November 9, 2009 Author Posted November 9, 2009 My apologies...yes I am trying to load a custom LISP. I should have explained that I have that in the set of commands. (autoload "nasc_props" '("nasc_props")) nasc_props is the lisp that uses the DWG command: (defun C:DWG () Quote
rkmcswain Posted November 9, 2009 Posted November 9, 2009 First off, you can't normally* call an externally defined lisp command like this (command "dwg") [* exception is if you use (vlax-add-cmd)] Secondly, if you are autoloading "nasc_props" and that file contains the "Dwg" function, then you need to add "Dwg" to the second argument in the (autoload) call, like this: (autoload "nasc_props" '("nasc_props" "dwg")) Lastly, to call this function, you can do this: (c:dwg) Quote
eric_monceaux Posted November 9, 2009 Author Posted November 9, 2009 I changed the code to what you have shown, and edited my original post to reflect those changes. Now I get the following: Job Number:*Cancel* Job Number: Command: *Cancel* Function cancelled Moving further into the description of the lisp that I am trying to automatically invoke, I am attaching the code for those below. This lisp is designed to require the user to enter in custom DWGPROPS info on the command line. After acaddoc.lsp completes, the nasc_props.lsp works fine. Here is the dependant lisp (named AutoDPROP.lsp in acaddoc.lsp) ;;; *********************************************** ************************* ;;; * Library DWGruLispLib Copyright © 2007 DWGru Programmers Group ;;; * ;;; * _dwgru-Dwgprops-get-all-prop ;;; * ;;; * 27/12/2007 Version 0001. Vladimir Azarko (VVA) ;;; *********************************************** ************************* (defun _dwgru-dwgprops-get-all-prop (Doc / si ret nc key value) ;;; Returns the file's properties, set the team _dwgprops ;;; Returns an associative list, where the key is: ;; - For properties created by the user (tab OTHER) ;;; Property name ;; - For standard properties (tab PAPER) ;;; Key field ;;; NAME - *TITLE* ;;; AUTHOR - *AUTHOR* ;;; TOPIC - *SUBJECT* ;;; KEY WORDS - *KEYWORDS* ;;; NOTES - *COMMENTS* ;;; Hyperlink Base - *HYPERLINK* ;;;!! Key fields are converted to uppercase ;;; Doc - a pointer to the PDF document, nil - the current ;;; Example ;;; (_dwgru-dwgprops-get-all-prop nil) ;;;(("* AUTHOR * "" VVA ") (" * COMMENTS * "" Memo ") (" * HYPERLINK * "" Base ") ;;;("* KEYWORDS * "" Key ") (" * TITLE * "" named ") (" * SUBJECT * "" R ") (" UNIQKEY "" Key ")) (and (or Doc (setq Doc (vla-get-activeDocument (vlax-get-acad-object))) ) (setq si (vla-get-SummaryInfo Doc)) (setq ret (list (list "*AUTHOR*" (vla-get-author si)) (list "*COMMENTS*" (vla-get-comments si)) (list "*HYPERLINK*" (vla-get-HyperlinkBase si)) (list "*KEYWORDS*" (vla-get-keywords si)) (list "*TITLE*" (vla-get-Title si)) (list "*SUBJECT*" (vla-get-Subject si)) ) ) (setq nc (vla-numcustominfo si)) (while (> nc 0) (vla-GetCustomByIndex si (- nc 1) 'key 'value) (setq ret (append ret (list(list (strcase key) value)))) (setq nc (1- nc)) ) (vlax-release-object si) ) ret ) ;;; *********************************************** ************************* ;;; * Library DWGruLispLib Copyright © 2007 DWGru Programmers Group ;;; * ;;; * _dwgru-Dwgprops-get-custom-prop ;;; * ;;; * 27/12/2007 Version 0001. Vladimir Azarko (VVA) ;;; *********************************************** ************************* (defun _dwgru-dwgprops-get-custom-prop (key Doc / app counter counter2 counter3 doc dwgprops kv) ;;; Returns the value of the property created by the user (team _dwgprops) ;;; Returns an associative list, where the key is: ;; - For properties created by the user (tab OTHER) ;;; Key - a string property name (tab OTHER) ;; - For standard properties (tab PAPER) ;;; Key field ;;; NAME - *TITLE* ;;; AUTHOR - *AUTHOR* ;;; TOPIC - *SUBJECT* ;;; KEY WORDS - *KEYWORDS* ;;; NOTES - *COMMENTS* ;;; Hyperlink Base - *HYPERLINK* ;;; ;;; Uses the library ;;; _dwgru-Dwgprops-get-all-prop ;;; _dwgru-Assoc (_dwgru-assoc-multi) ;;; Doc - a pointer to the PDF document, nil - the current (cadr (_dwgru-assoc key (_dwgru-dwgprops-get-all-prop Doc))) ) ;;; *********************************************** ************************* ;;; * Library DWGruLispLib Copyright © 2007 DWGru Programmers Group ;;; * ;;; * _dwgru-Dwgprops-set-custom-prop ;;; * ;;; * 27/12/2007 Version 0001. Vladimir Azarko (VVA) ;;; *********************************************** ************************* (defun _dwgru-dwgprops-set-custom-prop (key value Doc / si) ;;, Create in the properties of the figure (team _dwgprops bookmark OTHER) ;;; Property with key and value value ;;; If the property was not, it is created, otherwise the changes ;;; Key - a string property name (tab OTHER) ;;; Value - a string (string) - value of property ;;; Uses the library ;;; _dwgru-Dwgprops-get-custom-prop ;;; Doc - a pointer to the PDF document, nil - the current ;;; Returns - nil ;;; Example ;;; (_dwgru-dwgprops-set-custom-prop "dwgru" "dwgru-dwgprops-set-custom-prop" nil) (or Doc (setq Doc (vla-Get-ActiveDocument (vlax-Get-Acad-Object))) ) (setq si (vla-Get-SummaryInfo Doc)) (if (_dwgru-dwgprops-get-custom-prop key Doc) (vla-SetCustomByKey si key value) (vla-AddCustomInfo si key value) ) ) (defun _dwgru-assoc-multi (key lst) (if (= (type key) 'str) (setq key (strcase key)) ); _ End of if (vl-remove-if-not (function (lambda (a / b) (and (setq b (car a)) (or (and (= (type b) 'str) (= (strcase b) key)) (equal b key)) ); _ End of and ); _ End of lambda ); _ End of function lst ); _ End of vl-remove-if-not ); _ End of defun (defun _dwgru-assoc (key lst) (car (_dwgru-assoc-multi key lst)) ); _ End of defun And Here is the nasc_prop.lsp ;;; *********************************************** ************************* ;;; * NASC Field Properties* ;;; * ;; *Allows user to type in job info in command bar* ;; *for use with the FIELDS in the titleblock* ;;; * ;; *For North American Stone Company* ;;; * ;;; * 11/09/2009 Version 0001. Vladimir Azarko (VVA) ;;; *********************************************** ************************* (defun C:DWG () (vl-load-com) ;;; Do not forget to add (setq str (getstring t "\nJob Number:")) (_dwgru-dwgprops-set-custom-prop "Job Number" str nil) (setq str (getstring "\nCustomer:")) (_dwgru-dwgprops-set-custom-prop "Customer" str nil) (setq str (getstring t "\nAddress:")) (_dwgru-dwgprops-set-custom-prop "Address" str nil) (setq str (getstring t "\nCity St:")) (_dwgru-dwgprops-set-custom-prop "City St" str nil) (setq str (getstring t "\nColor:")) (_dwgru-dwgprops-set-custom-prop "Color" str nil) (setq str (getstring t "\nDrawn By:")) (_dwgru-dwgprops-set-custom-prop "Drawn By" str nil) (setq str (getstring t "\nDelivery Date:")) (_dwgru-dwgprops-set-custom-prop "Delivery Date" str nil) (setq str (getstring t "\nDrawing Date:")) (_dwgru-dwgprops-set-custom-prop "Drawing Date" str nil) (setq str (getstring t "\nFinish:")) (_dwgru-dwgprops-set-custom-prop "Finish" str nil) ) Quote
eric_monceaux Posted November 9, 2009 Author Posted November 9, 2009 First off, you can't normally* call an externally defined lisp command like this (command "dwg") [* exception is if you use (vlax-add-cmd)] Is there a better way to invoke a Lisp automatically when a drawing is opened or new? Quote
tzframpton Posted November 9, 2009 Posted November 9, 2009 Yes, just LOAD the path of the LSP file itself, using double backslashes to separate the directory hierarchy instead of single backslashes. For example: ;;; begin acaddoc.lsp (load "K:\\Project Manager Department\\1-AutoCad\\Lisp\\fixblock.lsp") ;;; end acaddoc.lsp This is a single Lisp file called "fixblock.lsp" that we all use in my office. It's located on the networked K drive. Just put this exact code in like it is for each Lisp file you want to load, and then each time you open or create a new drawing it'll be there. Quote
rkmcswain Posted November 9, 2009 Posted November 9, 2009 Is there a better way to invoke a Lisp automatically when a drawing is opened or new? Invoke (run), or just load? Quote
alanjt Posted November 10, 2009 Posted November 10, 2009 Yes, just LOAD the path of the LSP file itself, using double backslashes to separate the directory hierarchy instead of single backslashes. For example: ;;; begin acaddoc.lsp (load "K:\\Project Manager Department\\1-AutoCad\\Lisp\\fixblock.lsp") ;;; end acaddoc.lsp This is a single Lisp file called "fixblock.lsp" that we all use in my office. It's located on the networked K drive. Just put this exact code in like it is for each Lisp file you want to load, and then each time you open or create a new drawing it'll be there. Tannar, you should always add either nil or "Some Message" to the end of all load functions. If the file cannot be found in your above code, it will error and not continue (granted, in your case, you only have the one thing, but still). Example: Command: (load "asldkfj") Error: LOAD failed: "asldkfj" Command: (load "asldkfj" nil) nil Command: (load "asldkfj" "") "" Quote
tzframpton Posted November 10, 2009 Posted November 10, 2009 Tannar, you should always add either nil or "Some Message" to the end of all load functions. If the file cannot be found in your above code, it will error and not continue (granted, in your case, you only have the one thing, but still). Yeah, I definitely have all my stuff rigged that's for sure, lol. I'll do it because you say to, but ya I'm no programmer. Granted, if something doesn't load right, obviously I know exactly where to go to find it.... Thanks for the tip though. Always appreciated from a pro such as yourself. Quote
alanjt Posted November 10, 2009 Posted November 10, 2009 Yeah, I definitely have all my stuff rigged that's for sure, lol. I'll do it because you say to, but ya I'm no programmer. Granted, if something doesn't load right, obviously I know exactly where to go to find it.... Thanks for the tip though. Always appreciated from a pro such as yourself. I just happened to notice and wanted to offer that bit of information. I'm no pro, I just run my mouth too much. Quote
eric_monceaux Posted November 12, 2009 Author Posted November 12, 2009 You know its pretty funny seeing two AutoCAD Gods give each other flak...But seriously, all of you "super elites" (ReMark, alanjt, StykFace, Lee, etc.) have been such a great help to me, and to others. I am hoping to get to your knowledge level someday! I have worked with AutoCAD since 1995 on version 10, and have strived to learn all I can. However, the one "dragon" I haven't ever beem able to catch is LISPs. Most of the stuff that I have learned has either come from you guys, or the crypic AutoCAD help file! Keep up the great work gentlemen (or, dudes...if you prefer). I don't know what we would do without you! Ok that is enough cheese for today...dont you think? Quote
eric_monceaux Posted November 12, 2009 Author Posted November 12, 2009 Oh, and, I actually had a question to ask. I actually want to get that acaddoc.lsp to not show up at the beginning of each drawing. I tried adding (command "MENUECHO" "2") to the beginning of the LISP, but it didnt work. Is there another way to accomplish this? Quote
alanjt Posted November 12, 2009 Posted November 12, 2009 You know its pretty funny seeing two AutoCAD Gods give each other flak... LoL ....Gods....LoL I had to add that to my signature. LoL Quote
alanjt Posted November 12, 2009 Posted November 12, 2009 Oh, and, I actually had a question to ask. I actually want to get that acaddoc.lsp to not show up at the beginning of each drawing. I tried adding (command "MENUECHO" "2") to the beginning of the LISP, but it didnt work. Is there another way to accomplish this? What do you mean by not show[ing] up? Quote
eric_monceaux Posted November 12, 2009 Author Posted November 12, 2009 Sorry, forgot to use proper terminology. The AutoCAD Text Window. Quote
alanjt Posted November 12, 2009 Posted November 12, 2009 Sorry, forgot to use proper terminology. The AutoCAD Text Window. Sounds like you have (textscr) in your startup. Quote
eric_monceaux Posted November 12, 2009 Author Posted November 12, 2009 I explored that option a little bit at first. I was going to add a line (command "graphscr") at the begining of the run, but when the LISP runs, I get the following output (shortened): Regenerating model. AutoCAD menu utilities loaded.graphscr base Enter base point <0'-0",0'-0",0'-0">: 0,0,0 -INSERT Enter block name or [?]: Z_STD_SETUP Duplicate definition of block _ArchTick ignored. Units: Inches Conversion: 1.0000 Specify insertion point or [basepoint/Scale/X/Y/Z/Rotate]: 0,0 Enter X scale factor, specify opposite corner, or [Corner/XYZ] <1>: 1 Enter Y scale factor <use X scale factor>: Specify rotation angle <0>: 0 ERASE Select objects: L 1 found AND the text screen still shows up. ---------------------------------- I created the acad.lsp and acaddoc.lsp, and I haven't put (command "textscr"), or any other variation, in. Is there another file that would hold that value? ---------------------------------- P.S. Here is the most current acaddoc.lsp ;;; ;;; ;;;North American Stone Drawing Set Up ;;; ;;; ;;;--------------------- ;;;ENVIRONMENT (command "graphscr") (command "base" "0,0,0") (setvar "osmode" 6255) (command "-INSERT" "Z_STD_SETUP" "0,0" "1" "" "0") (command "ERASE" "L" "") (command "-STYLE" "SHEET" "tahoma.TTF" "0" "1" "0" "N" "N") (command "-LAYER" "S" "0-STONE" "") (command "-DIMSTYLE" "R" "16") (command "LTSCALE" "6") (command "PDMODE" "3") (command "PDSIZE" "0") (command "-HATCH" "P" "AR-SAND" "0.25" "0" "") (command "-UNITS" "4" "16" "1" "0" "0" "N") (command "VIEWRES" "Y""20000") (command "SPLINESEGS" "20") (command "FACETRES" "10") (command "ISOLINES" "20") (command "grid" "off") ;;;--------------------- Quote
alanjt Posted November 12, 2009 Posted November 12, 2009 It's this line: (command "-UNITS" "4" "16" "1" "0" "0" "N") You should be able to set everything with the following: insunits lunits luprec aunits auprec Quote
alanjt Posted November 12, 2009 Posted November 12, 2009 BTW, these are extremely dangerous: (command "-INSERT" "Z_STD_SETUP" "0,0" "1" "" "0") [color=Red](command "ERASE" "L" "") <- If block isn't inserted, you will erase last thing created in drawing[/color] (command "-STYLE" "SHEET" "tahoma.TTF" "0" "1" "0" "N" "N") [color=Red](command "-LAYER" "S" "0-STONE" "") <-Will error if layer doesn't exist (command "-DIMSTYLE" "R" "16") <-Will error if dimstyle doesn't exist[/color] You could use something like this: (command "-INSERT" "Z_STD_SETUP=" nil) (if (tblsearch "layer" "0-STONE") (command "-LAYER" "_T" "0-STONE" "S" "0-STONE" "") (command "_.-layer" "_m" "0-STONE" "" "") ) (and (tblsearch "dimstyle" "16") (command "-DIMSTYLE" "R" "16") ) Quote
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.