Thursday, August 24, 2006

Edit, Load and Protect your LISP files with VLIDE

Back in May I posted an article on Basic LISP. It should help you understand the format of lisp, some simple functions and how to load a LISP through the CUI interface. After you have progressed a little down the LISP programming path, you may want a better way edit, load and protect your LISP files. Enter the Visual LISP Interactive Development Environment or VLIDE.

You can invoke this environment from inside AutoCAD by typing vlide or vlisp on the command line.

Editing Made Easy
The figure above shows how the VLIDE environment interprets characters and color codes them making the creation of lisp files much easier. Lines commented by semicolons are shown in grey. Parentheses are always red, functions blue and variables magenta. Once you get used to the colors, most people never go back to a text editor.

I should note that there are a lot of simple editors out there that can really help you create code as well. I have been partial to Edit Pad for some time.

Protect Your LISP
There are a wide variety of tools inside this environment, but what I want to focus on the ability to take all of your LISP and combine and compile it in order to simplify loading it and protect your source code when sharing your LISP. To do this I use the “Make Application” from the “File” menu. If you are new to making applications, try the “New Application Wizard”. It will walk you through the whole process.


The making application process combines your LISP into a single VLX file that will run on any station yet the source code is compiled and unreadable to the user. This is handy when you want to sell your code or share your code, but you don’t want the recipient to be able to alter or build upon your code. During the process a FAS file is created for each of the individual LISPs contained in your VLX.

Loading VLX files
There are a lot of ways to load lisps, but here is what I choose to do. Once I have created the VLX file, I edit my acaddoc.lsp file to load the VLX when I start AutoCAD.

Here is a sample line of code to place in your acaddoc.lsp file.

(load "X:/lisps/ACME_lisps.vlx")

That’s it. You can add more load calls if you create more than one VLX. To update your VLX when you add a new LISP or change existing LISP select “Rebuild Application…” under File -> Make Application.

It’s tuff to be real generic and still address the details of what you might run into when you try it, so don’t be bashful about posting a comment to this article if you run into problems.

15 comments:

zeffer87 said...

I'M NEW TO AUTOCAD AND HAVING TO LEARNAT A RAPID PACE. MY BOSS IS ASKING ME TO MAKE SOME .LSP FILES, I HAVE FINALLY MADE SOME THAT WORK. THE PROBLEM IS THEY DON'T LOAD AUTOMATICALLY WHEN THE PROGRAM STARTS. WHAT DO I NEED TO DO DIFFERENTLY. I PLACED THE FILES IN A FOLDER WHERE OTHER FILES (.VLX) ARE LOADED FROM. IS THIS WRONG? ALSO CAN YOU HELP ME MAKE A LISP THAT WILL PLACE A CERTIAN LINE OF TEXT INTO A DRAWING? (EX. IF SOMETHING IS IN THE DRAWING ,THAT I RECIEVE FROM SOMEONE ELSE, THAT WE ARE NOT GOING TO MAKE I DONT WANT TO DELETE THE ITEM,BUT I WANT TO PLACE TEXT OVER IT THAT SAYS SOMETHING LIKE "NOT TO BE MADE HERE". YEAH I COULD DTEXT BUT I DO THIS MANY TIMES A DAY. CAN YOU HELP?

Todd M. Shackelford said...

Hey Zeffer87,

The simpliest way I know to have a lisp load automatically when you start AutoCAD is to type APPLOAD at the command line. In the dialog that appears in the lower left corner you will see a briefcase icon. Click on it and select ADD to add lisps that you would like loaded every time you start AutoCAD. This only works on the PC you do this on, so if you have 5 PCs in your office, repeat for each one.

As far as the lisp you want. What you are really talking about here is a way to insert a drawing that has the text you desire in it on the fly and at the appropriate scale. See my posting on Basic Lisp. You can use the "command" function to insert the dwg and the dimscale variablew to determine how to scale. I am away from AutoCAD right now, but I can post the lisp for you tomorrow.

Good luck.

zeffer87 said...

thanks for the quick response! I did get the lisp to auto load so we are good there.

Now the other problem I will probally be asking alot of q's about. I'll try not to take advantage of the situtation and annoy you. I really want to learn this lisp language and am going to try to take some training to do so.

I need the text to be accessible from any drawing. I get drawings from multiple states that I have to qc and as you know I can't save it as a block and import.

That would be to easy! So any help from a "professional" like yourself would be appreciated.

zeffer87 said...

thanks for the quick response! I did get the lisp to auto load so we are good there.

Now the other problem I will probally be asking alot of q's about. I'll try not to take advantage of the situtation and annoy you. I really want to learn this lisp language and am going to try to take some training to do so.

I need the text to be accessible from any drawing. I get drawings from multiple states that I have to qc and as you know I can't save it as a block and import.

That would be to easy! So any help from a "professional" like yourself would be appreciated.

zeffer87 said...

where do i need to look for the lisp? can you send me a link? thanks

Todd M. Shackelford said...

Zeffer87,

You can find my tutorial on lisp at...


http://lazydrafter.blogspot.com/2006/05/basic-lisp.html

I noodled around trying to write something that would create text on the spot, but I ran into trouble getting AutoCAD to accept lisp generated text. Way easier is what I mentioned before. Create a drawing with the desired text, then write a lisp to insert that drawing when needed. The code below could be used if placing the note as a palette tool.

^C^C-INSERT *X:/NetworkLocation/Note;\(*(GETVAR "DIMSCALE"));\

I hope this works for you. Good luck.

zeffer87 said...

Tool palettes was the way to go works great!!!! thanks for the help.
where can i find a list of input commands ( as in symbols that stand for something in lisp. how do you express "enter" I'm working on a lisp but can't complete it because I need it to enter on its on...

Todd M. Shackelford said...

Lisp is different than making a macro like shown above. An "enter" can be represented by a blank space or a semi colon. 2 quotes together like this "" will work in a lisp.

Anonymous said...

My main goal is to prevent vlx and lsp programs to be loaded even if it is attempted to be load by appload. Can you share some syntax on how to prevent custom programs (vlx, fas, or lsp) from being loaded again? I plan to put it under the acaddoc.lsp.

call me Ivan

Todd M. Shackelford said...

Ivan,

Your best bet here is un-defining the appload command. Here is a snipit of how to do that in acad.lsp


ACAD.LSP
(defun s::startup ()
(command “undefine” “appload”)
)

When "You" need to use appload, type a period in fromt of the command and it will work, like this (.appload).

Good luck.

Todd

Anonymous said...

Hi Todd,

Thanks for the help.

I tried the "undefine" and placed it under s::startup of acad.lsp just as you suggested. It's not working. I'm convinced it should work. But when I tried to type undefine in the command line it is working. I even placed it also under acaddoc.lsp. Pls. help again. thanks.

Ivan

Todd M. Shackelford said...

Ivan,

Can you copy your code into a comment so I can look at?

Todd

Anonymous said...

Hi Todd,

Sorry for my previous comment. I found out there's a difference between writing a code in the text editor and writing it in the visual lisp editor. Maybe there's a problem with my keyboard settings that my code looks different in each editor. Thanks again. It's working now. Till next time.

Ivan

HasanCAD said...

Hi

thanks for your help about loading lisp through menu.

But how can i load arx file through the menu asame as lisp

Hasan

Todd M. Shackelford said...

Hey HasanCAD,

ARX files are different. I load mine in the acaddoc.lsp file with a simple "load C:\something\something.arx" statement. Putting it in the acaddoc.lsp ensures it it loaded every time I start AutoCAD.