Simple

Discussion in 'AutoCAD' started by Justin Fisk, Oct 22, 2004.

  1. Justin Fisk

    Justin Fisk Guest

    Looking to do something very simple, and I'm sure everyone can save me some
    time.
    I have a routine that needs to search for a piece of incremented text.
    Effectively I need to set a string variable to increment with a counter,
    like:

    TEXT (1)
    TEXT (2)
    TEXT (3)
    ......
    TEXT (n)

    I need to be able to set the variable to (x), including the parenthesis.
    So...
    (setq text1 "(" x ")") doesn't seem to do it for me. I'm new to LISP so be
    kind.
    Thanks.
     
    Justin Fisk, Oct 22, 2004
    #1
  2. (setq text (strcat "(" x ")"))
     
    Alan Henderson @ A'cad Solutions, Oct 22, 2004
    #2
  3. Justin Fisk

    T.Willey Guest

    Try this.

    Tim

    (defun c:AddNumEnd(/ ent seqn *seqn txt1)

    (command "undo" "end")
    (command "undo" "group")

    (if (not *seqn)
    (setq *seqn 1)
    )

    (princ "\nStarting no. <")
    (princ *seqn)
    (setq seqn (getint ">: "))

    (if (not seqn)
    (setq seqn *seqn)
    (setq *seqn seqn)
    )

    (graphscr)
    (setq ent nil)
    (setq ent (nentsel "\nSelect text to start: "))

    (while ent
    (if ent
    (progn
    (setq ent (entget (car ent)))
    (if (or (= (cdr (assoc 0 ent)) "TEXT") (= (cdr (assoc 0 ent)) "ATTRIB"))
    (progn
    (setq txt1 (cdr (assoc 1 ent)))
    (setq txt1 (strcat txt1 " (" (itoa seqn) ")"))
    (entmod (subst (cons 1 txt1) (assoc 1 ent) ent))
    (entupd (value -1 ent))
    (setq seqn (1+ seqn))
    )
    (princ "\nEntity must be TEXT")
    )
    )
    )
    (princ "\n")
    (princ seqn)
    (setq ent (nentsel " - Select text to be changed: "))
    (setq *seqn seqn)
    )
    (command "undo" "end")
    (princ)
    )
     
    T.Willey, Oct 22, 2004
    #3
  4. Justin Fisk

    Justin Fisk Guest

    This is close to what I want to do... but it still has problems.
    When I use (i being my counter):
    (setq os (strcat "(" i ")"))
    It only seems to return the i. (then I get an error since i is a number not
    a string).
     
    Justin Fisk, Oct 22, 2004
    #4
  5. Justin Fisk

    Tom Smith Guest

    (setq os (strcat "(" i ")"))
    not a string).

    You need to convert the integer variable i to a string.

    (strcat "(" (itoa i) ")")
     
    Tom Smith, Oct 22, 2004
    #5
  6. Justin Fisk

    Justin Fisk Guest

    Thanks! Learning more every time.

     
    Justin Fisk, Oct 22, 2004
    #6
  7. Justin Fisk

    Tom Smith Guest

    Thanks! Learning more every time.

    The various conversion functions are a little tricky at first, just as with
    any language. Often it comes up when you're trying to string a bunch of
    stuff together into a message.

    In the Developer's Guide, look in the Appendices/AutoLISP Function
    Synosis/Utility Functions/Conversion Functions. The Synopsis area gives a
    good breakdown of lisp functions by what they do.

    Good luck!
     
    Tom Smith, Oct 22, 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.