Jump to content

Macro to insert text block


Recommended Posts

Posted

First off I'm very new to this and have figures some of this out by digging on google. So you'll have to talk really slow.

 

I'm wanting to make a macro that will insert a particular text block I have created. It would be great if I could make one that would even let me insert information to create the block but for now I am happy with editing the block after it is inserted.

 

I have gotten far enough that it will insert my block on the first attempt, but it also opens autocad help. the second time I try to use the command it either doesn't work, redoes the last command, or opens the CUI dialog box. Below is the macro I used. Any suggestions are greatly appreciated.

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    9

  • Chad_bestmnf

    9

  • Glen Smith

    4

  • ReMark

    1

Posted

Firstly,

 

Welcome to CADTutor! We hope you like it here :)

 

You could use a macro to automate this task - but why not delve into the exciting world of LISP :P

 

The routine would be much more robust, and you could edit attributes/perform rotations/breaks... the list is endless :)

 

Lee

Posted

I am all for it. The only problem is Macros are still about ten feet over my head can you help me understand a lisp? where to insert that text?

Posted

If you want to learn the fundamentals of LISP, check out a few of these:

 

http://www.cadtutor.net/forum/showthread.php?t=38760

 

http://www.cadtutor.net/forum/showthread.php?t=38734

 

http://www.afralisp.net/

 

http://www.jefferypsanders.com/autolisptut.html

 

http://ronleigh.info/autolisp/index.htm

 

http://midpointcad.com/au/docs/lakose_The_Visual_LISP_Developers_Bible.pdf

 

 

But to get you started, this is probably the simplest way to insert your block using LISP:

 

(defun c:ins (/ blk iPt)

 (setq blk "programstamp") ;; Block Name

 (cond ((not (or (tblsearch "BLOCK" blk)
                 (setq blk (findfile (strcat blk ".dwg")))))
        (princ "\n** Block Not Found **"))

       ((setq iPt (getpoint "\nSelect Point for Block: "))
        (command "_.-insert" blk "_non" iPt 1. 1. 0.)))

 (princ))

 

Note:- this could be improved in many ways, by use of error handlers etc - but lets start you off on the easy stuff :)

 

Lee

Posted

Welcome to CADTutor!

 

First thing to know is that Lee would (and probably can) write a LISP routine to read his mind and enter his drawings directly.

 

Getting the Macro to insert your block is definetly within your reach today, writing a LISP to do it will take some time.

 

The best way to get a macro right is to do the function that you are trying to automate (as much as possible) via the keyboard, once done, open the Autocad Text Window (hit F2) and look at what you typed. The "Enter" key is coded in your Macro as a semicolon ";" you are short a few of them in your macro. If you need user input, either keyboard or a mouse click for an insertion point use the "\".

 

To get a full list of the special chars, search for "Use Special Control Characters in Macros" in AutoCAD help.

 

Good luck, and post if you need more help.

 

Glen

Posted

Thanks Glen - maybe I was stepping forward too quickly with it - you know how I get o:)

Posted
Thanks Glen - maybe I was stepping forward too quickly with it - you know how I get o:)

 

 

No dig, I just remember how thriled I was when I wrote my first macro (which I still use) that zoomed extents on both the model and layout tabs, saved and closed the drawing.

 

Then I found out what LISP can do and I realized just how much more there was to learn.

 

Then I found out that you taught yourself LISP in basically a year (right?) and went home to 'have a lay down'.

 

Glen

Posted
No dig, I just remember how thriled I was when I wrote my first macro (which I still use) that zoomed extents on both the model and layout tabs, saved and closed the drawing.

 

Then I found out what LISP can do and I realized just how much more there was to learn.

 

Then I found out that you taught yourself LISP in basically a year (right?) and went home to 'have a lay down'.

 

Glen

 

I know what you mean - except mine was kinda the other way around - I found out about LISP first, then learnt about macros somewhere along the way (but never pursued them too far).

 

Yeah, will be about a year this month :)

Posted

It is said that God created the world in six days and took the seventh one off to watch football.

 

Lee Mac would have taken one day to write the code that would have created the earth on day two. The other five days he would be bored.

Posted
It is said that God created the world in six days and took the seventh one off to watch football.

 

Lee Mac would have taken one day to write the code that would have created the earth on day two. The other five days he would be bored.

 

Haha :lol:

 

Thanks ReMark, but I still have a lot to learn myself :) LISP is just the tip of the iceberg...

Posted

I'm having some trouble. I'm on one of the website you gave me and it wants me to save the text in notepad as "ASCII Text file" I don't have that option in notepad. Do I need to download an update or another program

Posted

If you are saving a LISP file, copy the code into Notepad and save as .lsp, Make sure you have "ALL FILES" set in the "Save as type" box.

Posted

I tried that and couldn't seem to get it to work. A guy I work with pointed out that I have notepad++. That seems to work perfect. Thanks

Posted

Ok I have entered the lisp you gave me and Its giving me. C:INS

what do I need to do different?

Posted

Glen. I have gone through the process like you suggested and hand wrote down every step to get what I want. I can't see where you say I need more enters. Can you help

Posted

Ok, here is a copy of an insertion of a block from the text window.

 

Command: -insert
Enter block name or [?]: blockname
Units: Unitless   Conversion:      0'1"
Specify insertion point or [basepoint/Scale/X/Y/Z/Rotate]:
Enter X scale factor, specify opposite corner, or [Corner/XYZ] <1>:
Enter Y scale factor <use X scale factor>:
Specify rotation angle <0.000>:

 

so your macro needs to be

^C^C ~to cancel any previous commands that may be running

-insert ~to kick off the block insert command

; ~to hit enter after the command

BLOCKNAME ~the name of the block that you want to insert

; ~to hit enter after the name of the block

\ ~to get user input for the insertion point (a mouse click)

; ~to take the default Xscale factor of 1

; ~to take the default Yscale factor of same as Xscale factor

; ~to take the default rotation angle of 0.00 degrees

 

 

That should be the whole thing all on one line the macro would look like:

^C^C-insert;BLOCKNAME;\;;;

 

This assumes that the block is available in the drawing already. Check the design center to be sure. You can also set the ATTREQ system variable to 1 and CAD will bring up the attribute editor so you can plug in your text.

 

Pay attention to the command line window as you work on entering your macros. If you are missing stuff, usually there will be prompts waiting for you to enter them. Once you know how far what you have in there got you, you can see what still needs to be added.

 

Good luck!

 

Glen

Posted

To slightly clarify, ATTREQ and ATTDIA are two system variables that work together. ATTREQ controls whether AutoCAD assumes the default values for your attributes or REQuires you to enter values. ATTDIA controls whether you get a DIAlog box with places to enter the attributes or just get prompted at the command line.

 

Glen

 

PS,

 

If you got to the point with the LISP that AutoCAD gave you C:ins then you probably have managed to load the LISP routine. To execute the LISP, just type INS at the command line.

Posted

Lee Mac, I went to that hyperlink and followed the instructions but still couldnt' accomplish running the lisp. I got as far as it saying "successfully loaded" then when I typed it into the command line it says unknown command. Do I just need to leave it alone and pull out a pen and piece of paper or could there be some setting that would prevent me from running lisp??? I don't consider myself stupid but starting to wonder if I should rethink my stand on that subject.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...