Help with a text counter

Discussion in 'AutoCAD' started by Matthew.Corbin, Aug 5, 2004.

  1. 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.
     
    Matthew.Corbin, Aug 5, 2004
    #1
  2. 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))

    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.
    "error: bad argument type: numberp:" Any help would be greatly appreciated.
     
    Allen Johnson, Aug 5, 2004
    #2
  3. Matthew.Corbin

    T.Willey Guest

    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
     
    T.Willey, Aug 5, 2004
    #3
  4. 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
     
    Matthew.Corbin, Aug 5, 2004
    #4
  5. 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

    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.
    working. I'm getting errors like "error: bad argument type: numberp:"
    Any help would be greatly appreciated.
     
    Ken Alexander, Aug 5, 2004
    #5
  6. 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
     
    Matthew.Corbin, Aug 5, 2004
    #6
  7. 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

    Vlisp more often.It is pretty similar to VBA right? Your help has been
    greatly appreciated. Thanks for the code.
     
    Ken Alexander, Aug 5, 2004
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.