MODIFY EXISTING LISP

Discussion in 'AutoCAD' started by FELIPE, Sep 28, 2004.

  1. FELIPE

    FELIPE Guest

    This is a lisp file that changes the Most Significant Digit
    of an Alphanumeric String or Numeric String.
    It needs to be modified so,
    If the 1st character in a string is an alpha character, do not change anything in the string.
    In addition, if the string is less than 3 characters long, do not change anything in the string.
    I would appreciate any help thanks.

    (defun c:1st_num (/ found)
    (setq new_val (getstring "Enter replacement numeral: "))
    (if (setq string_set (ssget '((0 . "text,mtext"))))
    (progn
    (setq counter (sslength string_set))
    (while (> (setq counter (- counter 1)) -1)
    (setq cur_string (entget (ssname string_set counter)))
    (if (and (setq cur_value (cdr (assoc 1 cur_string)))(/= cur_value ""))
    (progn
    (setq the_length (strlen cur_value)
    char_place 1
    no_number T
    )
    (while (and (>= the_length char_place) no_number)
    (if (numberp (distof (setq cur_char (substr cur_value char_place 1))))
    (progn
    (setq cur_value (vl-string-subst new_val cur_char cur_value))
    (entmod (subst (cons 1 cur_value)(assoc 1 cur_string) cur_string))
    (setq no_number nil)
    )
    (setq char_place (+ char_place 1))
    )
    )
    )
    )
    )
    )
    )
    )
     
    FELIPE, Sep 28, 2004
    #1
  2. FELIPE

    T.Willey Guest

    Ok.

    (if
    (and
    (not (< (strlen cur_value) 3)); <- check string length
    (not (<= 65 (ascii (substr cur_value 1 1)) 122)) <- check to see if it's a letter between "A" and "z"
    ); and
    ); if

    This will go on if the string length is longer than 3, and the first value isn't between "A" and "z". I think that is what you asked.

    Hope it helps.
    Tim
     
    T.Willey, Sep 28, 2004
    #2
  3. FELIPE

    FELIPE Guest

    Sorry for being dense.
    but I guess I just don't know were in the routine to put this.
    thanks
     
    FELIPE, Sep 28, 2004
    #3
  4. FELIPE

    T.Willey Guest

    Try this. It took a long time for me to understand how you wrote it and see where I needed to add it, but it worked on my test drawing. Watch for word wrap.

    Tim

    (defun c:1st_num (/ new_val string_set counter cur_string cur_value the_length char_place
    no_number cur_chr found)

    (setq new_val (getstring "Enter replacement numeral: "))
    (if (setq string_set (ssget '((0 . "text,mtext"))))
    (progn
    (setq counter (sslength string_set))
    (while (> (setq counter (- counter 1)) -1)
    (setq cur_string (entget (ssname string_set counter)))
    (if (and (setq cur_value (cdr (assoc 1 cur_string)))(/= cur_value ""))
    (progn
    (setq the_length (strlen cur_value)
    char_place 1
    no_number T
    ); setq
    (while (and (>= the_length char_place) no_number)
    (if
    (and
    (numberp (distof (setq cur_char (substr cur_value char_place 1))))
    (> (strlen cur_value) 3); <- check string length
    (not (<= 65 (ascii (substr cur_value 1 1)) 122)); <- check to see if it's a letter between "A" and "z"
    ); and
    (progn
    (setq cur_value (vl-string-subst new_val cur_char cur_value))
    (entmod (subst (cons 1 cur_value)(assoc 1 cur_string) cur_string))
    (setq no_number nil)
    ); progn
    (setq char_place (+ char_place 1))
    ); if
    ); while
    ); progn
    ); if
    ); while
    ); progn
    ); if
    )
     
    T.Willey, Sep 28, 2004
    #4
  5. FELIPE

    FELIPE Guest

    Thanks Tim
    Its exactly what I needed, and it works great.
     
    FELIPE, Sep 29, 2004
    #5
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.