Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Increment Selected Text

  1. #1
    Member
    Join Date
    2015-09
    Posts
    6
    Login to Give a bone
    0

    Default Increment Selected Text

    Hi,

    Does someone know of or can help with a Lisp routine that can change selected text by a specified increment?

    We have text headings and references to these headings are throughout the drawing.

    Certain text is not to be used: I, O, Q
    Above Z it becomes double letters AA, AB, AC......BA, BB, BC

    An example of the text is as follows:
    A, A, A, A, B, B, C, C, C, D, D, E, E, F, F, G, G, H, H,...........M, M, N, N,..............Z, Z

    With an increment of 2 , the text is changed as follows:
    C, C, C, C, D, D, E, E, E, F, F, G, G, G, G, J, J, K, K,...........P, P, R, R,..............AB, AB

    Thanks

  2. #2
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Increment Selected Text

    welcome rjb709739...

    What you are trying to do is create a base 23 (26 - 3 letters) number.

    It got me thinking that it would be useful to create other base numbers using any characters you might choose.

    I came up with this.

    Let me know if you find any bugs...

    P=

    Code:
    ;___________________________________________________________________________________________________________|
    ;
    ;
    ; Function to convert integers to and from a BaseK String 
    ;___________________________________________________________________________________________________________|
    
    (defun C:BaseK ()
     (and
      (setq strBase   "ABCDEFGHJKLMNPRSTUVWXYZ") ;AlphaNumeric
     ; (setq strBase  "0123456789ABCDEF")       ;Hexadecimal
     ; (setq strBase  "0123456789")             ;Decimal
     ; (setq strBase  "01")                     ;Binary
      (setq intNumber (getint "\nEnter Integer: "))
      (setq strValue (Base10ToBaseK strBase intNumber));<-Convert Integer to BaseK string
      (princ (strcat "\nValue in " strBase " Values: "))
      (princ strValue)
      (setq intNumber (BaseKToBase10 strBase strValue));<- Convert BaseK String to Integer
      (princ "\n")
      (princ intNumber)
     )
     (princ)
    )
    
    ;___________________________________________________________________________________________________________|
    
    (defun Base10ToBaseK (strBase intNumber / intBase intDigit intRemainder lstReturn )
     (setq intBase   (strlen strBase))
     (if (= intNumber 0)(setq lstReturn (list 0)))
     (while (> intNumber 0)
      (setq intDigit     (/ intNumber intBase))
      (setq intRemainder (- intNumber (* intBase intDigit)))
      (setq lstReturn    (cons intRemainder lstReturn))
      (setq intNumber    intDigit)
     )
     (apply 'strcat (mapcar '(lambda (X)(substr strBase (1+ X) 1)) lstReturn))  
    )
    
    ;___________________________________________________________________________________________________________|
    
    (defun BaseKToBase10 (strBase strValue / intBase intCount intTotal)
     (setq intBase (strlen strBase))
     (setq intTotal 0)
     (repeat (setq intCount (strlen strValue))
      (setq intTotal (+ intTotal 
                        (* (expt intBase (- (strlen strValue) intCount))
                           (vl-string-search (substr strValue intCount 1) strBase)
                        )
                     )
      )
      (setq intCount (1- intCount))
     )
     intTotal
    
    )
    (vl-load-com)
    Attached Files Attached Files
    AutomateCAD

  3. #3
    Member
    Join Date
    2015-09
    Posts
    6
    Login to Give a bone
    0

    Default Re: Increment Selected Text

    Thanks Peter. That was an interesting way of looking at it - using Base23.

    One problem is that integer 23 returned 'BA' rather than 'AB' and so on.

    I don't have the skills yet to take your code further to be able to select text and enter an increment or decrement to change the selected text.
    Hopefully someday.

    Thanks again.

  4. #4
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Increment Selected Text

    A in this code is 0.

    Show me your code for selecting text and getting the string value to change.

    It is very straight forward, but it is good practice for you to try.

    P=
    AutomateCAD

  5. #5
    Member
    Join Date
    2015-09
    Posts
    6
    Login to Give a bone
    0

    Default Re: Increment Selected Text

    Hi Peter,

    I did notice that A is 0 in the code. The problem is that the current sequence used on the drawings is X,Y,Z,AA,AB..... and not X,Y,Z,BA,BB.......

    That cannot be changed.

    When I figure out the required code I will post it.

    Thanks!

  6. #6
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Increment Selected Text

    Revised to give you Y,Z,AA,AB, etc...

    P=

    Code:
    ;___________________________________________________________________________________________________________|
    ;
    ;
    ; Function to convert integers to and from a BaseK String 
    ;___________________________________________________________________________________________________________|
    
    (defun C:BaseK2 ()
     (and
      (setq strBase   "ABCDEFGHJKLMNPRSTUVWXYZ") ;AlphaNumeric
      (setq intNumber (getint "\nEnter Integer: "))
      (setq strValue (Base10ToBaseK2 strBase intNumber));<-Convert Integer to BaseK string
      (princ (strcat "\nValue in " strBase " Values: "))
      (princ strValue)
      (setq intNumber2 (BaseKToBase102 strBase strValue));<- Convert BaseK String to Integer
    ;  (princ "\n")
    ;  (princ intNumber)
     )
     (princ)
    )
    
    ;___________________________________________________________________________________________________________|
    
    (defun Base10ToBaseK2 (strBase intNumber / intBase intDigit intRemainder lstReturn )
     (setq intBase   (strlen strBase))
     (if (= intNumber 0)(setq lstReturn (list 0)))
     (while (> intNumber 0)
      (setq intDigit     (/ intNumber intBase))
      (setq intRemainder (- intNumber (* intBase intDigit)))
      (or (> intRemainder 0)
          (setq intRemainder intBase intDigit (1- intDigit))
      )
      (setq lstReturn    (cons intRemainder lstReturn))
      (setq intNumber    intDigit)
     )
     (apply 'strcat (mapcar '(lambda (X)(substr strBase X 1)) lstReturn))  
    )
    
    ;___________________________________________________________________________________________________________|
    
    (defun BaseKToBase102 (strBase strValue / intBase intCount intTotal)
     (setq intBase (strlen strBase))
     (setq intTotal 0)
     (repeat (setq intCount (strlen strValue))
      (setq intTotal (+ intTotal 
                        (* (expt intBase (- (strlen strValue) intCount))
                           (1+ (vl-string-search (substr strValue intCount 1) strBase))
                        )
                     )
      )
      (setq intCount (1- intCount))
     )
     intTotal
    
    )
    
    (vl-load-com)
    Attached Files Attached Files
    Last edited by peter; 2015-10-05 at 02:50 AM.
    AutomateCAD

  7. #7
    Member
    Join Date
    2015-09
    Posts
    6
    Login to Give a bone
    0

    Default Re: Increment Selected Text

    Thanks Peter.

    Slight problem in that Integer 23 fails and does not output 'Z'.

  8. #8
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Increment Selected Text

    Quote Originally Posted by rjb709739 View Post
    Thanks Peter.

    Slight problem in that Integer 23 fails and does not output 'Z'.
    I tweaked it to prevent the fail on 23.

    P=
    AutomateCAD

  9. #9
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Increment Selected Text

    Quote Originally Posted by rjb709739 View Post
    Not sure how to put the code in a nice formatted window like your post.
    You mean code tags...
    Look here : http://forums.augi.com/misc.php?do=bbcode#code

    [code] Your code here ... [/code]

  10. #10
    Member
    Join Date
    2015-09
    Posts
    6
    Login to Give a bone
    0

    Default Re: Increment Selected Text

    Thanks Marko. That was it.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 5
    Last Post: 2016-08-11, 11:35 PM
  2. 2013: Copy and Increment Text
    By nlrdavid in forum AutoCAD General
    Replies: 6
    Last Post: 2013-05-16, 06:46 PM
  3. Replies: 2
    Last Post: 2007-12-17, 09:10 PM
  4. Increment Text
    By robert.1.hall72202 in forum AutoLISP
    Replies: 11
    Last Post: 2007-01-11, 08:11 PM
  5. Increment Text Numbers
    By larry.80915 in forum AutoCAD General
    Replies: 2
    Last Post: 2005-01-12, 05:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •