Tips from Our Readers -- May 2007 (Hot Tip Harry AutoCAD Tutorial)
30 Apr, 2007 By: Bill KramerProgrammer productivity tools -- by programmers, for programmers.
Join the Hot Tip Harry Challenge
Calling all tip writers! The Hot Tip Harry Challenge is under way for 2007 and is sponsored by Autodesk. Share your hot tips and tricks for a
| |||
Harry had a big smile on his face when he handed off this batch of tips. "As a fellow programmer, you're going to like these," he quipped and then headed out the door in pursuit of some more tips -- mumbling something about drawing standards again. This month's set of tips is focused on programmers with tools and examples specifically meant for programmers. As an old-time programmer who actually started by punching cards, all I can say is, "Yeah, I like these!"
You can use Lisp Log (Tip #2204) from Paul Kirill to track the use of your LISP routines by others (or yourself). Be sure to add the source code for this tip into your primary LISP module that loads automatically with every drawing, because it sets up a reactor callback that is triggered when an AutoLISP program is started inside AutoCAD. All the reactor function does is store the name of the function started in the evaluator. Inside the functions that you want to track, you add the function call (LISPLOG). This function opens a log file and writes the name of the current function and the date. I advise that you look closely at the LISPLOG function definition in this tip's source code because you'll most likely want to revise the log file location. Also note that this function-tracking trick is only for the main function initiated from the command level of AutoCAD. A great example of the reactor system, thanks Paul!
LISP Progress Bars (Tip #2205) by Terry Miller is a cool trick for entertaining users when your program is involved in a long iterative process. When applications need a long time to solve a problem or search for an answer, it's not uncommon for users to be left in the dark, wondering if the process is actually running or if the computer needs to be reset. Progress bars are an accepted method by most users because they see them frequently in other applications. Implementing progress bars in Visual LISP is greatly simplified by using Terry's utility set. In the source code, you'll find several examples of the progress bar system being used (functions named DEMO) in a variety of instances. There are three functions that you use in your programming along with a dialog box file (DCL) that needs to be located somewhere in the AutoCAD search path. The three functions can be found in the LISP source file after the DEMO examples, and they are for initiating the progress bar dialog, filling in the bar during the run and then closing the dialog. This sure beats putting dots on the Command line!
Start Associated Application (Tip #2206) from Leon Brumin is a utility function that accepts a filename and then initiates a Windows applications associated with the file type. This is just like double-clicking on a file in the Windows Explorer program. Files with extensions recognized by Windows cause the associated application to start. This function makes use of the VLAX functions inside Visual LISP to create a shell object that is then started with the given filename. The shell object is the avenue to the Windows operating system where the open method accepts a filename and starts up the application. Once started, the application object is released from Visual LISP, and the application can continue to run on its own. For programmers looking for an example of how to start up a spreadsheet or text editor from inside LISP, Leon comes through for you with this easy way.
Create Command Functions (Tip #2207) by Ed Jobe is a way to implement a bridge between VBA macros and AutoCAD's command system using Visual LISP. The LISP code in this tip is meant to be loaded when starting a drawing editor session. When it loads, the LISP code establishes a set of command function names as directed by a list of your creation (see CommandList in the source code). These function names correspond to macro names in your VBA project so that when the LISP code is finished loading, you have command names for each of your macros. Command names let you run the VBA macros by typing in a name at the Command line (or in a menu entry) thereby simplifying the deployment of macros to multiple users. This is a great solution to a problem common many VBA programmers find in AutoCAD.
Command Library (Tip #2208) by Andrew Siddeley is this month's top tip for programmers. The purpose of this function set is to display the names of command functions (with comments) in various LSP files. If you have a LISP library like some of those described by the power users in the Hot Tip Harry Forums, then you need to take a look at this utility. After loading the LISP code, type CCC (short for Custom Command Catalog) to start up the tool. A dialog box shows the command functions defined. Initially this dialog box is empty. To fill it up, select the LSP button then pick a file for it to analyze. Any function definitions with C: as part of the function name are collected and nearby comments are added for display in the dialog box. By the way, this function set creates its own dialog box on the fly and demonstrates some excellent modular programming. Plus, there are several other hidden features that I'll leave to the hearty LISP explorer to find. Nice job, Andrew -- and congratulations on earning the status of Top Tip for this month!
Toggle Black and White Background Color (Tip #2209) from Watson Kilbourne is not exactly a programmer utility but fits into the AutoCAD power user category. The goal of this routine is to change your screen background between black and white while leaving the cursor crosshair colors untouched. Load the LISP code and type TWB to flip between the background options. Power AutoCAD users who have a particular preference for one background or another while also using alternative colors for the crosshair will enjoy having this utility in their arsenal when visiting other people's workstations. This function is a great example of how to programmatically manipulate items inside the AutoCAD system.
Block Quantify (Tip #2210) by Brock Narum counts the number of blocks, xrefs and dynamic blocks inserted into an active drawing. Load the LISP code for this tip then type BLKQNT at the AutoCAD Command line to activate. The program then reads through the block definitions table and construct a report that can be viewed in the AutoCAD text window. Narum reports that he uses this function to help verify designs by making sure the component counts correspond. Block management, especially when external references are involved is greatly simplified using custom report generators like this one. Thanks, Brock!
Bring It On!
Harry is always looking for more tips to share. Harry pays well for those that are used, and your name is entered into a drawing for some great prizes. Check out the details at Hot Tip Harry Challenge 2007 and send in your tip.
In the meantime, if you have any questions or want to modify one of the many thousands of tips, please visit one of Harry's forums and leave a message -- experts from around the world are watching, including Harry. Go to Hot Tip Harry: Requests when you're looking for help with a certain routine or to find an old tool that you've misplaced. Go to Hot Tip Harry: Help! for help related to CAD programming and customization. Until next month, keep on programmin'.
For Mold Designers! Cadalyst has an area of our site focused on technologies and resources specific to the mold design professional. Sponsored by Siemens NX. Visit the Equipped Mold Designer here!
For Architects! Cadalyst has an area of our site focused on technologies and resources specific to the building design professional. Sponsored by HP. Visit the Equipped Architect here!