Help with a text counter

  • Thread starter Thread starter Matthew.Corbin
  • Start date Start date
M

Matthew.Corbin

Hello all,

I'm sure something similar has popped up in here before but I haven't been able to find a solution. I'm writing a routine to change existing text. First it will ask for a starting number, then a number to increment by. I've gotten that all done. I'm having trouble adding the increment to each subsequent number I pick. Here is the code i'm flustered with.

(setq firsttext (entget (car (entsel "\nselect text: "))))
(entmod (subst (cons 1 startingnumber)(assoc 1 firsttext)firsttext))

(setq startingnumber (+ startingnumber increment))

(while
(setq nexttext (entget (car (entsel "\nselect destination text: "))))
(entmod (subst (cons 1 startingnumber)(assoc 1 nexttexttext)nexttext))

(setq startingnumber (+ startingnumber increment))

)

I'm not sure what i'm missing. For some reason the addition isn't working. I'm getting errors like "error: bad argument type: numberp:" Any help would be greatly appreciated.
 
Is startingnumber an integer? I suspect that it is. If so, you need to convert it to a string

(entmod (subst (cons 1 (itoa startingnumber)) (assoc 1 firsttext) firsttext))
(entmod (subst (cons 1 (itoa startingnumber)) (assoc 1 nexttexttext) nexttext))

Matthew.Corbin said:
Hello all,

I'm sure something similar has popped up in here before but I haven't been able to find a
solution. I'm writing a routine to change existing text. First it will ask for a starting number,
then a number to increment by. I've gotten that all done. I'm having trouble adding the increment to
each subsequent number I pick. Here is the code i'm flustered with.
(setq firsttext (entget (car (entsel "\nselect text: "))))
(entmod (subst (cons 1 startingnumber)(assoc 1 firsttext)firsttext))

(setq startingnumber (+ startingnumber increment))

(while
(setq nexttext (entget (car (entsel "\nselect destination text: "))))
(entmod (subst (cons 1 startingnumber)(assoc 1 nexttexttext)nexttext))

(setq startingnumber (+ startingnumber increment))

)

I'm not sure what i'm missing. For some reason the addition isn't working. I'm getting errors like
"error: bad argument type: numberp:" Any help would be greatly appreciated.
 
Looks like it might be trying to add strings, not numbers. How do you get the first "startingnumber"? If you use getstring, try getreal.. or some other function to get a number.


Hope it helps.
Tim
 
I'm pretty sure i'm not dealing with a string as i've used this code earlier on to make sure.

(setq startingnumber (rtos startingnumber 2 0))

I've also used getreal to get the "startingnumber". You can probably see why i'm puzzled. theoretically it should work. When I remove the code that adds the increment to the startingnumber everything works fine. Also, "increment" is set the exact same way as "startingnumber". So both should be real numbers.

Matthew Corbin
 
Here is a snippet from a routine.

(initget 7)
(setq new_num (getint "\nInput new start number: "))
(initget 7)
(setq inc (getint "\nInput increment value: "))
(while
(and
(setq ent (car (entsel "\nSelect Sheet Number")))
(vlax-property-available-p
(setq ent (vlax-ename->vla-object ent))
"textstring"))
(vla-put-textstring ent (rtos new_num))
(setq new_num (+ new_num inc))
)


--
Ken Alexander
Acad2004
Windows XP

"We can't solve problems by using the same kind
of thinking we used when we created them."
--Albert Einstein

Matthew.Corbin said:
Hello all,

I'm sure something similar has popped up in here before but I
haven't been able to find a solution. I'm writing a routine to change
existing text. First it will ask for a starting number, then a number
to increment by. I've gotten that all done. I'm having trouble adding
the increment to each subsequent number I pick. Here is the code i'm
flustered with.
(setq firsttext (entget (car (entsel "\nselect text: "))))
(entmod (subst (cons 1 startingnumber)(assoc 1 firsttext)firsttext))

(setq startingnumber (+ startingnumber increment))

(while
(setq nexttext (entget (car (entsel "\nselect destination text: "))))
(entmod (subst (cons 1 startingnumber)(assoc 1 nexttexttext)nexttext))

(setq startingnumber (+ startingnumber increment))

)

I'm not sure what i'm missing. For some reason the addition isn't
working. I'm getting errors like "error: bad argument type: numberp:"
Any help would be greatly appreciated.
 
Hmm that is indeed short and sweet. Maybe I should look at using Vlisp more often.It is pretty similar to VBA right? Your help has been greatly appreciated. Thanks for the code.

Matthew Corbin
 
You're welcome.

BTW:

(entmod (subst (cons 1 startingnumber)(assoc 1 nexttexttext)nexttext))

(assoc 1 nexttexttext).....got one too many "text"

--
Ken Alexander
Acad2004
Windows XP

"We can't solve problems by using the same kind
of thinking we used when we created them."
--Albert Einstein

Matthew.Corbin said:
Hmm that is indeed short and sweet. Maybe I should look at using
Vlisp more often.It is pretty similar to VBA right? Your help has been
greatly appreciated. Thanks for the code.
 
Back
Top