AutoCAD Civil 3D General Discussion

Reply
Valued Mentor
bcsurvey
Posts: 281
Registered: ‎04-29-2008
Message 1 of 20 (307 Views)
Accepted Solution

Need to prompt for block attributes on QNEW

307 Views, 19 Replies
09-20-2012 07:20 AM

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).

 

Thanks!

Civil 3D 2014
Windows 7 Professional SP1
Dell Precision T1700
(i7 @ 3.40 GHz)
8GB RAM
Nvidia Quadro K600
*Expert Elite*
tcorey
Posts: 2,476
Registered: ‎12-18-2002
Message 2 of 20 (291 Views)

Re: Need to prompt for block attributes on QNEW

09-20-2012 03:06 PM in reply to: bcsurvey

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")

 

  (progn

    (ask for attributre info and fill in the blocks)

  );end progn

);end if

 

 

Tim Corey, Owner
Delta Engineering Systems
Redding, CA
Autodesk Authorized Value-Added Reseller
Valued Mentor
bcsurvey
Posts: 281
Registered: ‎04-29-2008
Message 3 of 20 (242 Views)

Re: Need to prompt for block attributes on QNEW

12-20-2013 06:45 AM in reply to: tcorey

Hey Tim,

     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?

 

Thanks!

Civil 3D 2014
Windows 7 Professional SP1
Dell Precision T1700
(i7 @ 3.40 GHz)
8GB RAM
Nvidia Quadro K600
Valued Mentor
bcsurvey
Posts: 281
Registered: ‎04-29-2008
Message 4 of 20 (226 Views)

Re: Need to prompt for block attributes on QNEW

12-20-2013 09:55 AM in reply to: bcsurvey

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.

 

Thank you

Civil 3D 2014
Windows 7 Professional SP1
Dell Precision T1700
(i7 @ 3.40 GHz)
8GB RAM
Nvidia Quadro K600
*Expert Elite*
tcorey
Posts: 2,476
Registered: ‎12-18-2002
Message 5 of 20 (223 Views)

Re: Need to prompt for block attributes on QNEW

12-20-2013 10:03 AM in reply to: bcsurvey
No, you don't need the asterisk. The substr function with 1,7 means start at character 1 and go for 7 characters. Drawing is seven characters so any file that starts w drawing will meet the test.

If you can detail your wishes, next week will be slow for me and I can probably whip out the code you need to perform this task.

Best regards,

Tim
Tim Corey, Owner
Delta Engineering Systems
Redding, CA
Autodesk Authorized Value-Added Reseller
*Expert Elite*
tcorey
Posts: 2,476
Registered: ‎12-18-2002
Message 6 of 20 (217 Views)

Re: Need to prompt for block attributes on QNEW

12-20-2013 10:11 AM in reply to: bcsurvey
(Setq drafter (getstring "backslashnEnter drafter name: "))

Use an actual backslash in the line above. My iPad keyboard doesn't have one. (Anyone know how to get a backslash on iPad?)

Using slash instead of backslash it would be (setq Drafter (getstring "/nEnter drafter name: "))

Just be sure to use the backslash. Backslash n is how you instruct the prompt to move to a new line in the command area.
Tim Corey, Owner
Delta Engineering Systems
Redding, CA
Autodesk Authorized Value-Added Reseller
Valued Mentor
bcsurvey
Posts: 281
Registered: ‎04-29-2008
Message 7 of 20 (211 Views)

Re: Need to prompt for block attributes on QNEW

12-20-2013 11:22 AM in reply to: tcorey

Thanks a bunch for that Tim.  I assume I sub that into (ask for attribute info and fill in the blocks)?

 

 

Civil 3D 2014
Windows 7 Professional SP1
Dell Precision T1700
(i7 @ 3.40 GHz)
8GB RAM
Nvidia Quadro K600
*Expert Elite*
Joe-Bouza
Posts: 4,780
Registered: ‎12-15-2008
Message 8 of 20 (198 Views)

Re: Need to prompt for block attributes on QNEW

12-20-2013 03:07 PM in reply to: bcsurvey
usually you get attribute prompts on insert not creating a new drawing?
My knee jerk reaction is SSM or fields. redifine the attributes in the template to use SSM fields if using SSM.
Thank you

Joseph D. Bouza, P.E. (one of 'THOSE' People) Civil 3D 2012 & 2013
HP Z210 Workstation
Intel Xeon CPU E31240 @ 3.30 Hz
12 GB Ram


Note: Its all Resistentialism, so keep calm and carry on

64 Bit Win7 OS
*Expert Elite*
tcorey
Posts: 2,476
Registered: ‎12-18-2002
Message 9 of 20 (191 Views)

Re: Need to prompt for block attributes on QNEW

12-20-2013 05:09 PM in reply to: bcsurvey

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. 

 

Best regards,

 

Tim

 

 

(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)

 

 

 

Tim Corey, Owner
Delta Engineering Systems
Redding, CA
Autodesk Authorized Value-Added Reseller
Valued Mentor
bcsurvey
Posts: 281
Registered: ‎04-29-2008
Message 10 of 20 (149 Views)

Re: Need to prompt for block attributes on QNEW

12-26-2013 01:24 PM in reply to: tcorey

Tim,

     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!

Civil 3D 2014
Windows 7 Professional SP1
Dell Precision T1700
(i7 @ 3.40 GHz)
8GB RAM
Nvidia Quadro K600

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Civil 3D Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for AutoCAD Civil 3D helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Civil 3D

Twitter

Facebook

Blogs