Hello Reader
I am new to LISP and I am hoping you can help me with a problem of mine...
So after defining attributes, i created a block by using the wblock command. Now, when I insert the block, a dialog box pops up asking for the values of the attributes i created.
I am inserting the block using autolisp, is there a way I can provide the values for the dialog box within the autolisp code... so that when the command is run... the block gets plotted with the attribute values set and no dialog box pops up ??
In short, i dont want the block to get user input. Instead i want tohard code those value within the autolisp code.
Please help...
Add (setvar "ATTDIA" 0) before the ._INSERT part and reset back to (setvar "ATTDIA" 1) after entering all the attribute values.
Hi @TomBeauford
Thankyou for your response
could you please explain it a little more..
I am using this command
(command "_insert" strBlockName1 insertpt1 "" "" "") to insert the block.. where should i hardcode the values for my attributes ?
I have attached an image of the dialog box.. can you tell me how to provide the values for them within the code ?
You can just feed Attribute values in at the end of the Insert command. Inside a (command) function, it won't use the dialog box.
(command "_.insert" "YourBlockName" YourInsertionPoint "" "" "" "YourAttributeValue1" "YourAttributeValue2" "YourAttributeValue3")
YourInsertionPoint is however you need to specify it [a (getpoint) function, or pause, or a variable name that holds a location, etc.). The "" "" "" are for default X and Y scale factors of 1 and Rotation of 0. If the Block is defined for uniform scaling, remove one "". Feed in the Attribute values in [EDIT:] reverse order of creation of the Attribute Definitions.
The "ATTDIA" var controls the "attribute dialog". If set to 1, then show the attribute dialog on attributed block insertion. If set to 0, then do not show the attribute dialog on attributed block insertion.
Your code would look like :
(defun C:YOUR-BLOCK_INSERT_COMMAND (/ ATD ATR strBlockName1 insertpt1)
;| any additional code here |;
(setq ATD (getvar 'attdia))
(setq ATR (getvar 'attreq))
)
The above code is only an example. I hope it helps.
Hi @Kent1Cooper
Thankyou for responding to my query
For the insterpt1... i have defined it like this:
(setq insertpt1 (list 16.88 10.88))
I have tried your method and I changed my code to this:
(command "_insert" strBlockName1 insertpt1 "" "" "" "ABC" "DEF")
But the dialog box still pops up...
@ss6153 wrote:
....
But the dialog box still pops up...
I must have sub-consciously been thinking the ATTDIA setting was saved in the drawing, and testing in a new one and not getting the dialog box I assumed that would be the default operation. But it's saved in the Registry, and mine is set to 0.
You need to have attdia 0 and attreq 1. That's all.
A dash isn't necessary, which is in line with the usual LISP rules that when a command has both COMMAND (with dialog) and -COMMAND (without dialog) versions, LISP will use -COMMAND automatically even if the dash isn't specified. But some newer commands violate this... and require a dash in LISP. So it is better to include it.
Code untested.
(defun c:InsertMyBlock (/ *error* atd atq) (defun *error* (errmsg) (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end")) (princ (strcat "\nError: " errmsg))) (if atd (setvar 'attdia atd)) (if atq (setvar 'attreq atq)) (princ)) ; ----------------------------------------------------------------------------------------- (setq atd (getvar 'attdia)) (setvar 'attdia 0) (setq atq (getvar 'attreq)) (setvar 'attreq 1) (command "_.-insert" "MyBlockName" "_scale" 1 "_rotate" 0 pause ; for user point input "Att1Value" "Att2Value" ) (*error* "end") (princ) )
Can't find what you're looking for? Ask the community or share your knowledge.