Using Lisp Command to insert a Block then adjust block attributes

Using Lisp Command to insert a Block then adjust block attributes

Anonymous
Not applicable
2,351 Views
20 Replies
Message 1 of 21

Using Lisp Command to insert a Block then adjust block attributes

Anonymous
Not applicable

My questions is I found a basic lisp that takes a block and inserts it into a drawing. The block I want to use has attributes that makes you fill in a data table. For some reason when using the lisp I cant activate the attribute prompt (Just acts like a dumb block). But if I skip the lisp and just insert the block into the drawing the attribute menu pops up. So my questions is why is this giving different results???

0 Likes
2,352 Views
20 Replies
Replies (20)
Message 2 of 21

ВeekeeCZ
Consultant
Consultant

That could be managed by a code. Post the code and we tell you what's wrong.

BTW some dialog prompts are suppressed by using in LISP code automatically .

0 Likes
Message 3 of 21

Anonymous
Not applicable

(defun C:ins ()
(initget 1 "1--InfoBlock 2--Blockname2 3--Blockname3") ;;;; not space ;;;; 1-- =4 >>> (substr A 4
(Setq A
(getkword
"\n*** Info *** :
[
1 *** Info Block /
2 *** Blockname2 /
3 *** Blockname3 /
]<1>
"

)
);setq
;;// Note: <1> = Set default number 1
(setq B (substr A 4 70))
(setq C (strcat "*" B))
(setq pt (getpoint "Specify insertion point:"))
(command "insert" C pt "1" "0") ; "1" = scale "0"=angle
(princ)
);defun

0 Likes
Message 4 of 21

Moshe-A
Mentor
Mentor

set this system variable before running your lisp

 

attreq =1

 

moshe

0 Likes
Message 5 of 21

ВeekeeCZ
Consultant
Consultant

And ATTDIA 1 for dialog 

or 0 for cmd setting: (command "insert" C pt 1 0 "Hello")

ATTREQ 1 for sure.

0 Likes
Message 6 of 21

Anonymous
Not applicable

all ready set to 1

0 Likes
Message 7 of 21

Moshe-A
Mentor
Mentor

then change this line

(command "insert" C pt "1" "0")

 

to be:

 

(command "-insert" C pt 1 "0")

 

0 Likes
Message 8 of 21

ВeekeeCZ
Consultant
Consultant

Any particular attribute mode - like "Present"?

Can you post that block?

0 Likes
Message 9 of 21

Anonymous
Not applicable

Here is the Block I am thinking of using. The whole point is to have some sort of data tracking for each drawing so I know what was done for each job. So I dont have to spend hours trying to find the closet match for the next job I do.

0 Likes
Message 10 of 21

ВeekeeCZ
Consultant
Consultant

It must be 

(command "insert" C pt "1" "1" "0")   ; that's differ between uniform and non-uniform scale.

 

or better (command "insert" C pt 1 1 0) ; not need to be a string. An integer is fain.

 

or the best (command  "insert" C "_scale" 1 "_rotate" 0 "_none" pt) ; this way overcome above issue.

 

BTW. You're aware that you've posted block "Info Block" within the "InfoBlock" file, right? You need to insert the one with the space in you code!! (not sure about that iniget-getkword-substr thing... I think it's wrong.)

0 Likes
Message 11 of 21

Anonymous
Not applicable

If i change that command line it just makes me have to type in the insert point...... at least what i had before I just click and its placed in. so to add to the confusion. so if I insert that block that add a new attribute it wont work at all. so I dont know what to think.

0 Likes
Message 12 of 21

cadffm
Consultant
Consultant
I didn't take a look in the dwg, but i can read the insert sequence and there you dont create a new instance/reference from a blockdefinition, that is why adesk not asking for attribut values.

It is the same as you open the info block file, copy all by ctrl+c and paste it with ctrg+v, no dialog/question about attributes appears.

Note the "*" in the code and read about command -INSERT in F1

Sebastian

0 Likes
Message 13 of 21

cadffm
Consultant
Consultant

And after a look to the file, offtopic:

Inside the file "InfoBlock.dwg" the one blockreference of Block "Info Block"

a) is not well updated to the current blockdefinition (no attributes)

b) it is a reference of a anonym block, that show me it was a dynamic block which has not only a basepont parameter.

 

All of this can be done wisely by an admin or it is only a triple mistake of a user try,

for a normal User that isn't a good thing.

 

 

Sebastian

0 Likes
Message 14 of 21

ВeekeeCZ
Consultant
Consultant

Hmm, I thought you'll put it together after my last reply.
Anyway, let's don't make it such big deal, here you have something what works for sure. Just as a starting point...

 

(defun c:Ins ( / name pt)
  (initget "1 2 3 Infoblock Blockname blockName")
  (if (and (setq name (cond ((getkword "\nBlock name to insert [1:Infoblock/2:Blockname/3:blockName] <Infoblock>: "))
			    ("Infoblock")))
	   (setq name (cond ((wcmatch name "1,Infoblock")
			     "Info Block")
			    ((wcmatch name "2,Blockname")
			     "Block 2")
			    ((wcmatch name "3,blockName")
			     "Block 3")))
	   (setq pt (getpoint "\nSpecify insertion point: "))
	   )
    (progn
      (setvar 'attdia 1)
      (setvar 'attreq 1)
      (command "_.insert" name "_scale" 1 "_rotate" 0 "_none" pt)
    ))
(princ)
)

 

0 Likes
Message 15 of 21

cadffm
Consultant
Consultant

only the point with the file / file content remains .. in case the block does not exist yet.

Sebastian

0 Likes
Message 16 of 21

ВeekeeCZ
Consultant
Consultant

@cadffm wrote:

only the point with the file / file content remains .. in case the block does not exist yet.


WBLOCK the block somewhere, add the path between support paths. No biggie.

0 Likes
Message 17 of 21

cadffm
Consultant
Consultant

@Anonymous The last answer of BeeKeeCZ was more for you as a supplement to his previously provided Lisp. . WBLOCK, option Block -> Info Block

Then all works well for you. And if you have time, try to understand why it was not working befor with your Lisp and your file.

 

Sebastian

Message 18 of 21

Anonymous
Not applicable

so one question im confused about. When I run that lisp it inserts the block as it should but again it doesnt have any attributes. But if you use the insert command after it gives you two options Info_Test_Block and Infotestblock. Infotestblock is the one with the working attributes. So my question is, what can I do to differentiate the lisp command so the block with working attributes is inserted instead?

0 Likes
Message 19 of 21

cadffm
Consultant
Consultant
Read this again please
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/using-lisp-command-to-insert-a-block...
Check the statements in your attached file.

Or use tge bypass without understandig "why it happen" and export your blockdefinition as new file.
Open your file with the block, use command wblock, option block <selec the right blockname> .
The new created file you can use as blockdefinition and the result of the lisp is what you want.

The issue topic is" nested block"

Sebastian

0 Likes
Message 20 of 21

roland.r71
Collaborator
Collaborator

@Anonymous wrote:

Here is the Block I am thinking of using. The whole point is to have some sort of data tracking for each drawing so I know what was done for each job. So I dont have to spend hours trying to find the closet match for the next job I do.


This will not work. Keep in mind that using a dwg to -insert a block, the dwg is inserted AS block.

Since your DWG contains a block, you are actually inserting a block inside a block. Even if that block did contain attributes (which it doesn't !?!?!?) its nested inside a block without attributes.

 

Either explode the infoblock inside the infoblock.dwg, or use WBLOCK to export the block to a dwg, which you can use to insert it as a block. If the block already exists, you need to use a slightly different aproach in order to redefine the existing block. Otherwise the existing block will not change.