View Full Version : Attribute in Dynamic Block does not prompt on insertion
matthew g.
2010-08-23, 10:29 PM
The subject line pretty much says it all. I've tried creating the attribute from scratch within the block editor, I've tried creating it within the drawing but NOT in the block editor, etc. I'm using vanilla AutoCAD 2011 and all I want is a prompt when I insert the dynamic block. Something like "Enter the number: " and the the block shows up with that number in it, you know, the way regular attributes work.
Thanks!
Matthew
matthew g.
2010-08-23, 10:39 PM
I should add that I am inserting it via LISP with something like this:
(defun C:ShearWallTag ()
(setvar "cmdecho" 0)
(setq la (getvar "clayer"))
(command "layer" "s" "S-ANNO-SYMB" "")
(setq ds (getvar "DIMSCALE")
pa (getpoint "\nPick symbol insertion point: ")
swtxt (getstring T "\nEnter Shear Wall number: ")
)
(command "-insert" "*ShearWallTag" pa ds "0" swtxt)
(command "layer" "s" la "")
(princ)
)
I have played around with the "-insert" line quite a bit and yes I searched the Help, these groups, and Google before posting this. I feel like I'm missing something really simple here.
irneb
2010-08-24, 06:27 AM
If you use the -Insert command directly (not through Lisp) does it then ask you for the attribute values? If not try changing the ATTREQ sysvar to 1.
BTW, you don't need the minus prefix in lisp to ensure the command-line version of a command. What I would suggest though is the dot & underscrore prefix: (command "._INSER" ...). This will allow the standard insert command even if it's redefined, and use the internationalized name even on another language pack.
If it simply doesn't want to work, you could always start the DDEDIT command and select the entlast to edit. To ensure you also get the dialog interface, preempt the (command ...) with (initdia).
matthew g.
2010-08-24, 04:49 PM
It does not ask me even when I manually insert the block, even with the ATTREQ variable set. I've attached the block just in case I've done something stupid in there. Thanks for the tip on the LISP routine as well.
Oh, and I'm lovin the sig.
Matthew
irneb
2010-08-25, 05:55 AM
First off, you're inserting the DWG file itself (not the block). This file contains a reference(s) to the block ... no ATTDEF's directly in its model space. So inserting the ShearWallTag file/block is not creating any ATTRIB entities, just a reference to the ShearWallTag block definition (which already has the attribs as linked to the block reference(s) of SheerWallSymbol.
You're also inserting it as exploded. So after exploding the definition's objects are copied as is to the model space. If you had done this manually, you will never be asked to input the attributes, since you're not creating any new block reference with attributes by the insert command. What you're effectively doing is copy an existing set of attributed blocks, or more correctly as if you Ctrl+C out of BEdit and Ctrl+V into Model Space. No way would that pop-up the question of attribute entry (no matter what any sysvar is set to).
If you change your code to insert "ShearWallSymbol" instead (also note not exploding it), then you'll be asked for its attribute value. However, it then depends on if the block is set to scale uniformly, and here your code breaks down again. You're entering the insertion point, then the X scale factor. Because the block's definition is not set to be scaled uniformly, ACad then asks for the Y scale factor. To which your code responds with the rotation angle of "0" --->>> ERROR, you can't scale something to ZERO!
However, there's still a further problem, which causes my previous suggestion to become null-n-void: If you don't use the minus prefix to the insert command, the attribute entry opens as a dialog box. You could change this by setting ATTDIA=0, but then you have to set it back again. So the easiest thing to do would be to leave your code as is (including the minus prefix).
So, you've got 2 options:
Insert the ShearWallSymbol block instead of the ShearWallTag block. To fix the scaling issue, you've got 2 sub-options:
BEdit the block and change its Uniform Scale property to Yes; or
Modify your code to add a "" just after the ds, so the Y defaults to the same as the X. Or add 3 ds's to set the same value for XYZ.
Change your code so that after the ShearWallTag block is inserted and exploded you can obtain the entities it's created, with the intention of modifying the attributes. You do so by saving the ename of the last entity before inserting (use entlast). Then after inserting, everything which entnext gives after this entity is new. Check the DXF data of each, until you find one with (0 . "ATTRIB"). Then change it's (1 . "Value") to what was entered in swtxt.Just a further suggestion: You're setting CMDECHO=0, but never resetting it - not too bad, but not ideal. If you're also going to set ATTREQ and / or ATTDIA this will cause problems for the user as using this routine will change his setup each time. You need to save a sysvar's value before changing it, then reset it to its old value after the function completes. You may even want to restore the current layer through the CLAYER sysvar as well (instead of using the -LAYER command).
Further to above, you need to catch errors (e.g. the user pressing Esc midway through the function) so that even if an error occurs these sysvar's are reset to their original. Search the AutoLisp (http://forums.augi.com/forumdisplay.php?f=91) forum for Error Handling.
And then the final suggestion, it's good practice (and several good reasons for) declaring variables as local to a function. Again, there's quite a few threads in the AutoLisp forum about why you should do such.
matthew g.
2010-08-26, 05:12 PM
Sweet, thanks Inreb! I've printed that out and will go over it.
Ok, so this may be a stupid question but how do I now save out the "ShearWallSymbol" in a way that the LISP routine will see it in one of the set paths?
irneb
2010-08-27, 05:57 AM
Ok, so this may be a stupid question but how do I now save out the "ShearWallSymbol" in a way that the LISP routine will see it in one of the set paths?Uhmm ... have you ever used the WBLOCK command? It's not exactly new ... I've used ACad for over 20 years, and I can't remember any version without it!
matthew g.
2010-08-30, 04:25 PM
<chuckle> yes, I've used it for many moons. However, it doesn't work from within the block editor and if I WBLOCK out an already inserted block don't I still have the same issue of the block now being nested and therefore it won't prompt me?
Nevermind, I've always just manually selected the block to WBLOCK out and then had the nesting problem. I did it using the "Block" radio button in the WBLOCK dialog and that worked out much better. Thank you again for all of your help irneb, it is greatly appreciated and I will be editing that LISP along with many other to take your suggestions into account. Most of them are a good decade old so it doesn't surprise me that they need to be revised.
irneb
2010-08-31, 06:01 AM
Well, there's a slight trick with WBlock. If you select one (and only one) reference of a particular block, and if it's not a DB with some edited parameter, then WBlock should automatically select its name from the Block drop-down. Otherwise its Objects option is turned on - which is going to nest the block as you've said.
matthew g.
2010-09-03, 05:36 PM
Thanks again for all of your help, finally got this one working and now I know how to do several others that need updating and fixing to be dynamic as well.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.