In this Article...
Hai Le has shared some cool tips how to utilize macros in AutoCAD. He shows that customization doesn’t have to be complex.
Check some old tips he shared me before:
- Restore AutoCAD standard layers and styles.
- Automatic dimension spacing with double click.
- More macro tips to change UCS and text layer.
Macro is very useful, but you are limited to use it in CUI. You can access macro in toolbar, ribbon, double click or tool palettes. But if you want to use command line, then you have to use AutoLISP.
Just like macro, customization doesn’t have to be complex. Here are some secondary commands idea from Hai Le.
Secondary commands
AutoCAD commands have many settings that you can change in command line when the command is running. If you often change setting when you use a particular command, it would be a good idea to create a secondary command. Below are two ideas that you can use as secondary commands.
O for OFFSET, OO for OFFSET to current layer
By default AutoCAD Offset command will create a result on the same layer as original object. You can change the layer to current layer by changing the parameter when offset command active. It would be faster if you type OO to create the result on current layer, isn’t it?
You certainly can use OC as the command. But the idea of secondary commands here is to have options for available commands quickly. It’s much faster to type OO than OC, right?
Check this first AutoLISP tutorial: Zoom to origin. The tutorial will give you an idea how you can create simple customization by creating a LISP program.
Similar as described in that tutorial, you can create similar program to make Offset to current layer with this code:
(defun c:OO (/ )
(command "_OFFSET" "L" "C")
)
You can create another LISP to create object on the same layer as source object like this:
(defun c:OOO (/ )
(command "_OFFSET" "L" "S")
)
Of course, you can use other command than OOO if you like.
M for MOVE, MM for MOVE previous selected objects
Another idea is to create a custom command to move previously selected objects. Here is the code:
(defun c:MM (/ )
(command "_MOVE" "P")
)
Instead of typing M enter then P enter, you can type MM then enter.
You can download the LISP code above here. If you don’t know how to load AutoLISP program, read about it here.
Do you have an idea about other secondary commands?
If you like the idea of creating secondary commands, you may have some ideas to create a command that you use often. Do you have an idea to share with us? Write in this comment section so other readers can read about it too!
We surely can learn something from you too.
And thanks to Hai Le for the cool idea!
I was in a business that had a lot of .25 radius fillets. a LISP line was created:
(defun c:F25 () (command “fillet” “r” “.25” “fillet”))
This would start the fillet command, set the radius to .25 and restart the fillet command to let you fillet what ever needs the fillet.
That is excellent Guy!
Thanks for sharing.
Hi there,
So I’ve just started looking into LISP and Macro’s and really don’t know much but I want to create the following command and I’m not finding the information I need :( (I’m not good with searches…)
The details of the command:
Once executed, the command opens a specific folder and presents the contents of the folder as options in the command line and as a dynamic menu.
On user selection, the folder is opened and the contents again displayed in the command line and as a dynamic.
This will continue until a dwg is selected at which point the command INSERTS the selected drawing.
The point of this is to increasing good old productivity.
Yes, I can easily set up a tool palette with all my blocks in and just drag and drop but there is more to this command, one step at a time though. First I need to write the script that will create the menu’s to get me to point of the block being inserted.
Do you know of any resources that can help?
Have you tried using Design Center? You can see the block thumbnail and insert it from any DWG file.
However, if you prefer to use LISP anyway, you can try to ask in CADtutor forum: http://www.cadtutor.net/forum/forum.php
There are many AutoLISP masters there who can you help you with it. My LISP knowledge is still basic, just for my own use.
I’m sorry I can’t be more helpful.
Hi Edwin,
Thanks for the reply. I do already use design center but my end purpose is to create tool that inserts a block selected by the user and then performs a single row array in ‘x’ with a user specified number of columns and the blocks touching end to end.
It may well be that I need to use VisualLISP or something else, LISP is just where I have started
I’ve written V.1 of the array part of this tool (see below) which cuts down on data entry as it auto fills all the information regarding rows. The main improvement I want to achieve in this routine is to have the routine work out the column width from the block as this removes another user input point leaving the only user inputs being to select the block and enter the quantity of columns required.
I’ll check out the site you have suggested, hopefully I’ll find something there.
Here’s my little array command:
(defun c:xarray()
(setq oldsnap (getvar “osmode”))
(setvar “osmode” 1)
; this is to make selecting the ends of the block easier without the user
;having to change their snap settings
(command “array” pause “” “rectangular” “1” pause pause “”)
(setvar “osmode” oldsnap)
; this returns the snaps to the users previous settings
(princ)
)
(princ)
Wow! I am definitly not to where i would try this, yet. I will be soon, I just need the enviornment and mind syncronicity.
Hey Edwin,
I had started a new job I had been a long time AutoCad user since 2003 but had stopped using it on 2010. The problem is the job I have me will require me to use autocad and revit and ai had found this website which is really helpful.
I know you are busy but I hope you would be able to help me go back to the proficent level and I am anout to embark a new learning progress with Revit.
Can sou help me what to do?
I made en lisp to move multiple times te same selection.
;;;Move Multiple
(defun c:MMultiple (/ ss1 L1 L2)
(setq ss1 (ssget))
(while (setq L1 (getpoint “\nBasepoint (1): “))
(setq L2 (getpoint L1 “\nReferencepoint (2): “))
(command “MOVE” ss1 “” L1 L2)
) ;_ end of while
(princ)
) ;_ end of defun
That is cool!
Thanks for sharing.
I am hoping that you could help figure out a macro to add to current autocad commands to force object to a specific layer and return to previous layer, aca 2016