AutoCAD 2010/2011/2012

Reply
Valued Contributor
Rikkes
Posts: 77
Registered: ‎04-07-2008
Message 1 of 11 (1,278 Views)
Accepted Solution

Inserting blocks with macro

1278 Views, 10 Replies
11-15-2012 07:02 AM

Hi,

 

I recorded a macro that inserts a block in top view. It works good but it takes allways the last inserted block, just like the insert command. 

I would like to create a few buttons with macros tha insert a predefined block.

For example: I need a button that, when clicked, inserts 'drawing.dwg' in top view AND exploded.

Can you help me out with that?

 

Thx

 

Rikkes

 

Valued Contributor
golf32902
Posts: 59
Registered: ‎12-01-2008
Message 2 of 11 (1,230 Views)

Re: Inserting blocks with macro

11-19-2012 07:29 AM in reply to: Rikkes

The easiest way is to write a lisp that would insert the block. Then you can assign the new command to a button.

 

(defun c:Blockinsert ()
  (command "insert" "File Path" (getpoint "\nSelect insertion point: ")
    "1" "1" "0" )
  (princ)
  )

 

Just fill in the File Path and then rename the Blockinsert to whatever you would like. Save that file as a .lsp and then load it in autocad using appload.

 

After it is loaded then make a button and make the command read the same as whatever you renamed the Blockinsert to.

 

Let me know if you need any help.

**Master
dmfrazier
Posts: 2,722
Registered: ‎05-13-2003
Message 3 of 11 (1,211 Views)

Re: Inserting blocks with macro

11-19-2012 01:41 PM in reply to: Rikkes

If you prefer not to delve into AutoLISP in the short term (I recommend it for the long term), you can also put the following simple macro right into the macro field of a custom command via the CUI editor:

 

-INSERT *DRAWING \\\\

 

The "-" in front of the INSERT command says to use the command-line version (this is optional).

The space after the command and other input is equivalent to hitting the Enter key.

The "*" at the beginning of the block/drawing name means insert exploded.

The backslashes (one for each prompt for user input) mean pause for user input of the insert point, X-scale, Y-scale, rotation. (If you want to force any of these, replace the slash with the point or value.)

(Note that for this macro to work you must have the path to the file in your support files search path, otherwise you would have to include the entire path to the file.)

 

I'm not sure what you mean by "in top view", but I assume you mean the user would insert the drawing while plan to the view it should appear in.  This is not something you can automate easily, so you'll have to rely on the user for that.

 

 

Valued Contributor
Rikkes
Posts: 77
Registered: ‎04-07-2008
Message 4 of 11 (1,200 Views)

Re: Inserting blocks with macro

11-19-2012 11:38 PM in reply to: Rikkes

Allright! That works for so far!

 

But... I would like to add a few things to the command:

 

First, the drawing that I'm working in should turn to top view first, before inserting the new part, even when I am in working in front view. It doesn't have to go back to the original view. Just go to top view an insert the new drawing.

 

Second: I would like to explode the inserted drawing.

 

Hope you can help me out. I's working great so far!  :smileyvery-happy:

 

Rikkes

**Master
dmfrazier
Posts: 2,722
Registered: ‎05-13-2003
Message 5 of 11 (1,192 Views)

Re: Inserting blocks with macro

11-20-2012 05:44 AM in reply to: Rikkes

Well, I'm glad to hear it works (so far).

As I noted in my previous post, the asterisk (*) preceding the drawing/block name results in the "block" being inserted exploded, so that is already taken of.

As for "turn to top view first", you can add the commands for doing that to the beginning of the macro (between ^C^C and -INSERT).  The way to figure out the macro contents is to run through the process yourself on the command line and record your keyboard and mouse input.  See Help topic "Overview of Macros" for more info about how to enter macros in the CUI editor. 

Valued Contributor
golf32902
Posts: 59
Registered: ‎12-01-2008
Message 6 of 11 (1,189 Views)

Re: Inserting blocks with macro

11-20-2012 05:48 AM in reply to: Rikkes

Dmfrazier is correct. That would be the easiest way to do that.

Valued Contributor
Rikkes
Posts: 77
Registered: ‎04-07-2008
Message 7 of 11 (1,182 Views)

Re: Inserting blocks with macro

11-20-2012 06:13 AM in reply to: Rikkes

Guys,

 

This is the lisp file I made myself, with the 'top view' option included (found out this morning :-)) (It's 3PM in Belgium right now)

 

(defun c:zijkant ()
(command "view" "top") 
(command "insert" "//SERVERBOOM/DataBoom/BOOM/Jobs/ACad Sjablonen/Zijkant met rijboring basis.dwg" (getpoint "\nSelect insertion point: ")
    "1" "1" "0" )
  (princ)
  )

 

This works fine but it doesn't explode. 

 

Now, when I add an asterisk just before //SERVERBOOM.... etc. it does something weird. It goes to top view, then, on a click it inserts the block, explodes and then says that '0' is a bad command. When I look at the inserted block is is rotated left by 1°. I think the asterisk is not at the right position there...

 

We're getting closer...:smileywink:

**Master
dmfrazier
Posts: 2,722
Registered: ‎05-13-2003
Message 8 of 11 (1,171 Views)

Re: Inserting blocks with macro

11-20-2012 07:09 AM in reply to: Rikkes

"This is the lisp file I made myself..."

Don't you mean the LISP you modified from golf32902's original?:smileywink:

 

If you put the asterisk between the double-quote and the double slashes, it's in the right place.

I think the problem is that when inserting a drawing "exploded", the command only needs one argument for the scale factor, so the second "1" is being taken as the rotation angle, after which the "0" is interpreted as a new, unknown command.

Valued Contributor
Rikkes
Posts: 77
Registered: ‎04-07-2008
Message 9 of 11 (1,165 Views)

Re: Inserting blocks with macro

11-20-2012 07:29 AM in reply to: Rikkes

BAM!

 

It works! 

 

Thx a lot!!!

 

Rikkes

Valued Contributor
golf32902
Posts: 59
Registered: ‎12-01-2008
Message 10 of 11 (1,149 Views)

Re: Inserting blocks with macro

11-20-2012 02:51 PM in reply to: Rikkes

if you wanted to use the lisp then it would be showen with a * before the link to the dwg file. It will look like so.

 

(defun c:zijkant ()
(command "view" "top") 
(command "insert" "*//SERVERBOOM/DataBoom/BOOM/Jobs/ACad Sjablonen/Zijkant met rijboring basis.dwg" (getpoint "\nSelect insertion point: ")
    "1" "1" "0" )
  (princ)
  )

 

This will exploded the block that you are inserting.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community




Connect with AutoCAD

Twitter

Facebook

Blogs

Pinterest

Youtube