See the top rated post in this thread. Click here

Results 1 to 4 of 4

Thread: AutoLISP program coverts upper to lower, or lower to upper case

  1. #1
    I could stop if I wanted to
    Join Date
    2006-04
    Posts
    442
    Login to Give a bone
    0

    Default AutoLISP program coverts upper to lower, or lower to upper case

    ;this autolisp program coverts upper to lower, or lower to upper case

    Code:
    (DEFUN C:TCC (/ TC TCT TS TSL CT LP NEN NENL NENA NENS NNENS NNENA NNENL)
      (PROMPT "\n*TEXT CASE CONVERSION* ")
      (SETQ TC (GETSTRING "Uppercase/Lowercase <U> :"))
      (IF (OR (= TC "U") (= TC ""))
        (SETQ TCT NIL)
        (SETQ TCT 1)
      )
      (PROMPT "\nChoose text to convert")
      (SETQ TS (SSGET '((0 . "TEXT"))))
      (SETQ TSL (SSLENGTH TS))
      (SETQ CT (- TSL 1))
      (SETQ LP 1)
      (WHILE LP
        (SETQ NEN (SSNAME TS CT))
        (SETQ NENL (ENTGET NEN))
        (SETQ NENA (ASSOC 1 NENL))
        (SETQ NENS (CDR NENA))
        (SETQ NNENS (STRCASE NENS TCT))
        (SETQ NNENA (CONS 1 NNENS))
        (SETQ NNENL (SUBST NNENA NENA NENL))
        (ENTMOD NNENL)
        (SETQ CT (- CT 1))
        (IF	(< CT 0)
          (SETQ LP NIL)
        )
      );END WHILE
      (PRINC)
    );END TCC
    [ Moderator Action = ON ] What are [ CODE ] tags... [ Moderator Action = OFF ]
    Attached Files Attached Files
    Last edited by Mike.Perry; 2007-01-09 at 09:21 AM. Reason: [CODE] tags added.

  2. #2
    I could stop if I wanted to
    Join Date
    2003-11
    Posts
    277
    Login to Give a bone
    0

    Default Re: AutoLISP program coverts upper to lower, or lower to upper case

    Hi aaronic,
    Do you mean like this.
    Code:
    (defun c:tcc (/ cnt edm lp nen nena nenl nnena nnens tc ts tsl)
      (prompt "\n*text case conversion* ")
      (setq tc (getstring "uppercase/lowercase <u> :"))
      ;(if (or (= tc "u") (= tc "")) (setq tct nil) (setq tct 1))
      (cond
        ((or (= tc "u")(= tc ""))(setq tc "u"))    
        ((= tc "l")(setq tc "l"))
        )
      (prompt "\nchoose text to convert")
      (setq ts (ssget '((0 . "text")) ))
      (setq tsl (sslength ts))
      ;(setq ct (- tsl 1))
      (setq cnt 0)
      (setq lp 1)
      ;(while lp
      (repeat
        tsl
        (setq nen (ssname ts cnt))
        (setq nenl (entget nen))
        (setq nena (cdr (assoc 1 nenl)))
        ;(setq nens (cdr nena))
        (if
          (= tc "u")
          (progn
    	(setq nnens (strcase nena))
    	(setq nnena (cons 1 nnens))
    	;(setq nnenl (subst nnena nena nenl))
    	(setq edm (subst nnena (assoc 1 nenl) nenl))
    	(entmod edm)
    	)
          )                               ; if
        (if
          (= tc "l")
          (progn
    	(setq nnens (strcase nena t))
    	(setq nnena (cons 1 nnens))
    	;(setq nnenl (subst nnena nena nenl))
    	(setq edm (subst nnena (assoc 1 nenl) nenl))
    	(entmod edm)
    	)
          )                               ; if    
        ;(setq ct (- ct 1))
        (setq cnt (1+ cnt))
        ;(if (< ct 0) (setq lp nil))
        )                                  ; repeat
      (princ)
      );end tcc
    Quote Originally Posted by aaronic_abacus
    ;this autolisp program coverts upper to lower, or lower to upper case

    (DEFUN C:TCC (/ TC TCT TS TSL CT LP NEN NENL NENA NENS NNENS NNENA NNENL)
    (PROMPT "\n*TEXT CASE CONVERSION* ")
    (SETQ TC (GETSTRING "Uppercase/Lowercase <U> :"))
    (IF (OR (= TC "U") (= TC "")) (SETQ TCT NIL) (SETQ TCT 1))
    (PROMPT "\nChoose text to convert")
    (SETQ TS (SSGET '((0 . "TEXT")) ))
    (SETQ TSL (SSLENGTH TS))
    (SETQ CT (- TSL 1))
    (SETQ LP 1)
    (WHILE LP
    (SETQ NEN (SSNAME TS CT))
    (SETQ NENL (ENTGET NEN))
    (SETQ NENA (ASSOC 1 NENL))
    (SETQ NENS (CDR NENA))
    (SETQ NNENS (STRCASE NENS TCT))
    (SETQ NNENA (CONS 1 NNENS))
    (SETQ NNENL (SUBST NNENA NENA NENL))
    (ENTMOD NNENL)
    (SETQ CT (- CT 1))
    (IF (< CT 0) (SETQ LP NIL))
    );END WHILE
    (PRINC)
    );END TCC

  3. #3
    I could stop if I wanted to
    Join Date
    2015-08
    Posts
    263
    Login to Give a bone
    0

    Default Re: AutoLISP program coverts upper to lower, or lower to upper case

    Quote Originally Posted by aaronic_abacus
    ;this autolisp program coverts upper to lower, or lower to upper case

    Code:
    (DEFUN C:TCC (/ TC TCT TS TSL CT LP NEN NENL NENA NENS NNENS NNENA NNENL)
    (PROMPT "\n*TEXT CASE CONVERSION* ")
    (SETQ TC (GETSTRING "Uppercase/Lowercase <U> :"))
    (IF (OR (= TC "U") (= TC ""))
    (SETQ TCT NIL)
    (SETQ TCT 1)
    )
    (PROMPT "\nChoose text to convert")
    (SETQ TS (SSGET '((0 . "TEXT"))))
    Friends,

    It is better to user Initget and Getkword functions to control user inputs. Then chances of crashing your code is minimal. I am posting a text case change utility, which includes MTEXT also.

    Code:
     
    ;;; Change Text to upper case or lower case
    ;;; Default is upper case
    ;;; By Abdul Huck <abdulhuck@rediffmail.com>
    ;;;__________________________________________________________________
    (defun c:case (/  s_set	s_len	 edata	 temp
    		ex_string nw_string Opt	  lgname	OldCmd
    		OldLup
    	   )
      
      (setq Oldcmd (getvar "cmdecho"))
      (setq OldLup (getvar "Luprec"))
      (setvar "cmdecho" 0)
      (setvar "luprec" 0)
      (prompt "\nSelect text entities......")
      (setq s_set
      (ssget
    	'((-4 . "<OR") (0 . "TEXT") (0 . "MTEXT") (-4 . "OR>"))
      )
      )
      (if s_set
    	(progn
    	  (initget "Upper Lower")
    	  (setq Opt (getkword "\nChange to <Upper> / Lower case ?"))
    	  (if (= opt nil)
     (setq opt "UPPER")
    	  )
       (setq s_len (sslength s_set))
       (While
    	 (> s_len 0)
    	  (setq temp (ssname s_set (setq s_len (1- s_len))))
    	  (setq edata (entget temp))
    	  (setq ex_string (cdr (assoc 1 edata)))
    	  (if (/= (strcase Opt) "LOWER")
    		(setq nw_string (strcase ex_string))
    		(setq nw_string (strcase ex_string T))
    	  )
    	  (setq edata
    	  (subst (cons 1 nw_string) (cons 1 ex_string) edata)
    	  )
    	  (entmod edata)
       )
    	)
    	(princ "\n* No text entities found to proceed *")
      )
      (setvar "cmdecho" OldCmd)
      (setvar "luprec" OldLup)
      (princ)
    )
    (princ)
    This I was using from long back, so didn't use any VLisp functions. I hope our VLisp experts will popup with more efficient and compact codes...

    Regards,

    Abdul Huck

  4. #4
    Active Member
    Join Date
    2005-11
    Posts
    61
    Login to Give a bone
    1

    Default Re: AutoLISP program coverts upper to lower, or lower to upper case

    Express tools has that

Similar Threads

  1. 2013: Sheet set manager text a mix of upper case & lower case
    By nextvkin in forum AutoCAD Sheet Set Manager
    Replies: 6
    Last Post: 2018-03-27, 09:26 PM
  2. force UPPER/lower case in text
    By MikeJarosz in forum Revit Architecture - General
    Replies: 1
    Last Post: 2012-09-13, 02:35 PM
  3. Upper/Lower case text
    By djn in forum Revit Architecture - General
    Replies: 8
    Last Post: 2007-01-05, 10:40 PM
  4. Changing from UPPER case to lower case
    By IamSnave in forum AutoCAD General
    Replies: 9
    Last Post: 2005-02-09, 10:30 PM
  5. Layer names from lower to upper case
    By dqueen in forum AutoCAD Customization
    Replies: 2
    Last Post: 2004-06-23, 03:05 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
  •