Keep Your Code Collection in Perfect Harmony (Harry's Code Class Newsletter)22 Jul, 2008
Harry offers a few tips for using free Web downloads, and gives a sneak peak of Cadalyst's new CAD Tips site.
The world of CAD customization offers many opportunities for you to tweak and improve your software. You can buy third-party tools, write your own, or download free programs from Web sites such as Cadalyst's. It's all good, right? Not really. Some real problems can crop up if you're not careful or don't know what you're doing. Generally, the third-party developers have the issues under control. The questions arise around the custom code you write and what you pull from the Web. Let's take a look at the most popular problems you might encounter when downloading code from the Web or writing your own macros -- and how you can prevent them.
Sometimes the stuff you download can contain nasty components put in there intentionally to disrupt your work. You won't find those among Cadalyst's offerings -- Harry carefully checks that stuff before allowing it to be published. But it does not hurt to be extra careful any time you're downloading free tools.
When downloading free stuff for AutoCAD, my basic rule of thumb is that it must include the source code. If the freebie contains only binary or object code, for example, I won't use it because I cannot be certain of what it's doing. I also insist on this rule because if I use the code, I want to be able to maintain and update it in the future. Without source code, you may find yourself stuck when a new version of AutoCAD is released, rendering the cool tool obsolete or invalid. In many cases, a free download might be good for only a few versions, and if you want the update, you have to pay a service fee. Although that may seem unfair at the moment it hits, it is a valid marketing approach for third-party vendors breaking into the scene, and not really a nasty thing as much as it is a surprise. Just keep in mind that if you don't have the source code, you have no reassurance the tool will work into the future.
The most common problem encountered when downloading free customization tools from the Web will be a conflict in symbol use, especially when dealing with Visual LISP (AutoLISP) downloads. This occurs when the newly downloaded program uses a symbol name that matches one you have used in your own code or in some previous download. Symbol names may point to function definitions and variables; thus, a conflict will most likely disable one or both of the programs. In LISP, symbols can be reassigned at any time. This ability is a powerful tool when used properly. But it can also be a real nightmare when you are tracking through a complex set of programs looking for the culprit.
The solution is to get tight control over your symbol names by establishing a couple standard practices. Creating a naming convention to be used throughout your office helps a lot. If you start all your symbol names with a unique, standard character sequence -- for example, your company's name or initials -- you'll greatly reduce the likelihood that a downloaded freebie would duplicate one of your names.
The next standard practice to consider is to keep all your symbols local with respect to the command functions. Visual LISP looks for local definitions before looking for global definitions. So if you define your symbols as local to a function, you can avoid conflict with any global definitions of the same name.
Third, use AutoCAD's VLIDE (Visual LISP for AutoCAD Developer Environment) to create projects (VLX files). A project provides a name space where your symbols will be yours and yours alone. This sort of programming is not for the novice and is only mentioned here to support the basic premise of keeping your symbols straight.
AutoCAD programmers often create new versions of existing AutoCAD commands, with a twist -- and call them something new. This is a great way to introduce new programming to generic AutoCAD users, but it can present a problem for other programs that use the command that was redefined. The best way around this is to use the period character (.) before any command name you use. This forces the (COMMAND) expression to follow the original command in AutoCAD and not end up in the redefined command function. Along with the period is the underscore character (_). Using this character when invoking a command name inside your code forces AutoCAD to use the English command version and enables macros to run on any international version of AutoCAD. I recommend that you just make it a general practice to include the period and underscore whenever you use the (COMMAND) expression in your coding.
Introducing: Cadalyst CAD Tips
So why is Harry thinking about the best approach for integrating Web downloads into your workflow? Simple: He wants to prepare you for another super treat he has in store. Before Cadalyst launches a full promotion of its new CAD Tips site, everyone reading this newsletter is being offered the opportunity to take a sneak peek at the beta version.
Cadalyst's CAD Tips site -- at www.cadalyst.com/CADTips -- is a brand new online tool that replaces Cadalyst's long-standing Get the Code! library. CAD Tips is the Web's largest library of AutoLISP and VBA custom programming code and hatch patterns for AutoCAD -- nearly 1,800 tips and growing. The new site offers a bunch of new and improved tools for you code fans. Remember how difficult it was to locate the tip you needed in Get the Code!, and then you had to download an entire month's worth of code files to get the one tip you sought? The new CAD Tips site employs a greatly souped-up search engine to help you quickly locate the tip you need -- or you can use Google or another standard search engine. Once you locate the tip you need, you can download code just for that individual tip. Search by tip number, keyword, or date (using Advanced Search) or browse by category. The new search even checks for matching content inside code files. Users who register also can tag tips to identify and organize your own favorites, rate tips, share feedback about tips, and upload modified versions of code files, so each tip can continue to evolve in usefulness. Check out this new beta site and give it some heavy testing. Send all feedback to firstname.lastname@example.org.
Until next time, keep on programmin'.Related Resources
Check out these resources for more information and examples:
- AutoLISP Learning Series - Lesson Seven: Using Global and Local Variables, by Dave Pitzer
- Visual LISP: Applications, by Bill Kramer
- What to do with Visual LISP files from the Internet, by Bill Kramer
In her easy-to-follow, friendly style, long-time Cadalyst contributing editor and Autodesk Technical Evangelist Lynn Allen guides you through a new feature or time-saving trick in every episode of her popular AutoCAD video tips. Subscribe to the free Cadalyst Video Picks newsletter and we'll notify you every time a new video tip is published. All exclusively from Cadalyst!