Let the plot have all the answers by George Nikopoulos Two questions frequently asked about the hard copy of a cad file are, "What is the filename?" and "When was the hard copy plotted



Download 13.05 Kb.
Date05.05.2018
Size13.05 Kb.
#48004
LET THE PLOT HAVE ALL THE ANSWERS by George Nikopoulos Two questions frequently asked about the hard copy of a CAD file are, "What is the filename?" and "When was the hard copy plotted?" The first question generally arises during the beginning of a project when drawing numbers have not been issued but drawings are being generated. The CAD operator will usually give some arbitrary name to the file. If this file has not been worked on for a period of time or if someone other than the original CAD operator is looking for the drawing, a considerable amount of time can be spent calling up drawing files one at a time trying to find the correct one. The second question occurs most often near the end of a project when both time and plotter availability can be in short supply. How often has the following scene happened? An engineer goes to a CAD operator and asks for the latest print of a certain drawing. Laying around are several prints of the drawing, but there isn't a way to determine which is the latest version. The CAD operator now has to plot the drawing file. If the drawing file is larger than 150K, the time re quired to plot can be substantial. The engineer, CAD operator, and the workstation are now all waiting for the drawing to plot, and yet the latest version could be one of the plots laying around. If this scene is repeated often, it can easily drain time and effort from a project. A solution is for the date and time the file was last modified and the filename to be printed out on the plot. Then a comparison can be made with the date/time modifier of the drawing file to determine if a new plot is needed. An easy way of doing this is to redefine a command that the CAD operator would ordinarily use. In this case the End command was selected. Accomplishing this is done with the AutoLISP startup function. Place the following routine in the ACAD.LSP file, and every time AutoCAD is invoked, this command will execute automati cally. (defun S::STARTUP () (command "Undefine" "END") ) Now the End command can be redefined using AutoCAD's getvar functions of CDATE, TIME, and DWGNAME to provide the necessary information and to place it on the drawing automatically. Whenever a drawing is modi fied automatically, certain steps must be taken to insure integrity. In this case, since a new text style and layer will be created, the existing values need to be stored. Lines 2 and 3 of Listing 1 use the getvar functions of CLAYER and TEXTSTYLE to store these values so they may be retrieved later. Line 4 uses the sytem variable DWGNAME to retrieve the filename. Line 5 places a space at the end of the filename so the information will not run together. Lines 6_13 shows how to extract the date. Using the system variable CDATE does not return a readily usable value; it must first be converted from real to string. Then the substrings must be concatenated into the standard month/day/year format. A similar proce dure is done to make the time readable. These values will reflect the computer's internal clock. If there is more than one workstation in the office, the clocks should be synchronized to prevent confusion. Lines 14_16 concatenate the filename, date, and time into a single entity but with the various values delimited by a space. The information is now ready to be placed on the drawing. Since the desired plotted height of the date/time value is one-tenth of an inch, regardless of sheet size or scale, there are several other getvar functions that must be used before the information can be placed on the drawing. Lines 18 and 19 determine the limits of the drawing. Line 20 establishes the relative maximum value for x. This is done to accommodate drawings that don't have origins at 0,0. Line 21 takes the maximum x value and divides it into the maximum y value. To illustrate, suppose a drawing with a plotted sheet size of 36 x 24 inches has a scale of 1_8 inch = 1 inch. That would put the limits at 288 x 192 feet. Dividing 192 by 288 results in a quotient of 0.6667. Now take a drawing with the same sheet size that has a scale of 1:1. The limits are now 36 x 24 inches. Dividing 24 by 36 results again in a quotient of 0.6667. The values in lines 23, 26, 29, and 32 are the ratios for those particular sheet sizes. Lines 24, 27, 30, and 33 take the width of the sheet (in this case, 36 inches), multiply by 10 (so the resulting answer will be in tenths) and divide into the maximum x value (288 feet). AutoCAD displays the limits in feet but must store the value in inches since the answer is given in inches. The value returned is 9.6 inches, which is the height the text needs to be so as to plot out at one-tenth of an inch. The decision was made to place the date/time value between the edge of paper and drawing border so as not to be confused with information on the body of the drawing. Lines 35_37 establish the insertion point (zzz) for the text. In this case, that point is just inside the origin of the drawing. Line 38 creates a selection set of any text entities located in the layer timedate. If no entities are found, a layer timedate is made (Line 41), and a text style (donotuse) is created (Line 42). Now everything is ready to place the date/time value on the drawing in the WORKING WITH LISTS, PART III Beginning AutoLISP by Leif Eriksen This month we continue our investigation of the AutoLISP list data type. Until now, the lists we have seen could be classified as gener al-purpose lists. Now we'll turn our attention to a few special-pur pose lists. A list is defined as a collection of data arranged in a certain order. Most commonly, data are integer, real, string, symbol, and other lists. The ordering of the list may or may not be significant. For example, the ordering of a list representing a coordinate is signifi cant. The first element is the x value, the second is the y value, and the third is the z value. Another list may represent all the block names in your drawing, such as ("PARTA" "PARTB" "PARTC"). In this case, the ordering is not significant. A list may have any number of data elements inside. The only limitation is the size of memory avail able to AutoLISP. Dotted-Pair Lists A special type of list, called a dotted-pair list, has only two data elements. The advantage of a dotted pair is that it uses less memory. Figure 1 shows a standard list and dotted-pair list of two elements. Note that the dotted pair uses one less node. A dotted-pair list is represented by two elements separated by a dot. For example, a list with two elements, the integer 0 and the string "TEXT", is represented by: (0 . "TEXT") Note that there must be at least one space on each side of the dot. Due to this rule, many AutoLISP programmers have encountered the message "invalid dotted pair." This happens when you include a real number in a list without using a zero immediately preceding the deci mal point. For example, the list (0 .123) is not a dotted pair since there is no space after the dot. Dotted-pair lists are usually created in one of two ways. If you already know the value of the list, you can use the quote method. For instance, to create a variable dp with (0 . "TEXT"), you can write: Command:(setq dp '(0 . "TEXT")) (0 . "TEXT") Suppose, however, you do not know the second part of your dotted pair. To handle this, you should use the cons function. This function creates a dotted pair. Typically, cons is used to add an element to the front of a list. The first argument is the element to be added to the list (which is the second argument). For example: Command:(cons 0 '("TEXT")) (0 "TEXT") If the second argument is not a list, a dotted pair is created: Command:(cons 0 "TEXT") (0 . "TEXT") To write a program that inputs a variable called entype, create a dotted pair of 0 and entype, which is written: (setq entype (getstring "\nEnter Drawing Entity Type: ")) (setq dp (cons 0 entype)) If you entered "ARC" to the getstring function, then dp is set to (0 . "ARC"). Cdr works differently with dotted-pair lists. Cdr returns the last element of a dotted-pair list rather than the last element inside a list. For example: Command:(cdr '(0 . "ARC")) "ARC" This effect is useful since you might otherwise use the cadr function to take the second element out of a list. Cdr saves the computer one operation. Figure 2 shows the effect of cdr on a list and a dotted- pair list using a node cell representation. In these days of computers with large amounts of RAM and virtual- memory AutoCAD (Release 10/386 and 11/386), saving one node (12 bytes) may not be much incentive to use dotted-pair lists. However, a second special list type is very important in AutoLISP programming, and it uses dotted-pair lists extensively. This list type is called an asso ciation list. Association List An association list contains multiple sublists. Each sublist is a single characteristic or fact that helps describe the object repre sented by the list. Other programming languages use arrays or struc tures to hold multiple pieces of data. AutoLISP uses association lists to describe entities (lines, arcs, text, etc.) in a drawing. All information attached to an entity is available in its association list. Entity access functions are used to create and modify entity association lists. The form of each sublist of the association list is (key value). The general form of an association list is: ( (Key1 Value1) (Key2 Value2) (Key2 Value3) . . (KeyN ValueN) ) The association list for a line might resemble the following: ( (-1 . ) ( 0 . "LINE") ( 8 . "0") (10 0.0 0.0 0.0) (11 1.0 1.0 0.0) (210 0.0 0.0 1.0) ) The first element of each sublist is the key or identifier for that sublist. The number ties into the DXF codes for each type. Key -1 is the unique name for the entity in the current drawing session. Key 0 is the entity type. Key 8 is the layer name holding the entity. Keys 10 and 11 are the starting and ending points of the line. Key 210 is the extrusion direction. DXF codes are described in Appendix C of the AutoCAD Reference Manual. Notice in the line association list that the first three sublists are dotted-pair lists. Many, but not all, of the sublists are dotted-pair lists. ASSOC function Typically the first thing you want to do with an association list is use the assoc function to search for and extract one of the sublists. Given a key and an association list, the assoc function returns the first matching sublist. For example, if our line association list above is assigned for the variable al, then using a key of 8 returns the layer name that contains the line. Command:(assoc 8 al) (8 . "0") To extract the layer name as a string, the cdr function is used. Command:(cdr (assoc 8 al)) "0" The layer name is not within a list since assoc is returning a dotted-pair list. If the key cannot be found in the association list, assoc returns nil, as in the following: Command:(assoc 99 al) nil Notice in Figure 3, a diagram of the assoc function, that both argu ments are required. Though the key need not be an integer_it can be any data type_an association list created by entity access function always uses an integer (from DXF) as the key. SUBST In addition to picking out a sublist from an association list, it is often necessary to change one or more sublists. This may be done with the subst (substitute) function. Subst will work on all lists, not just association lists. It has three arguments, and all are required (Figure 4). The first argument is the new value, the second is the old value to be replaced, and the third is the list. For example, if we have a list with numbers 1 through 4, we can change 3 to 6. Command:(setq test '(1 2 3 4)) (1 2 3 4) Command:(subst 6 3 test) (1 2 6 4) In our association list for a line, suppose we want to change the layer of the line from "0" to the layer "LINE". The following will make the change.

Download 13.05 Kb.

Share with your friends:




The database is protected by copyright ©ininet.org 2024
send message

    Main page