seeking a LISP program

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

  1. FELIPE

    FELIPE Guest

    To All:

    I am seeking a LISP program that is capable of changing the Most Significant Digit
    of an Alphanumeric String or Numeric String, Also having a global select or find property.

    Example:

    The strings 213CR, 235CON, and 210 are found or selected.

    Thru the input prompt the number <5> was entered.

    The results are:

    513CR, 535CON, and 510.

    Thanks
     
    FELIPE, Sep 10, 2004
    #1
  2. FELIPE

    worlandm Guest

    The FIND command does this
     
    worlandm, Sep 10, 2004
    #2
  3. FELIPE

    FELIPE Guest

    Please provide an example.
     
    FELIPE, Sep 10, 2004
    #3
  4. FELIPE

    andywatson Guest

    Is this what you're looking for?
    1. Start with "sigdig".
    2. Type new most significant digit.
    3. Select text or mtext objects.
    The command will analyze each text object from left to right. As soon as a number is found, that number is replaced with user-entered number.

    Code:
    ;; given an ascii code, function determines if it represents a number.
    ;; returns T if number, nil if something other than number
    (defun IsNumber (asc / )
    (and
    (>= asc 48)
    (<= asc 57)
    ); and
    ); defun
    ;;
    ;;
    ;; command to replace most significant digit of user-selected
    ;; mtext or text entities with user-supplied number.
    ;; analyzes text string from left to right. when a number is found,
    ;; that number is replaced with the new sig dig.
    ;; if text contains no numbers, nothing happens.
    (defun c:sigdig ( / ss)
    ;; load activex
    (vl-load-com)
    ;; get autocad document
    (setq acadDoc (vla-get-activedocument (vlax-get-acad-object)))
    ;; if user enters new sig dig and select objects...
    (cond
    ;; user entered empty string
    ((= "" (setq intNewSigDig (getstring "\nEnter new most significant digit: ")))
    ;; do nothing
    nil
    )
    ;; user entered new sig dig and selects objects
    ((setq ss (ssget '((0 . "TEXT,MTEXT"))))
    ;; get activex selection set
    (setq ss (vla-get-activeselectionset acadDoc))
    ;; cycle through every object in selection set
    (vlax-for obj ss
    ;; get text string, convert to list of ascii codes
    (setq strText (vla-get-textstring obj)
    intCodes (vl-string->list strText)
    ); setq
    ;; start from left side of string, iterate thru codes until a number code is found
    (while (and
    intCodes
    (not (IsNumber (car intCodes)))
    ); and
    ;; remove first code from list
    (setq intCodes (cdr intCodes))
    )
    ;; if a number is found within textstring
    (if intCodes
    (progn
    ;; get string value of left-most number, replace with user-specified sig dig
    (setq intOldSigDig (chr (car intCodes))
    strNewText (vl-string-subst intNewSigDig intOldSigDig strText)
    ); setq
    ;; replace textstring in text object
    (vla-put-textstring obj strNewText)
    ); progn
    ); if
    ); vlax-for
    )
    ); cond
    ;; release autocad document object
    (vlax-release-object acadDoc)
    ;; exit quietly
    (princ)
    ); defun
    ;;
    ;;
    (prompt "\nStart command with \"sigdig\".")
    
     
    andywatson, Sep 14, 2004
    #4
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.