Jump to content

Tcount Alternative


Artek

Recommended Posts

Has anyone got a renumber lisp routine that I can use? I'm looking for something much simplier to use than autocad's tcount command.

 

Conditions:

1. Will deduct or add a given value (x for additional and -x for deduction) to all numbers or numbers with prefixes in the current drawing (excluding xrefs and blocks).

2. Prompts for a starting and ending number. (Limits the code within those given numbers)

3. Must include text with any prefixes like A1, COL1, etc. (no space in between)

5. Keeps all original text properties.

 

Thank you very much.

Link to comment
Share on other sites

Thank you very much for your suggestions. What I'm looking for is something much simpler and direct to the point coding that doesn't involve selections or dialog boxes. Just input the increment/decrement nos., starting and ending nos, and that's all. The simpler, the better as they say. :)

Link to comment
Share on other sites

There are several custom lisp routines that do it "simple". An Internet search should have no problem turning one or more of them up.

Link to comment
Share on other sites

There are several custom lisp routines that do it "simple". An Internet search should have no problem turning one or more of them up.

 

Thanks very much for your helpful suggestion.

Link to comment
Share on other sites

Two macros for incrementing numbers can be found here...http://www.cadeverything.com/help/showthread.php/2826-Automatic-incrementing-of-numbers-in-LT

 

Macros are about as simple as one can get. Assign macros to a button.

 

Leader lisp routines with incremental numbering can be found here...http://www.theswamp.org/index.php?topic=25254.0

 

Download a copy of INCNUM.lsp here...http://autocad.xarch.at/code/tanzillo/ghindex.html

 

Increment text and Increment text block lisp routines can be found here...http://www.cadlispandtips.com/2011/01/lisp-increment-text.html

Link to comment
Share on other sites

Again, thanks very much for your time. I'll just have to do it the long way then. :( Cheers!

 

Download a copy of INCNUM.lsp here...http://autocad.xarch.at/code/tanzillo/ghindex.html

 

Sorry for giving up too soon. I found the code below on one of your links and is very close to what I'm looking for. The only thing missing is the 'starting' and 'ending' number prompts for selections. Is there anyone out there who can help modify the code to include those lines please?

 

 

(defun extract (s / i prefix number suffix)
  (setq i 0 prefix "" number "" suffix "")
  (repeat (strlen s)
     (setq c (substr s (setq i (1+ i)) 1))
     (cond
        (  (and (wcmatch c "#")
                (eq suffix ""))
           (setq number (strcat number c)))   ; 3
        (  (and (eq c "-")
                (= suffix number "")
                (wcmatch
                   (substr s (1+ i) 1) "#"))
           (setq number (strcat number c)))   ; 3
        (  (eq number "")
           (setq prefix (strcat prefix c)))   ; 3
        (t (setq suffix (strcat suffix c))))) ; 5
  (if (not (zerop (strlen number)))           ; 3
      (list prefix number suffix)
  )
)
(defun C:INCNUM ( / ss off e d s s1 i fltr)
 (setq fltr '((0 . "TEXT") (1 . "*#*")))
 (cond
   ((not (setq ss (ssget fltr))))               ; 4
   ((not (setq off (getint "\nIncrement: "))))  ; 4
   (  (zerop off)
      (princ "\nValue must be non-zero."))
   (t (setvar "cmdecho" 0)
      (command ".undo" "g")
      (repeat (setq i (sslength ss))
         (setq e (ssname ss (setq i (1- i)))   ; 3
               d (entget e)
               s (cdr (assoc 1 d)))            ; 3
         (if (setq s (extract s))              ; 3
           (entmod
             (list
               (cons -1 e)
               (cons 1
                 (strcat
                   (car s)
                   (itoa
                      (+ off (atoi (cadr s)))) ; 4
                   (caddr s)))))))             ; 7
      (command ".undo" "e")))                  ; 3
 (princ)
)

Edited by Artek
Additional lines
Link to comment
Share on other sites

Artek, I'm not so sure your code is quite as simple as you seem to think. You mention a starting number and an ending number. What are these for? After all, you said you want to add/subtract from all existing text numbers in the drawing. What gives? In general, it is best to show what you want a program to do with examples, and explain the examples.

Link to comment
Share on other sites

Artek, I'm not so sure your code is quite as simple as you seem to think. You mention a starting number and an ending number. What are these for? After all, you said you want to add/subtract from all existing text numbers in the drawing. What gives? In general, it is best to show what you want a program to do with examples, and explain the examples.

 

Thanks for asking. Using the above code (IncNum) as reference, instead of selecting the texts with numbers to increment/decrement, i need it to prompt the user the limits of numbers to process (starting and ending prompts). The code will only process the numbers within those two given values. Let's say i got hundreds of texts on my drawing with texts starting with 'Unit-01' up to 'Unit-300'. If i need to add an extra 5 units after Unit-100, then i have to increment all the texts starting from Unit-101 up to Unit-300 by 5. So, the code will prompt for the following: an increment value which is 5, the starting number which is 101 and the ending number which is 300. The code will only increment the texts within the given range (101-300) by 5 and leaving 1-100 untouched. So the texts for Unit-01 up to Unit-100 remain the same and Unit-101...Unit-300 will change to Unit-106....Unit-305 respectively.

 

 

Existing texts:

Unit-01..... Unit-300

 

Prompts:

Increment value: 5 ;or enter - value for deduction

Starting number: 101 ;prompt 1

Ending number: 300 ;prompt 2

 

Please note: The range (prompts 1 and 2) to replace the selection prompt from the IncNum code.

 

Results:

Unit-01.....Unit-100 -> unchanged

Unit-101....Unit-300 -> Unit-106.....Unit-305

 

The texts in the drawing are sometimes not arranged in numerical order making it hard to locate and select manually hence the need for starting and ending numbers. The drawing also have sub-texts with the same numbers as the primary ones but with different prefixes (eg. Bath-01.... Bath-300) which should update as well. So, the code should work on all texts with numbers regardless of their prefixes, with or without separator (eg. '-' or space) except for attributes, those in blocks or xrefs. And I think, after some quick tests, 'IncNum' (as suggested above by ReMark) has met all the conditions and it's only the coding for the inclusion of starting & ending (range) numbers that are needed. If you require more examples then please just let me know.

 

I know what I'm looking for is not that simple. I only said that in comparison with the earlier suggested brilliant codes that offer a lot of useful features. I'm just looking for one that can do two functions and that is to increment or decrement numbers in texts within a given range.

 

Again, many thanks!

Link to comment
Share on other sites

Wow, excellent explanation, Artek! It wouldn't take a guru but a few minutes to add that, I think, unless they want to "fix" it also, or rewrite it, though it probably still wouldn't take them very long. It would take me a bit longer, but I can't get to it right away now in any case.

Link to comment
Share on other sites

OK, here's a revision of the main function. I did not change the extract function, so it is not repeated here. Try this and see how it does.

 

(defun C:INCNUM ( / ss off e d s s1 i fltr  StartNum EndNum CurNum)
    (setq fltr '((0 . "TEXT") (1 . "*#*")))
 (cond
   ( (not (setq ss (ssget fltr)))                ; 4
     (prompt "\nNo valid text found to change.") 
   ) 
   (T(initget 3)  (setq off (getint "\nIncrement: "))        ; 4
     (initget 7)   (setq StartNum (getint "\nStarting number: "))
     (initget 7)   (setq EndNum (getint "\nEnding number: "))
     (setvar "cmdecho" 0)   (command ".undo" "g")
     (repeat (setq i (sslength ss))
       (setq e (ssname ss (setq i (1- i)))    ; 3
               d (entget e)
               s (cdr (assoc 1 d))
       )                                      ; 3
       (if
          (and
             (setq s (extract s))              ; 3
             (setq CurNum  (atoi (cadr S))) 
             (<= StartNum CurNum)  
             (>= EndNum CurNum)  
           )
           (entmod (list
             (cons -1 e)
             (cons 1 (strcat
                (car s)
                (itoa (+ off CurNum))          ; 4
                (caddr s)
             )                )
           )                 )
        )
     )             ; 7        
     (command ".undo" "e")
   )
 )                  ; 3
 (princ)
)

Link to comment
Share on other sites

OK, here's a revision of the main function. I did not change the extract function, so it is not repeated here. Try this and see how it does.

 

You're a star! :thumbsup:

Just one tinie minie request, if you don't mind. Is it possible to get rid of the 'Select objects:' prompt at the beginning? It's kind of redundant, I think. Please make it automatically select all the texts in the drawing and just prompt for 3 values: Increment, Starting number and Ending number. Other than that... it's great! Cheers!:)

Link to comment
Share on other sites

You're a star! :thumbsup:

Just one tinie minie request, if you don't mind. Is it possible to get rid of the 'Select objects:' prompt at the beginning? It's kind of redundant, I think. Please make it automatically select all the texts in the drawing and just prompt for 3 values: Increment, Starting number and Ending number. Other than that... it's great! Cheers!:)

Glad it's working.

 

Try replacing this line

   ( (not (setq ss (ssget fltr)))                ; 4

with this line

   ( (not (setq ss (ssget "X" fltr)))                ; 4

Link to comment
Share on other sites

Glad it's working.

 

Try replacing this line

   ( (not (setq ss (ssget fltr)))                ; 4

with this line

   ( (not (setq ss (ssget "X" fltr)))                ; 4

 

Thanks for the quick response. It's perfect!

 

I actually attempted to give it a try :? and came up with the solution below. Please don't laugh. :oops: I couldn't believe that it's just a matter of adding the "X" to that line. :shock: LOL! Thanks a lot for all your help. Really appreciate it. Same thing goes to your fellow cad gurus, Lee Mac and ReMark, not to mention the original author (Tanzillo?) for this very useful code. Thank you guys!

 

(setq fltr [i][u](ssget "X"[/u] [/i]'((0 . "TEXT")(1 . "*#*"))))

(cond
   ( (not (setq ss [u]fltr[/u]))         ; 4
     (prompt "\nNo valid text found to change.") 
   )

Link to comment
Share on other sites

neophoible. Many thanks for a great little tool. Only problem I have is that it loses format for what I need.

 

eg. Say we have TAGS "P001", "P002", "P003", "P004" & "P005". Then run your tool...

 

>Increment: 2

>Starting number: 1

>Ending number: 5

 

Returns "P3", "P4", "P5", "P6" & "P7".

 

It loses the "00" pad! Do you know of a way to retain the pad/precision?

Link to comment
Share on other sites

Thanks for the quick response. It's perfect!

 

I actually attempted to give it a try :? and came up with the solution below. Please don't laugh. :oops: I couldn't believe that it's just a matter of adding the "X" to that line. :shock: LOL! Thanks a lot for all your help. Really appreciate it. Same thing goes to your fellow cad gurus, Lee Mac and ReMark, not to mention the original author (Tanzillo?) for this very useful code. Thank you guys!

You're welcome. Yes, it was a very simple fix, but I often find it's easier to just give the new line than try to explain what to add or replace within a line. It's usually less confusing that way. I try to not laugh at or make fun of attempts, at least not to your face. I just do it behind your back with the other gurus.:lol: That was a joke of course. And BTW, I'm not really one of the gurus, though way back in the day, I wasn't that bad. I'm just getting back into it now, and am way behind in so many areas.
Link to comment
Share on other sites

  • 4 months later...

Hi there neophoible!

I hope you are well. Sorry to bother you again. I'm just wondering if you could still help me with this one. I came across this problem recently when I have to renumber a combination of numbers separated by a hyphen. eg. A1 - A5. The above code can only change/update the first one (A1). Is it possible to make it work on single and combination of numbers? Thank you.

Link to comment
Share on other sites

Hi, Artek. It should be doable, but more involved. I suggest you open this up to anyone who wants to help. That's a good guideline in general, more like a rule. Things have heated up for me lately--a good thing, but it means I haven't so much time to even visit the forum.:(

Link to comment
Share on other sites

  • 4 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...