Last week we covered about loading AutoLISP file. You learned how to load, and optionally put your LISP to startup suite. Startup suite will load LISP automatically every time you start AutoCAD.
In this post, you will learn how to load AutoLISP program using acaddoc.lsp.
We also had another post about excel datalink. The problem with datalink is, it’s not updated automatically. We have to update it manually. It means we may send or plot files that use old value.
In this post, you will also learn how to make AutoCAD automatically update datalink when we save or plot our files. We will define our own plot and save command.
Getting started with acaddoc.lsp
What is ACADDOC.LSP?
In short, it’s also an AutoLISP file. The difference is, AutoCAD will execute it every time we create or open a drawing file. If you want further explanation, Jimmy Bergmark explain about ACADDOC.LSP in details here.
Create a new LISP file. You may use text editor or visual LISP editor to do it. Save it to a support file path. You may choose any existing path, or create your own support path.
I would recommend you to do the later, and you can also save all your LISP file there.
Loading AutoLISP program in acaddoc.lsp
You can load AutoLISP program using this line:
This sample below will load cnlabel.lsp and zoomextend.lsp.
Loading AutoLISP command is something quite basic we can do with acaddoc.lsp. Next, we will try to define our own command here.
Undefine and define PLOT function in acaddoc.lsp
In the next step, we will change how AutoCAD command work. Like we discuss before, we will change plot and save command. First, we need to undefine it.
Undefine and redefine
We can undefine AutoCAD command using UNDEFINE.
In AutoCAD command line, type UNDEFINE [enter] then PLOT [enter].
We just undefine plot command. Try to type plot in command line and see how AutoCAD will response.
Unknown command “PLOT”. Press F1 for help.
After we undefine PLOT, AutoCAD will not recognize it anymore.
Now try type .PLOT [enter]. Notice the dot before PLOT command. Plot command should work. The dot means we use AutoCAD built in command.
After we finished, PLOT and .PLOT will give different result. The first one will use plot we define in acaddoc.lsp. The last one use AutoCAD built-in plot command.
You can activate PLOT command back using REDEFINE [enter] PLOT [enter]
Defining function in acaddoc.lsp
Now let’s work with acaddoc.lsp. First we undefine PLOT, then define new command. The new plot command should update datalink before start to plot.
Our code become like this:
; This line below will undefine existing PLOT command
(command "undefine" "plot")
; This line below will define new PLOT command
(defun c:PLOT ( )
(command "_DATALINKUPDATE" K)
We use INITDIA to load AutoCAD plot dialog. If we don’t use INITDIA before plot, then you will not see the dialog box. You will need to setup the plot using command line.
Save this AutoLISP file. Create or open a new file then activate plot. You will see after I create a new file, our code will undefine plot. Then when we use PLOT command, it updates datalink first, then activate plot. Nice, isn’t it?
AutoCAD menu utilities loaded.undefine Enter command name: plot
Select an option [Update data link/Write data link] <Update data link>:
Update datalink when saving file
Now we don’t have to worry when we plot files. It surely will use most updated value from excel files. But we haven’t finished. We need to make sure datalinks in our files are updated before we send them. We need to modify save and saveas command.
It’s very similar with plot. You can modify them as your exercise. Discuss it here if you have problem.
How do you think acaddoc.lsp can be useful?
Do you think you can make use of acaddoc.lsp? Do you prefer to load AutoLISP from startup suite or this method?
And what command you want to modify? What do you want it to do? Share it here, the others might find it useful too!