PDA

View Full Version : Intelligent Renumber LISP



IdeaLogic584307
2016-07-30, 09:09 PM
I have created a map of my local area (in AutoCAD 10), that includes a table which lists N key businesses in alphabetical order. Each business also has a numerically ordered key number (1 through N) for purposes of locating the business on the map, via a callout. The callouts each consist of three entities, a dot (donut), a right-angle polyline, and the corresponding key number.
If I wish to add a new business, in order to maintain both the alphabetical order and the numerical order, I have to manually search for all callouts having key numbers that are equal to or greater than the number assigned to the newly-added business, and increment each of them by one. Since the callout numbers could be anywhere on the map, making sure I find each one is a manual process prone to error.

For example, the table lists Home Depot, with a key number of 21 and K-Mart with a key number of 22. Let's say I want to add Ikea at position 22, and increment the key numbers of all "higher" businesses by one (i.e. K-mart becomes 23, and so on through N+1).

I could use the Find and Replace feature, but I would need to do this multiple times (in my case 23 repetitions) which would become very tedious. Is there a LISP routine that would automatically search outside the table and replace the relevant key numbers, as needed to increment each by one integer? I assume it would need a couple inputs, e.g. starting key number, maximum key number, and maybe others. It wouldn't necessarily need to increment the key numbers in the table itself (although it would be okay if it did), that could be done manually with no great effort. Any assistance would be appreciated.

Opie
2016-08-01, 02:54 PM
Assuming your tag is a block with an attribute, you could get a selection set filtered by the specified block name, and then step through each block in the set thereafter to increment the attribute value. I'm certain there are several threads in this forum to change an attribute value.

IdeaLogic584307
2016-08-01, 04:11 PM
Unfortunately the tags are not blocks (each consists of four entities, as described). Maybe someone else will have an alternate suggestion. But if I need to, I will go back and convert the tags to blocks with attributes, per your solution. One question, though, when you say "step through each block in the set," would that process automatically advance sequentially (i.e. would each subsequent "step" find the tag with a number one higher than the previous tag or would it find them in a random order)?

Opie
2016-08-01, 05:12 PM
How do you currently know each block of text out of the four entities is for the number? How can you tell the program what to look for? That is why I suggested an attributed block.

Once you have your selection set with the correct entities, you will need to process each item to check if the number should be changed. Selection sets can be processed using the repeat function based on the number of items (query count of items with the sslength function) in the selection set.

BIG-AL
2016-08-21, 07:37 AM
Your blocks are more then likely retrieved in database order by creation, no problem incrementing automatically just add a number to an existing attribute.

Add att 22 kmart renumber all blocks attribute > 22

This will make a selection set, (setq ss (SSGET "X" (list (cons 0 "Insert")(cons 2 yourblockname)))) of all your blocks of 1 name then step through them making changes.

Just look for any sample code about changing block attributes,

irneb
2016-09-13, 03:22 PM
Are you sure you're using ACad 10? As in the R10 version from the late 1980s? Or do you mean the 2010 version (which is actually release number R25)?

In both cases, I would definitely suggest you change your tags to blocks with attributes for the number displayed. That's going to be so much simpler to work with this sort of auto renumbering idea. Else the lisp would need to search through all "donuts" (actually polylines with widths) and find the closest text to that with only a number in it - lots of possibilities for getting it wrong.

If you meant the 2010 version, this is the exact reason I made my AutoIncr routine originally. You can download the source from here: https://sourceforge.net/p/caddons/code/HEAD/tree/General/AutoIncr.LSP

It should make it possible for you to pick each text in turn to group them into a renumbering set (or using a by-fence selection drawing a line over the texts in the direction they should be numbered). Then later you can insert a new text anywhere in an existing set so it renumbers all of them. Though I'd still advise you rather make use of attributed blocks instead - it would make it possible to generate a table automatically too.