GOING FULL CIRCLE (atc.lsp)Trimming or breaking a circle into an arc is easy, but converting an arc back into a circle is a different matter. This AutoLISP program creates a new command called ATC (Arc To Circle) to convert arcs into circles. It takes the object data of each selected arc, modifies it, erases the arc and creates a circle with the new object data. The new circle has all the characteristics (location, radius, layer etc) of the original arc.The ListingThe first line after the program description defines the program name and localises the names of the variables used by the program. Localising variable names prevents clashes with variables of the same name used by other programs and is usually done after the program has been written and debugged.The next line initialises a variable called CTR2 that will be used as a counter to step through the selection set created later. Since the SSGET function can only display a generic 'Select objects:' prompt, we precede it with a 'Select arcs to convert to circles:' prompt to give users a better idea of what is expected of them. The SSGET function has only a filter list as an argument, which enables users to select objects by any method they wish but the filter list allows only arcs to be passed to selection set SS2. The first REPEAT function repeats the code nested in it as many times as there are objects in the selection set. By incrementing the variable CTR2 by 1 within the REPEAT function, we process each object in the selection set. This sets variable OBN2 to the name of the next object in selection set SS2 each time. Variable OBD2 is then set to the object data list, which is a list of association lists. We then change the object type in association list 0 from 'ARC' to 'CIRCLE' using the SUBST function. This modified object data list is not yet suitable for creating a circle since it still has association lists 50 and 51 - the start and end angles of the arc. These need to be removed before the object data list can be passed to the ENTMAKE function. As there is no direct method of deleting items from a list, this is done by copying all the association lists except 50 and 51 from OBID2 to OBD3. We start by setting variable CTR3 to 1 less than the number of association lists in the object data list, due to the way that the NTH function counts: nth 0 gets the 1st element, nth 1 gets the 2nd and so on. The REPEAT function is then called again to repeat the next portion of code once for each association list in the object data list. This is done in this manner because the number of association lists for an object can vary. If colour and linetype are BYLAYER then lists for them are not present and, if handles are disabled, a handles list is absent. This second REPEAT is nested within the first. Variable D2 is then set to an association list from the object, starting with the last and working down to the first with each iteration of the REPEAT loop performed by a decrement of variable CTR3. This association list is checked to see if it is neither 50 or 51 and, if true, it is copied to variable OBD3, adding it to any that are already there, building a new object data list. Since CONS always adds a new item to the beginning of a list, by starting at the last association list and working down to the first, the lists are kept in the same order. Variable CTR3 is decremented by 1 and the 2nd REPEAT loops around again, copying each association list from OBD2 to OBD3 via D2, leaving out any 50 and 51 association lists. When the REPEAT has finished, OBD3 will have a full and valid object data list for the creation of a circle. The existing arc is then erased with the ENTDEL function and the circle created with the ENTMAKE function. Variable OBD3 is then cleared to NIL otherwise subsequent objects will have their data appended to it. At this point, the first REPEAT will loop around (if more than 1 arc was selected) and OBN2 will be set to the name of the next object in the selection set. Once all the arcs have been replaced with circles, the PRINC function is called to exit the program without any 'leftover' values being printed on the screen. Leaving out the PRINC would result in the last value for variable CTR2 being printed to the command line area. |
©1996-2001 ZOTO Technologies