Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Insert block without dialog box

11 REPLIES 11
Reply
Message 1 of 12
ss6153
2031 Views, 11 Replies

Insert block without dialog box

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

11 REPLIES 11
Message 2 of 12
TomBeauford
in reply to: ss6153

Add (setvar "ATTDIA" 0) before the ._INSERT part and  reset back to (setvar "ATTDIA" 1) after entering all the attribute values.

64bit AutoCAD Map & Civil 3D 2023
Architecture Engineering & Construction Collection
2023
Windows 10 Dell i7-12850HX 2.1 Ghz 12GB NVIDIA RTX A3000 12GB Graphics Adapter
Message 3 of 12
ss6153
in reply to: TomBeauford

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 ?

Message 4 of 12
Kent1Cooper
in reply to: ss6153

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.

Kent Cooper, AIA
Message 5 of 12
mid-awe
in reply to: ss6153

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

(setvar 'attdia 0)
(setvar 'attreq 0)
(command "_insert" strBlockName1 insertpt1 "" "" "")
;| any additional code here |;
(setvar 'attdia ATD)
(setvar 'attreq ATR)
(princ)

)

 

The above code is only an example. I hope it helps.

 

Message 6 of 12
ss6153
in reply to: Kent1Cooper

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

Message 7 of 12
ss6153
in reply to: mid-awe

Hi @mid-awe 
Thanks for the detailed explained but sorry.. i will ask once again.. where do i hardcode my attribute values??? 
When i incoporate your code..the dialog box doesn't pop...but the attribute values are still not set for the block. 

Message 8 of 12
john.uhden
in reply to: ss6153

Remember what was told you about ATTDIA.

John F. Uhden

Message 9 of 12
Kent1Cooper
in reply to: ss6153


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

Kent Cooper, AIA
Message 10 of 12
Sea-Haven
in reply to: ss6153

Maybe "-insert" 

Message 11 of 12
ВeekeeCZ
in reply to: ss6153

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

 

Message 12 of 12
mid-awe
in reply to: ss6153

I had assumed that the values were made as default values for the block. My misunderstanding...
Z9E3zK5E's answer is correct; "You need to have attdia 0 and attreq 1".

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report