I'm further developing our template and would lke to know how much trouble it would be (if any) to be prompted for several block attributes upon a new file being created (QNEW). The information in these blocks is found throughout the .dwg file and I'd like to reduce the amount of time going through each instance to modify (something that should have been done a long time ago).
Solved! Go to Solution.
You could add some code to ACADDOC.LSP that would check the file name. If it's Drawing*, prompt for attribute information, if the name is something else, it means this is not a new drawing, don't ask.
(if (=(substr(getvar "DWGNAME")1 7) "Drawing")
(ask for attributre info and fill in the blocks)
I was going through some old posts and came across this one. I'd been wondering how what you provided could be accomplished and I may have just overlooked it before . . .
I put this code in my acad2012doc.lsp file but I don't get the prompts for attributes. Should the "Drawing" in the code be "Drawing*"? Also, I understand that lisp language changed in recent acad versions so perhaps that's an issue for what you've posted?
I just spent about 10 minutes clicking around trying to find a way to edit my post above . . . no luck, so here's another one:
I'm a novice at best with regard to lisp, but I'm pretty sure that tcorey just put in only descriptions of functions, not the code itself. I had copied it into my acad2012doc.lsp and was wondering why I wasn't getting prompted for attributes when I loaded a .dwg with "Drawing" in the file name.
If it wouldn't take too much time, can anyway give me the necessary code to output prompts for attributes. Only a few attributes right now: DRAFTER, TOWNSHIP, RANGE, SECTION, SURV_TYPE, CLIENT.
Thanks a bunch for that Tim. I assume I sub that into (ask for attribute info and fill in the blocks)?
Without having complete details of what you're doing, I might miss something, but the following code will Prompt the user for Drafter, Date and Favorite Baseball Team. It will then fill this attribute information into all instances of a block called Baseball, which has three attributes.
This assumes that you are wanting to update blocks that already are inserted into the drawing, not those that simply exist in the block table (database.) Also, it assumes that there might be several instances of the block and so it steps through a selection set and updates them all. Either of these assumptions could be way off, so this code is supplied as an example of how you would do this if those assumptions were true. Also, if you were in fact to want to use a Date attribute, you might consider using a Field in that attribute instead of using a prompt input.
(if (=(substr(getvar "DWGNAME")1 7) "Drawing") (progn (setq Dftr (getstring "\nDrafter name: ") Dte (getstring "\nDate: ") Bball (getstring "\nFavorite Baseball Team: ") ) (setq ss (ssget "x" (list (cons 0 "INSERT")(cons 2 "BASEBALL"))) ;Cons 2 is the block name. Change this to your block name. len (sslength ss) ctr 0) (while (< ctr len) (setq blk (ssname ss ctr) dftatt (entnext blk) dteatt (entnext dftatt) bballatt (entnext dteatt) ) (setq dftx (entget dftatt) dtex (entget dteatt) bballx (entget bballatt) ) (setq dftx (subst (cons 1 dftr) (assoc 1 dftx) dftx) ) (entmod dftx) (setq dtex (subst (cons 1 dte) (assoc 1 dtex) dtex) ) (entmod dtex) (setq bballx (subst (cons 1 bball) (assoc 1 bballx) bballx) ) (entmod bballx) (entupd blk) (setq ctr (1+ ctr)) );end while );end progn );end if (setq dftr nil dte nil bball nil ss nil len nil ctr nil blk nil dftatt nil dteatt nil bballatt nil dftx nil dtex nil bballx nil) (princ)
I've customized the code you provided to fit the .dwg I'm using (block name, attributes, etc.), but still can't seem to hash it out. I noticed you had 2 different variables referring to Drafter, so I corrected that (I think). Here's what I have in my acad2012doc.lsp file (see below it for what I get in command line upon opening .dwg). Perhaps something will stick out . . .
(if (=(substr(getvar "DWGNAME")1 7) "Drawing") (progn (setq dft (getstring "\nDrafter name: ") dte (getstring "\nDate: ") twn (getstring "\nTownship: ") ) (setq ss (ssget "x" (list (cons 0 "INSERT")(cons 2 "LispTest"))) ;Cons 2 is the block name. Change this to your block name. len (sslength ss) ctr 0) (while (< ctr len) (setq blk (ssname ss ctr) dftatt (entnext blk) dteatt (entnext dftatt) twnatt (entnext dteatt) ) (setq dftx (entget dftatt) dtex (entget dteatt) twnx (entget twnatt) ) (setq dftx (subst (cons 1 dft) (assoc 1 dftx) dftx) ) (entmod dftx) (setq dtex (subst (cons 1 dte) (assoc 1 dtex) dtex) ) (entmod dtex) (setq twnx (subst (cons 1 twn) (assoc 1 twnx) Twnx) ) (entmod twnx) (entupd blk) (setq ctr (1+ ctr)) ) ;end while ) ;end progn ) ;end if (setq dft nil dte nil twn nil ss nil len nil ctr nil blk nil dftatt nil dteatt nil twnatt nil dftx nil dtex nil Twnx nil) (princ)
This is what I get in command line after opening .dwg file:
AutoCAD menu utilities loaded. Drafter name: Command: C*Cancel* C Command: COMMANDLINE Date: properties Township: Command: *Cancel*
After this, if I do anything in the drawing, I immediately get a Fatal Error, consistently. The code above is the only thing I've added to the .lsp file since original installation.
As I'm sure your time is money, I'll say that this is not a critical matter. But I appreciate every second you can give me!
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register