Command for detail numbering

Command for detail numbering

Anonymous
Not applicable
762 Views
6 Replies
Message 1 of 7

Command for detail numbering

Anonymous
Not applicable

Hi I'm sure this has been posted a million times before (I've checked but no luck with quite what I'm looking for), so sorry in advance! I'm trying to create a command that will renumber details on a sheet for me, by first picked the text I'd like to change then telling it what number I'd like to start from. The one caveat being that I'd like to make sure anything less than 9 shows up as "01" etc. Currently getting a "lentityp nil" error when I try what I've got so far.

Thank you!

 

(defun c:dnum (/ index numb a n b1 str b iTx fmtval str newStr d )
(setq a ( ssget ) )
(setq n ( sslength a ) )
(setq index ( getint "\nBeginning Number: "))
(setq numb ( - index 1 ))
(repeat n
(setq b1 ( ssname a numb ) );Step through list
(setq numb ( + numb 1 ) );Increment number
(setq b ( entget b1 ) );Copy the list
(setq iTx ( assoc 1 b ) );Old Text
(setq fmtval ( rtos numb 2 0 ) );Format number
(if ( <= fmtval 9 )
(setq str (strcat "0" (itoa fmtval )))
(setq str (itoa fmtval))
)
(setq newStr ( strcat fmtval ) );combine formatted value with string
(setq d ( cons ( car iTx ) newStr ) );construct new list
(setq b1 ( subst d iTx b ) );replace old list with new list
(entmod b1 ) ;update the list
)
)
0 Likes
Accepted solutions (2)
763 Views
6 Replies
Replies (6)
Message 2 of 7

Sea-Haven
Mentor
Mentor

 If its a block attribute then can be done pretty easy and lots of examples out there, if its just text then it will be hard, is it a title block in layouts, is it the layout names, lots of questions.

 

Post a dwg

0 Likes
Message 3 of 7

Anonymous
Not applicable

It would just be for standard text in model space. I have it working just fine for doing it mindlessly starting at "1", but I'd like to be able to start it with whatever number I want and have 1-9 be "01" etc. The text will already be there, I just want to change what it says.

0 Likes
Message 4 of 7

steve_carson
Enthusiast
Enthusiast
Accepted solution

My guess is that the error you are getting is coming from your ssname function. You are passing it "a" (which is ok) and "numb". But numb is related to the number you type in, not the length of the selection set. You will need to keep 2 different counts as you loop through your objects, one to count through your selection set, and one to increment the value you are putting in the text.

 

There are lots of ways to do it, but I like to use ssname like this:

 

(setq SS (ssget))

(repeat (setq i (sslength SS))

    (setq OBJ (ssname SS (setq i (1- i))))

    (Do stuff with OBJ)

); repeat

 

I'm not sure this will work for you exactly, because it runs from the end of the selection set to the front, but I also don't know what the order of objects are in a selection set. You can play with it and find out. You may need to start i at -1 and add 1 each time, like this:

 

(setq SS (ssget))

(setq i -1)

(repeat (sslength SS)

    (setq OBJ (ssname SS (setq i (1+ i))))

    (Do stuff with OBJ)

); repeat

 

Message 5 of 7

Sea-Haven
Mentor
Mentor

This is a less than 10 example

 

; if less than 10
(if (< dwgnum 10.0) 
      (setq newstr2 (strcat "-D0"  (rtos dwgnum 2 0)))
      (setq newstr2 (strcat "-D"  (rtos dwgnum 2 0)))
)
0 Likes
Message 6 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution
(defun c:dnum (/ index numb a n b1 str b fmtval str d b2) ;;; removed iTx, newStr
  (setq a (ssget))
  (setq n (sslength a))
  (setq index (getint "\nBeginning Number: "))
;;; (setq numb (- index 1))
;;; if [for example] beginning number is 10 but there are 8 Text objects,
;;; (ssname) will fail.
  (setq numb 0) ;;; must be 0 to start at beginning of selection
  (repeat n
    (setq b1 (ssname a numb)); Step through list
      ;;; this b1 is an entity name - re-use later for entity data list is confusing
    (setq b (entget b1)); Copy the list
;;;  (setq iTx (assoc 1 b));Old Text ;;; not needed
    (setq fmtval (+ numb index)); Format number relative to index,
      ;;; but not into string yet, because:
    (if (<= fmtval 9) ;;; can't make numerical comparison with text string
      (setq str (strcat "0" (itoa fmtval ))) ;;; nor can you use (itoa) on text string
      (setq str (itoa fmtval))
    ); if
;;; (setq newStr ( strcat fmtval ) );combine formatted value with string
;;; something missing in above line [no point in (strcat) with 1 argument], but not needed
    (setq d (cons 1 str));construct new list
    (setq b2 (subst d (assoc 1 b) b));replace old list with new list ;;; new b2 variable name
       ;;; (assoc 1 b) directly here [no need for iTx variable]
    (entmod b2;update the list
    (setq numb (+ numb 1));Increment number ;;; moved from earlier
  ); repeat
); defun
 
In fact, the d and b2 variables are not really needed, either.  You could replace this much:
    (setq d (cons 1 str));construct new list
    (setq b2 (subst d (assoc 1 b) b));replace old list with new list
    (entmod b2;update the list
with just:
    (entmod (subst (cons 1 str) (assoc 1 b) b))
Kent Cooper, AIA
Message 7 of 7

Anonymous
Not applicable

Thank you Kent and Steve! Realized the hiccup was in the ssname function and getting my index screwy.

 

Here is what I have now, and I'm sure some of it is superfluous like you mentioned Kent (but at least it works now thank you):

 

(defun c:dnum (/ index numb ret ret2 a n b1 str b iTx str newStr d )
(setq index 0 )
(setq a ( ssget ) )
(setq n ( sslength a ) )
(setq numb ( getint "\nBeginning Number: "))
(repeat n
(setq b1 ( ssname a index ) );Step through list
(setq index ( + index 1 ) );Increment index
(setq b ( entget b1 ) );Copy the list
(setq iTx ( assoc 1 b ) );Old Text
(setq ret ( rtos numb 2 0 ) );Format numb
(setq ret2 (atoi ret))
(if (<= ret2 9) ; formats ret to have 0 in front
(setq ret (strcat "0" (itoa ret2 )))
(setq ret (itoa ret2))
); if
(setq d ( cons ( car iTx ) ret ) );construct new list
(setq b1 ( subst d iTx b ) );replace old list with new list
(entmod b1 ) ;update the list
(setq numb ( + numb 1 ) ) ;Increment numb
)
)
0 Likes