lisp for insert block from another drawing

lisp for insert block from another drawing

Anonymous
Not applicable
5,898 Views
9 Replies
Message 1 of 10

lisp for insert block from another drawing

Anonymous
Not applicable
^C^C_insert;"Template";^C-insert;"*Block 1";0,0;;;

I use the above macro script to insert 'Block 1' from Template.dwg into current drawing at 0,0,0 & explode it. I have the folder location in my search path.

Please help to convert this macro script into a lisp that does exactly the same thing.

Thanks in advance

Accepted solutions (1)
5,899 Views
9 Replies
Replies (9)
Message 2 of 10

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:
^C^C_insert;"Template";^C-insert;"*Block 1";0,0;;;

....

Please help to convert this macro script into a lisp that does exactly the same thing.

....


This should do it [untested]:

 

(defun C:IB1 (); = Insert Block 1

  (command "_.insert" "Template") (command)

  (command "_.insert" "*Block 1" "0,0" "" "")

  (princ)

)

 

The (command) function with no arguments is to cancel the first Insert command after the definition has been brought in [read about it in Help for (command)].

 

Change the IB1 to whatever you prefer as a command name.

Kent Cooper, AIA
Message 3 of 10

Anonymous
Not applicable

@Kent1Cooper wrote:

@Anonymous wrote:
^C^C_insert;"Template";^C-insert;"*Block 1";0,0;;;

....

Please help to convert this macro script into a lisp that does exactly the same thing.

....


This should do it [untested]:

 

(defun C:IB1 (); = Insert Block 1

  (command "_.insert" "Template") (command)

  (command "_.insert" "*Block 1" "0,0" "" "")

  (princ)

)

 

The (command) function with no arguments is to cancel the first Insert command after the definition has been brought in [read about it in Help for (command)].

 

Change the IB1 to whatever you prefer as a command name.


Thanks man. It works!

0 Likes
Message 4 of 10

m.jouini
Observer
Observer

Thank you it works !

However, is it possible to modify the script in order to get the X and Y coordinates from the user's input and not to have them predefined ? In addition to that, can we fix the Z coordinate to a fixed value ?

0 Likes
Message 5 of 10

Kent1Cooper
Consultant
Consultant

@m.jouini wrote:

.... is it possible to modify the script in order to get the X and Y coordinates from the user's input and not to have them predefined ? In addition to that, can we fix the Z coordinate to a fixed value ?


You can change the Insert line:

(command "_.insert" "*Block 1" pause "" "")

 

If you always want the Z to be the same, but the User's input at the pause might involve some different Z value, try:

(command "_.insert" "*Block 1" ".XY" pause YourZvalue "" "")

Kent Cooper, AIA
Message 6 of 10

Sea-Haven
Mentor
Mentor

Another option maybe worth looking at is Lee-mac Steal.lsp can be program driven known block name, no user input, also does much more including multiple blocks in one go.

0 Likes
Message 7 of 10

m.jouini
Observer
Observer

Thank you very much for your fast response !

 

You can change the Insert line:

(command "_.insert" "*Block 1" pause "" "")


this one worked very well as intended!

 


If you always want the Z to be the same, but the User's input at the pause might involve some different Z value, try:

(command "_.insert" "*Block 1" ".XY" pause YourZvalue "" "")


however, maybe I missed something here but when I try this script it doesn't work for me as it's supposed to.

this is the script in my example :

  (command "_.insert" "Picto Asc" ".XY" pause 3 "" "")

I want the bloc to be always placed at a height of 3 (Z value=3)

here's how it works after I execute it :

1) it tells me to specify an insertion point :

mjouini_0-1678871512074.png

2) After I select an insertion point, it's supposed to be placed automatically in it with a value of Z=3. But a (need Z) appears in the dialogue box :

mjouini_2-1678871979522.png

3) if I click, the bloc is infact inserted in the insertion point I've chosen but with Z=0 and scaled by 3 in X,Y and Z axis.

mjouini_3-1678872167913.png

What did I miss ?

0 Likes
Message 8 of 10

Kent1Cooper
Consultant
Consultant

@m.jouini wrote:

.... when I try this script it doesn't work for me as it's supposed to.....

What did I miss ?


You didn't -- I did.  I confess I hadn't actually tried it, relying on it to work the same way in an AutoLisp (command) function as it does manually at the Command: line.  I don't know why it doesn't, but this variant approach seems to work:

 

(command "_.insert" "Picto Asc" ".z" "0,0,3" pause "" "")

Kent Cooper, AIA
Message 9 of 10

m.jouini
Observer
Observer

Thank you, it worked !

 

0 Likes
Message 10 of 10

TomBeauford
Advisor
Advisor

The -INSERTCONTENT command was added with the 2021 version of AutoCAD which finally allows you to insert a block directly from another drawing. This macro starts the command and display the Select Drawing File dialog box for the drawing with the block you want to insert:

 

 

^C^C-INSERTCONTENT ~;

 

 

To account for spaces in file names and paths you need to use a semicolon for enter in these macros. The tilde (~) was to display the Select Drawing File dialog box in the macro above, do not include it with macros that include filenames.

This macro example inserts the block "Construction Entrance" from drawing G:/ENGDESGN/BeaufordT/Blocks/Typicals/Typicals.dwg

^C^C-INSERTCONTENT G:/ENGDESGN/BeaufordT/Blocks/Typicals/Typicals.dwg;Construction Entrance;

HTH

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