Mike Slinn / Selected Articles
|
||||
![]() 415-367-3789
mslinn@mslinn.com |
This article was originally published in 1985. ![]()
In this department interesting problems submitted by our readers are tackled by an independent consultant.
Our initial chef is Mike Slinn, the principal contributor to our ongoing LISP Tutorial. Other consultants are invited to let us know of their availability in case readers'enthusiasm exceeds his part-time capacity.
Dear CADalyst,
I am sure that a large number of AutoCAD users would welcome such an enriched linetype command. Yours
very truly, This request for a composite line type has been on the AutoCAD Wishlist for more than two years. Many users need to include letters or symbols as an integral identification of a line. The simplest example is perhaps the line with crossticks, either singly or in groups. Another frequent need is for code lettering: two or three text characters within a break in the line, repeated at regular intervals. The ability to include simple symbols or drawings is also useful. These need to be combined with lines that may be dashed or dotted like regular AutoCAD linetypes. We saw the general requirement to be this: after an initial solid line segment anchoring the beginning of a composite line, to repeat a sequence of elements in the direction of the second point until it cannot be repeated again, and then to complete it with a solid line from the end of the last complete repetition to the endpoint of the composite line segment. Each repeating sequence should be allowed to consist of (in any order) a reasonable number of dashes (line segments of specified length), gaps (spaces of specified length), text strings (placed in an appropriate length of gap) and AutoCAD Blocks or Shapes for symbols. We thought it necessary to provide an online definition capacity (similar to block definition and unlike the offline coding required for Shapes and text fonts). The user interface should parallel the ordinary Line command as nearly as possible. The Linetype definition does not provide options other than dots and parallel dashes. Because we have no access to the internal line drawing routines, our solution falls short of being a true AutoCAD line. It was not too difficult to imitate the point-to-point construction of an AutoCAD line, but standard editing eluded us. As an aid to editing, however, it seemed useful as an option to make each completed line segment into a block. It can then be removed by a single Erase Last. Although our routine is coded for v2.18 or above, the block-creating technique is only possible with v2.5. An interesting AutoLISP technique forms the heart of CLINE, involving a new programming idiom and the Eval function: (Setq J (List 'Command "text" "c" 'K L 'M N)) (Eval J) In this example, an AutoCAD command (Text) is set up as a list J and when J is later evaluated, the command is performed. The text string (a single character N) is centered at insertion point K, height L, and angle M. Because the text height L is not quoted, its current value at the time of the SetQ command will be stored in the list J. Because K and M are quoted, their values are not referenced until the (Eval J) statement is executed. CLINE may therefore reuse this command list variable J to place the same text string in many positions. The repeating sequence of lines, gaps, text and/or blocks that make up a composite line is created by making a list of variables like J. At each repeat of the sequence, the list elements are evaluated in turn and the included commands create the composite line entities. The initial version brought the following request for improvements from our client. Our responses are included in green. Dear CADalyst, I received the composite line routine for evaluation from Mike Slinn. I spent some time playing with it over the weekend. I couldn't expect a faultless performance and ran into a few surprises [these were attributed to their use of an early "patched" AutoCAD v2.18]. What I consider desirable modifications and additional features includes the following:
I would like to thank Mike Slinn and CADalyst, for giving me the opportunity to be part of tbis joint effort. I think that Mike has created a usable tool which, through normal evolution, should become very useful. Darko Dimitrijevic How to Use CLINECopy CLINE.LSP to your AutoCAD directory. Prior to starting AutoCAD v2.18 or v2.5, make sure the AutoLISP Stack and Heap are set correctly by typing: SET LISPSTACK=5000 SET LISPHEAP=40000 Then start AutoCAD as usual. Once inside the drawing editor, type: (load "CLINE") This loads the routine, which will prompt you to define a composite line and then use the definition immediately. You should first see: Composite line drawing routine (C) Copyright 1987 Michael Slinn Define composite line: Minimum end line segment length? <0.50000>: Your response
sets the minimum length of the line segments at beginning
and end of a segment of composite line. For now, press
the space or return key for the default. It then cues
you for the components of the repeating sequence: Next? Just type one letter followed by Enter to respond to the prompt,
eg. type T and press Enter to insert text.
The program will ask: Text string? Respond with a short
text string, such as SW and press Enter. It then
prompts for the text height, offering a default. From your
response it will define both the text height and the gap that
will include the text string. Again the program will ask:
Next? If you have AutoCAD v2.5 or later, CLINE will prompt you with an additional question: CLINE segments to form blocks? <Yes> Accept this default. If you do not, or if you are using V2.18, the routine will generate composite lines whose entities remain separate. [Users of v2.18 may ignore the next three paragraphs.] If v2.5 users hit Enter to assent to the default, each composite line segment (the portion of the line between each pair of points, no, matter how complex) will be drawn, transformed into a block and then re-inserted at the same location. This allows you later to Move, Erase or Rotate the line as a unit. Blocks need names; several composite lines of many segments will require many block names. The program requests a prefix character string (up to 27 characters long; the default is CLINEBLK), and an initial block sequence number from 1-9999 (default 1), to create a first block name (default CLINEBLK1). Horrible things will happen if the, block name already exists. CLINE has no way of checking to see if the block name has already been used. Pick a unique block name! As we draw each new line segment, the numeric suffix is increased by one. Should a block suffix reach 9999 ("Max Block Usage"), a new block name is requested. The last letter of the block name prefix is altered automatically and the block name suffix reset to 1 so that you may accept the default values offered without causing an error. Caution: once you leave the drawing editor, CLINE forgets the current block name suffix and prefix. The default name must be changed next, session when CLINE is first used, or again horrible things will happen with block name duplication. If you have prudently Listed and logged the last generated block name, you may continue the sequence with the same prefix and the next numeric suffix. You will now use the line definition for the first time. CLINE behaves much like the Line command. It requests the starting point of the line with "From point:" and subsequent segments by "To point:". Any point specification is valid, including digitizing a point, entering relative or absolute coordinates from the keyboard, or using 0Snap, but not including AutoLISP commands such as (GetPoint). With v2.5 or later you will see a rubberband line, and Ortho will work. The actual AutoCAD commands issued by CLINE are echoed onto the screen, which gives you an idea of what is going on but slows down the program. CLINE will crash when command echoing i s turned off, due to an undocumented bug in AutoCAD v2.52. Continue drawing lines until you have completed a first sequence. Upon pressing the spacebar, Enter or <Ctrl-C> CLINE asks: Close the polygon? <No> An N, space or Enter will cause the program to end. A Y causes one extra composite line segment to be generated which forms a closed polygon. After the first use on initial load, you may reuse the definition and generate more of the same composite lines at any time by typing CL. New definitions are possible by typing CN. More complex CLINEs may be defined by using more components. Blocks may be part of the composite line type definition. Make sure that blocks are of unit size (the X-dimension of the symbol should equal one drawing unit), and have their insertion point in the center of the block. They may be scaled when used (your menu macros defining CLINEs might need variables if you frequently work at different scales) and the blocks will be placed in a suitable scaled gap. Make cross-ticks as unit blocks with a horizontal line 1.2 units long through the center (0.6 units either side), and line or polyline diagonal ticks of whatever widths as required. A Shape could be used by inserting it in a block. Dots are made from very short dashes, dotted lines with short dashes and gaps. AutoCAD Linetypes can be used for the current layer, with discretion: symbols and text will also be drawn with whatever Linetype is chosen. Although the composite lines may appear to draw slowly, compare the rate at which they are drawn to the speed with which you can draw them any other way! Note that once they are constructed, subsequent regenerations will proceed much faster. CAD Cookbook
routines are available on diskette from CADalyst for
US$10.00. Write "CAD Cookbook", CADalyst,
282-810 West Broadway, Vancouver BC, Canada V5Z 4C9 and request
CLINE in IBM 360K or Victor 620K format. Profits go to the
routine's author.
|
![]() |
||
©
Copyright 1994-2008 Michael Slinn.
All rights reserved. |
||||