adding up lisp

Discussion in 'AutoCAD' started by Laura, Jul 22, 2003.

  1. Laura

    Laura Guest

    I have a lispoutine that adds up nummers.
    When I select a text it copies and ads 1 to it.
    So when I select a 2 it copies and places a 3.

    (defun c:add ( / OBJECT)
    (setq OBJECT (ssget))
    (setq pt (cdr (assoc 10 (entget (ssname OBJECT 0)))))
    (command "copy" OBJECT "" pt pt)
    (command "move" OBJECT "" pt pause)
    (setq cnt 0)
    (repeat (sslength OBJECT)
    (setq txt (cdr (assoc 1 (entget (ssname OBJECT cnt)))))
    (setq txt (itoa (1+ (atoi txt)))) ; converts string into integer
    (setq ent (subst (cons 1 txt) (assoc 1 (entget (ssname OBJECT cnt)))
    (entget
    (ssname OBJECT cnt))))
    (entmod ent)
    (setq cnt (1+ cnt))
    )
    )

    This works fine.

    Only I want to place a text in front of it. Like
    "part 1" copies into "part 2"

    "Atoi" turns a text into an integer.

    How can I split the selected text (like part 1) into
    "part " (=string) --> setq PART <string>
    "1" (=integer) --> setq integer txt
    add 1 to the integer

    To combine I know you have to use:

    (setq PARTTOTAL (strcat PART TXT))

    But I'm stuck further.

    can anybody help me?

    thanks

    Laura
     
    Laura, Jul 22, 2003
    #1
  2. Laura,
    take a look at the string - handling - functions



    Pierre



    The following table provides summary descriptions of the AutoLISP string-handling functions.

    String-handling functions&nbsp;



    Function



    Description



    (









    read
    [string])



    Returns the first list or atom obtained from a string



    (









    strcase
    string [which])



    Returns a string where all alphabetic characters have been converted to uppercase or lowercase



    (









    strcat
    [string1 [string2] ...)



    Returns a string that is the concatenation of multiple strings



    (









    strlen
    [string] ...)



    Returns an integer that is the number of characters in a string



    (









    substr
    string start [length])



    Returns a substring of a string



    (









    vl-prin1-to-string
    object)



    Returns the string representation of any LISP object as if it were output by the prin1 function



    (









    vl-princ-to-string
    object)



    Returns the string representation of any LISP object as if it were output by the princ function



    (









    vl-string-&gt;list
    string)



    Converts a string into a list of character codes



    (









    vl-string-elt
    string position)



    Returns the ASCII representation of the character at a specified position in a string



    (









    vl-string-left-trim
    character-set string)



    Removes the specified characters from the beginning of a string



    (









    vl-string-mismatch
    str1 str2
    [pos1 pos2 ignore-case-p])



    Returns the length of the longest common prefix for two strings, starting at specified positions



    (









    vl-string-position
    char-code str [start-pos [from-end-p]])



    Looks for a character with the specified ASCII code in a string



    (









    vl-string-right-trim
    character-
    set string)



    Removes the specified characters from the end of a string



    (









    vl-string-search
    pattern string [start-pos])



    Searches for the specified pattern in a string



    (









    vl-string-subst
    new-str pattern string [start-pos])



    Substitutes one string for another, within a string



    (









    vl-string-translate

    source-set dest-set str)



    Replaces characters in a string with a specified set of characters



    (









    vl-string-trim
    char-set str)



    Removes the specified characters from the beginning and end of a string



    (









    wcmatch
    string pattern)



    Performs a wild-card pattern match on a string





    &nbsp; &nbsp;Comments?&nbsp;&nbsp;
    "Laura" &lt;&gt; schrieb im Newsbeitrag &gt; I have a lispoutine that adds up nummers.
    &gt; When I select a text it copies and ads 1 to it.
    &gt; So when I select a 2 it copies and places a 3.
    &gt;
    &gt; (defun c:add ( / OBJECT)
    &gt;&nbsp; (setq OBJECT (ssget))
    &gt;&nbsp; (setq pt (cdr (assoc 10 (entget (ssname OBJECT 0)))))
    &gt;&nbsp; (command "copy" OBJECT "" pt pt)
    &gt;&nbsp; (command "move" OBJECT "" pt pause)
    &gt;&nbsp; (setq cnt 0)
    &gt;&nbsp; (repeat (sslength OBJECT)
    &gt;&nbsp;&nbsp; (setq txt (cdr (assoc 1 (entget (ssname OBJECT cnt)))))
    &gt;&nbsp;&nbsp; (setq txt (itoa (1+ (atoi txt)))) ; converts string into integer
    &gt;&nbsp;&nbsp; (setq ent (subst (cons 1 txt) (assoc 1 (entget (ssname OBJECT cnt)))
    &gt; (entget
    &gt; (ssname OBJECT cnt))))
    &gt;&nbsp;&nbsp; (entmod ent)
    &gt;&nbsp;&nbsp; (setq cnt (1+ cnt))
    &gt;&nbsp; )
    &gt; )
    &gt;
    &gt; This works fine.
    &gt;
    &gt; Only I want to place a text in front of it. Like
    &gt; "part 1" copies into "part 2"
    &gt;
    &gt; "Atoi" turns a text into an integer.
    &gt;
    &gt; How can I split the selected text (like part 1) into
    &gt; "part " (=string) --&gt; setq PART &lt;string&gt;
    &gt; "1" (=integer)&nbsp; --&gt; setq integer txt
    &gt; add 1 to the integer
    &gt;
    &gt; To combine I know you have to use:
    &gt;
    &gt; (setq PARTTOTAL (strcat PART TXT))
    &gt;
    &gt; But I'm stuck further.
    &gt;
    &gt; can anybody help me?
    &gt;
    &gt; thanks
    &gt;
    &gt; Laura
     
    Pierre de la Verre, Jul 22, 2003
    #2
  3. Laura

    Laura Guest

    I'm going to figure that out.



    thanks



    &nbsp;



    laura



    "Pierre de la Verre" &lt;&gt; schreef in bericht news:...





    Laura,
    take a look at the string - handling - functions



    Pierre



    The following table provides summary descriptions of the AutoLISP string-handling functions.

    String-handling functions&nbsp;



    Function



    Description



    (









    read
    [string])



    Returns the first list or atom obtained from a string



    (









    strcase
    string [which])



    Returns a string where all alphabetic characters have been converted to uppercase or lowercase



    (









    strcat
    [string1 [string2] ...)



    Returns a string that is the concatenation of multiple strings



    (









    strlen
    [string] ...)



    Returns an integer that is the number of characters in a string



    (









    substr
    string start [length])



    Returns a substring of a string



    (









    vl-prin1-to-string
    object)



    Returns the string representation of any LISP object as if it were output by the prin1 function



    (









    vl-princ-to-string
    object)



    Returns the string representation of any LISP object as if it were output by the princ function



    (









    vl-string-&gt;list
    string)



    Converts a string into a list of character codes



    (









    vl-string-elt
    string position)



    Returns the ASCII representation of the character at a specified position in a string



    (









    vl-string-left-trim
    character-set string)



    Removes the specified characters from the beginning of a string



    (









    vl-string-mismatch
    str1 str2
    [pos1 pos2 ignore-case-p])



    Returns the length of the longest common prefix for two strings, starting at specified positions



    (









    vl-string-position
    char-code str [start-pos [from-end-p]])



    Looks for a character with the specified ASCII code in a string



    (









    vl-string-right-trim
    character-
    set string)



    Removes the specified characters from the end of a string



    (









    vl-string-search
    pattern string [start-pos])



    Searches for the specified pattern in a string



    (









    vl-string-subst
    new-str pattern string [start-pos])



    Substitutes one string for another, within a string



    (









    vl-string-translate

    source-set dest-set str)



    Replaces characters in a string with a specified set of characters



    (









    vl-string-trim
    char-set str)



    Removes the specified characters from the beginning and end of a string



    (









    wcmatch
    string pattern)



    Performs a wild-card pattern match on a string





    &nbsp; &nbsp;Comments?&nbsp;&nbsp;
    "Laura" &lt;&gt; schrieb im Newsbeitrag &gt; I have a lispoutine that adds up nummers.
    &gt; When I select a text it copies and ads 1 to it.
    &gt; So when I select a 2 it copies and places a 3.
    &gt;
    &gt; (defun c:add ( / OBJECT)
    &gt;&nbsp; (setq OBJECT (ssget))
    &gt;&nbsp; (setq pt (cdr (assoc 10 (entget (ssname OBJECT 0)))))
    &gt;&nbsp; (command "copy" OBJECT "" pt pt)
    &gt;&nbsp; (command "move" OBJECT "" pt pause)
    &gt;&nbsp; (setq cnt 0)
    &gt;&nbsp; (repeat (sslength OBJECT)
    &gt;&nbsp;&nbsp; (setq txt (cdr (assoc 1 (entget (ssname OBJECT cnt)))))
    &gt;&nbsp;&nbsp; (setq txt (itoa (1+ (atoi txt)))) ; converts string into integer
    &gt;&nbsp;&nbsp; (setq ent (subst (cons 1 txt) (assoc 1 (entget (ssname OBJECT cnt)))
    &gt; (entget
    &gt; (ssname OBJECT cnt))))
    &gt;&nbsp;&nbsp; (entmod ent)
    &gt;&nbsp;&nbsp; (setq cnt (1+ cnt))
    &gt;&nbsp; )
    &gt; )
    &gt;
    &gt; This works fine.
    &gt;
    &gt; Only I want to place a text in front of it. Like
    &gt; "part 1" copies into "part 2"
    &gt;
    &gt; "Atoi" turns a text into an integer.
    &gt;
    &gt; How can I split the selected text (like part 1) into
    &gt; "part " (=string) --&gt; setq PART &lt;string&gt;
    &gt; "1" (=integer)&nbsp; --&gt; setq integer txt
    &gt; add 1 to the integer
    &gt;
    &gt; To combine I know you have to use:
    &gt;
    &gt; (setq PARTTOTAL (strcat PART TXT))
    &gt;
    &gt; But I'm stuck further.
    &gt;
    &gt; can anybody help me?
    &gt;
    &gt; thanks
    &gt;
    &gt; Laura
     
    Laura, Jul 24, 2003
    #3
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.