Jump to content

Uppercase in AutoLisp


Kokhanetz

Recommended Posts

Hi all,

 

Im new here, and i was already very interested in scripting with AutoLisp.

Yesterday i had my course for the basic commands. New im pioneering to get my first script so i hope someone can help me out.

The bolded line in the next script i have added to the already working script:

 

(defun c:xrde ( / ss strlay)
    (setvar "CMDECHO" 0)
    (setq strlay (ssget "_X" '((0 . "*TEXT")(8 . "B-??-??-TOPOGRAFIE-T18"))))
    (setq ss (ssget "_X" (list (cons 0 "HATCH")(cons 8 "~*WATER*-V"))))
    (command "erase" ss "")
    (COMMAND "_saveas" "" "~")
    (setvar "CMDECHO" 1)
    (princ "\nDone")
(princ)     
)
 

i have tested the code (setq strlay (ssget "_X" '((0 . "*TEXT")(8 . "B-??-??-TOPOGRAFIE-T18")))) and it will catch all text with the specified layer.

Now i found a code it will set one text in uppercase:

 

(defun C:TC (/ ss i objTxt)
  (if (setq ss (ssget (list (cons 0 "TEXT,MTEXT"))))
    (progn
      (setq i 0)
      (repeat (sslength ss)
    (setq objTxt (vlax-ename->vla-object (ssname ss i)))
    (vla-put-textstring objTxt
                (strcase (vla-get-textstring objTxt))
    )
    (setq i (1+ i))
      )
      (prompt "\nDone.")
    )
  )
  (princ)
)
 

Is there anyway i can combine these codes so it will grab all text (from strlay) with B-??-??-TOPOGRAFIE-T18 and puts it in uppercase?

Hope someone can help me out with this.

 

Greetz Wouter

 

 

 

Link to comment
Share on other sites

  • Kokhanetz changed the title to Uppercase in AutoLisp

zoiets? (untested)

 

(defun c:xrde2 ( / old-cmdecho strlay i objTxt ss) (vl-load-com)
  (setq old-cmdecho (getvar 'cmdecho)) (setvar "CMDECHO" 0)
  (if (setq strlay (ssget "_X" '((0 . "*TEXT") (8 . "B-??-??-TOPOGRAFIE-T18"))))
    (progn
      (setq i 0)
      (repeat (sslength strlay)
        (setq objTxt (vlax-ename->vla-object (ssname strlay i)))
        (vla-put-textstring objTxt (strcase (vla-get-textstring objTxt)))
        (setq i (1+ i))
      )
      (princ (strcat "\nUpdated " (itoa (sslength strlay)) " (m)text objects"))
    )
    (princ "\nSorry, no (m)text on layer B-??-??-TOPOGRAFIE-T18")
  )
  (if (setq ss (ssget "_X" (list (cons 0 "HATCH")(cons 8 "~*WATER*-V"))))
    (command "erase" ss ""))
  (command "_saveas" "" "~")
  (setvar 'cmdecho old-cmdecho)
  (princ "\nDoei")
  (princ)     
)

 

🐉

Edited by rlx
Link to comment
Share on other sites

Welcome. While using comman in lisp is convent I find its where the issues arise in the code so i try not to use it when i can. and since your using visual lisp to change the txt why not try an use it everywhere! Also I like to use foreach instead of the counting method. (setq i (1+ i)) nothing wrong with that tho.

 

(defun c:xrde2 (/ doc strlay objtxt ss ent)
  (vl-load-com)
  (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
  (if (setq strlay (ssget "_X" '((0 . "*TEXT") (8 . "B-??-??-TOPOGRAFIE-T18"))))
    (progn
      (foreach objtxt (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex strlay))))
        (vla-put-textstring objTxt (strcase (vla-get-textstring objTxt)))
      )
      (princ (strcat "\nCapatlized " (itoa (sslength strlay)) " text Stings"))
    )
    (princ "\nSorry, no Text Found")
  )
  (if (setq ss (ssget "_X" '((0 . "HATCH") (8 . "~*WATER*-V"))))
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
      (entdel ent)
    )
  )
  (vla-save doc)
  (vla-EndUndoMark doc)  
  (princ "\nDoei")
  (princ)
)

 

  • Agree 1
Link to comment
Share on other sites

I agree with mhupp to minimize the use of command functions , just wanted to stay as close to the original coding as possible because OP is making first steps on the road to eternal lisp glory and didn't want to overload or scare OP away 😁

  • Funny 1
Link to comment
Share on other sites

Thanks mhupp / rlx,

 

It worked properly!

 

Command: XRDE
Capatlized 148 text Stings
Done

 

I need to be honest that i dont know nothing about visual lisp. Im glad for now i just managed to make some scripts with the common lisp.

Thanks again for helping out

Edited by Kokhanetz
Link to comment
Share on other sites

On 3/31/2023 at 2:57 AM, mhupp said:
(vla-save doc)

 

i changed that line to:

 

(vla-saveas doc (getfiled "Save As" "" "dwg" 1))

 

otherwhise it will autosave instead of asking the user for save as.

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...