Tips from Our Readers -- February 2007 (Hot Tip Harry AutoCAD Tutorial)1 Feb, 2007 By: Bill Kramer
Rename layers automatically, modify divides, use an associative linear length dimensioning tool for arcs and more.
We will start with a tip from Jim Himes, Rename Layers from a List (Tip #2178). Once you load the LISP code into AutoCAD, type RENLAY to rename a set of layers with new names based on information in a pair of control lists. Before you run this command, you need to modify the contents of the NLL and OLL lists in the source code. OLL contains a list of old layer names, while NLL contains a matching list of new layer names to be used. This program reads through the layers table and when it finds a match with an entry in OLL, it renames the layer to the corresponding entry in NLL. This is a real time saver when changing the layer names on a group of drawings.
Pick Nearby Points (Tip #2179) by Pedro Ferreira is a cool demonstration of how you can use AutoLISP to expand how you select objects in AutoCAD. Load the LISP code and type MW (for Magic Wand) at the Command line. The function first asks you for a search tolerance, a value in drawing units that represents how far from the selected point you want to search. The next prompt is for the pick point. Locate a point near the objects and they are gripped, ready for use in your next command. This is a cool trick and is useful for a variety of applications.
Mosad Elewa sent us Modified Divide (Tip #2180). Sometimes the robust AutoCAD command set is not enough, and this tip shows how you can use AutoLISP to get AutoCAD to do exactly what you want. Once loaded, type DIV to activate the command, then select a line, arc or circle. DIV asks how many segments you want and then automatically places a line at each division point. The size of the line added is based on the size of the object selected. For arcs and circles, the line length is one quarter of the radius. For lines, the hash mark is the same size as the segment distance. According to the comment in the program, Mosad wrote this back in 1996 and it still runs today, 11 years later. Good LISP code never grows old!
Pedro Ferreira also provided a nice introduction to the power of Visual LISP object manipulation with Distance Along a Polyline (Tip #2181). Hidden in the VL functions of Visual LISP are the VLAX functions, a powerful set of tools that let you directly access objects inside AutoCAD and other places. One gem in the treasure chest is the VLAX-CURVE-GETDISTATPOINT function (what a mouthful). Pedro's function cleverly demonstrates how this function and others work. To use it, just load the LISP code and type DS at the Command line. Select a point somewhere along a polyline and the function reports the distance into the polyline, as well as the layer of the polyline, back to the AutoCAD text screen.
If you're looking for a more robust example of advanced object manipulation in AutoCAD, then check out Michael Kolomiyets's Linear Arc Dimension (Tip #2182), LAD for short. Draw an arc and then load the LISP code and type LAD at the Command prompt. Select the arc just drawn, and it displays dimensions containing the arc length. This by itself is useful; however, Michael's functions go further by establishing a reactor that goes off when you change the arc. If you modify the points or move the arc, the dimension follows right along with an updated value as needed. This function set demonstrates the power of reactors in a productive manner and establishes a template from which you can build other power dimensioning utilities. This is such nice work, it deserves the honor of being named this month's Top Tip!
Back to the concept that good LISP lasts a long time -- Lot Numbers (Tip #2183) by Dean Davis has a comment dating this function back to 1991. After loading the LISP code, type LOTNO at the Command line. This code is specifically written for labeling lots in a site survey, so the first prompt asks for the string prefix. Next, it requests the starting number. From that point on, all you have to do is locate points and the function draws in the text that contains the prefix and the number. Each time you create a new text object, the number is incremented by one. Good LISP just keeps on running.
Jay Thomas supplied Thick Leaders with Text (Tip #2184) that he whipped up for a colleague on the fly and later decided to share with all of us. This function draws a leader with an arrow using a thick polyline (one with a width not equal to zero). It draws the arrowhead and line as a single polyline object and places text at the end of the leader. Load the LISP code and then type PLL to get started. The first time into the program you are asked to verify the default settings (obtained from the AutoCAD system variables). This function does not create an associated dimension object, meaning that edits to the output are performed using regular AutoCAD commands should you want to relocate the leader or change the text. This is a nice set of functions, and very useful when marking up a drawing. Thick polyline leaders are hard to miss, especially if you do them in a different color.
Line Up Text (Tip #2185) from Gordon Reichhardt is a handy tool for vertically aligning text notes in a drawing. After loading the LISP code, type ATXT at the AutoCAD Command prompt to start this macro. It asks you to select text objects on the screen to be aligned. Pick text objects that will share the same X starting point (this function behaves best when working with text that was generated with left alignment). The program automatically employs a filter in the selection process so that you can window a bunch of objects and only the text (and MTEXT) is selected. Once you select the text objects, the program displays a vertical line that moves back and forth as you move the mouse (nice use of GRREAD, Gordon). Pick the point and the text is all aligned.
Michel Chayer sent in Formatted Date Srings (Tip #2186), a programmer's tool that accepts a date string in the form of DD/MM/YY (or nil for the current date) and returns a list of strings. The list of strings is the date value formatted in a variety of ways. All you have to do is pick the one you want for any given application. The names and formats in the function supplied by Michel are in French. It's easy enough to convert them to a different language and more formats once the code is in a text editor. Another programmer's tool supplied by Michel is Null String Test (Tip #2187). This very simple function exploits the AI tools supplied by Autodesk (see AI_UTILS in your AutoCAD support folder) to test for an empty string. In this case, an empty string is anything made up of spaces, as well as a string with nothing in it. If the string is empty, an error string is returned (in French); otherwise, the original string is the result. Programmers may want to modify this function for a null result and then employ it inside a conditional. Merci Michel, très bonne!
Send in Your Tips
Your tips make this Cadalyst column work. And, in turn, this feature makes your work easier and more productive. Hot Tip Harry enjoys reviewing everyone's tips, big and small, and then sharing them with the entire AutoCAD user community. Don't be shy, submit a tip today. We've got some great prizes for the winners and you will be entered into a lottery for some wonderful opportunities. Keep on programmin', and send in those tips!
In her easy-to-follow, friendly style, long-time Cadalyst contributing editor 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!