Jump to content

Recommended Posts

Posted

Hi All,

I wrote this routine to change the text string of all MLeaders in the drawing to Caps. I dont know hat is wrong, however, it doesn't happen...

 

(defun c:caps( / ss Count n LeaderObj dxf txtstr newtxt newdxf)
 (setq ss (ssget "_X" '((0 . "MULTILEADER"))))
 (setq Count (sslength ss))
 (setq n 0)
 (repeat Count
   (setq LeaderObj (ssname ss n))
   (setq dxf (entget LeaderObj))
   (setq txtstr (cdr (assoc 304 dxf)))
   (setq newtxt (strcase txtstr))
   (setq newdxf (subst (cons 304 newtxt) (assoc 304 dxf) dxf))
   (prompt (strcat "\nOld Text : " txtstr))
   (prompt (strcat "\nNew Text : " newtxt))
   (prompt "\n=============")
   (entmod newdxf)

   (setq n (1+ n))
 )
 (prompt (strcat "\nUpdated " (itoa Count) " Multileaders..."))
)

Posted

Things like this .... ? 8)

 

(defun c:TesT (/ selectionset) (vl-load-com)
 ;;; Tharwat 13. Dec. 2011 ;;;
 (if (ssget "_x" '((0 . "MULTILEADER")))
   (vlax-for mleader (setq selectionset (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
     (vla-put-textstring mleader (strcase (vla-get-textstring mleader)))
   )
   (princ)
 )
 (vla-delete selectionset)
 (princ)
)

Posted

Wow...!!! That worked...!!! Thanks a lot...!!!

Posted
(defun c:TesT (/ selectionset) (vl-load-com)
 ;;; Tharwat 13. Dec. 2011 ;;;
 (if (ssget "_x" '((0 . "MULTILEADER")))
   (vlax-for mleader (setq selectionset (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
     (vla-put-textstring mleader (strcase (vla-get-textstring mleader)))
   )
   (princ)
 )
 (vla-delete selectionset)
 (princ)
)

 

What if there are no MLeaders in the drawing... ?

Posted
What if there are no MLeaders in the drawing... ?

 

It means that we should add progn function to obtain vla-delete function within :D

 

Thanks

Posted

To answer the OP's original question:

 

I wrote this routine to change the text string of all MLeaders in the drawing to Caps. I dont know hat is wrong, however, it doesn't happen...

 

Apart from the check for a valid SelectionSet, I don't see too much wrong with your code harilalmn, indeed, it works as expected for me :thumbsup:

 

I might rewrite the code in the following way:

 

(defun c:caps ( / en i ss tx )
   (if (setq ss (ssget "_X" '((0 . "MULTILEADER"))))
       (repeat (setq i (sslength ss))
           (setq en (entget (ssname ss (setq i (1- i))))
                 tx (assoc 304 en)
           )
           (entmod (subst (cons 304 (strcase (cdr tx))) tx en))
       )
   )
   (princ)
)

  • 2 years later...
Posted

Hi all,

 

I was wondering if its possible to get Sentence case if possible for multi-leaders. Lee I've seen your code for changing text strings to that but I'm at a lost end in trying to implementing it.

 

Thanks.

Posted
I was wondering if its possible to get Sentence case if possible for multi-leaders. Lee I've seen your code for changing text strings to that but I'm at a lost end in trying to implementing it.

 

Use my Text Case functions, and simply substitute a call to LM:SentenceCase for strcase in the above code:

 

(defun c:caps ( / en i ss tx )
   (if (setq ss (ssget "_X" '((0 . "MULTILEADER"))))
       (repeat (setq i (sslength ss))
           (setq en (entget (ssname ss (setq i (1- i))))
                 tx (assoc 304 en)
           )
           (entmod (subst (cons 304 ([color=red]LM:SentenceCase[/color] (cdr tx))) tx en))
       )
   )
   (princ)
)

Posted
Use my Text Case functions, and simply substitute a call to LM:SentenceCase for strcase in the above code:

 

(defun c:caps ( / en i ss tx )
   (if (setq ss (ssget "_X" '((0 . "MULTILEADER"))))
       (repeat (setq i (sslength ss))
           (setq en (entget (ssname ss (setq i (1- i))))
                 tx (assoc 304 en)
           )
           (entmod (subst (cons 304 ([color=red]LM:SentenceCase[/color] (cdr tx))) tx en))
       )
   )
   (princ)
)

Terrific Lee, Thank you AGAIN.

 

Code for anyone who has trouble or lazy :)

 

(defun c:tcase_leader_Sentence ( / en i ss tx )

;; Sentence Case - Lee Mac
;; Returns the supplied string converted to Sentence Case
(defun LM:SentenceCase ( s / f )
   (vl-list->string
       (mapcar
           (function
               (lambda ( a b c )
                   (if (or f (= 46 a)) (progn (setq f (= 32 b)) b) c)
               )
           )
           (cons 46 (vl-string->list s))
           (vl-string->list (strcase s))
           (vl-string->list (strcase s t))
       )
   )
)

;; Orignal Code
   (if (setq ss (ssget "_X" '((0 . "MULTILEADER"))))
       (repeat (setq i (sslength ss))
           (setq en (entget (ssname ss (setq i (1- i))))
                 tx (assoc 304 en)
           )
           (entmod (subst (cons 304 (LM:SentenceCase (cdr tx))) tx en))
       )
   )
   (princ)
)

Posted
Terrific Lee, Thank you AGAIN.

 

You're welcome 3dwannab! :thumbsup:

Posted
You're welcome 3dwannab! :thumbsup:

Hi Lee, you may be interested to know I posted on the original location of the LISP and a user replied with the code to use the built in TcaseSup.lsp

 

(defun c:demo  (/ ent mleader sset txt)
 (vl-load-com)
 (load "TcaseSup.lsp")
 (setvar "errno" 0)
 (while (and (not sset)
      (/= (getvar "errno") 52)
      )
   (prompt "\n   >>   Select multileader >> ")
   (setq sset (ssget "+.:S:N" '((0 . "MULTILEADER"))))
   )
 (if (and sset
   (setq mleader (vlax-ename->vla-object (setq ent (ssname sset 0))))
   (eq acmtextContent (vla-get-contenttype mleader)))
   (vla-put-textstring
     mleader
     (acet-tcase-change-string (vla-get-textstring mleader) "Title")))
 (princ)
 )

(acet-tcase-change-string (vla-get-textstring mleader) "Title")))

can be changed to:

(acet-tcase-change-string (vla-get-textstring mleader) "upper")))

etc, etc.

 

For the life of me I cannot find that thread now :/

Posted

FWIW ;)

 

_$ (setq str "this is a test. ")
"this is a test. "
_$ (repeat 4 (setq str (strcat str str)))
"this is a test. this is a test. this is a test. this is a test. this is a test. this is a test. this is a test. this is a test. this is a test. this is a test. this is a test. this is a test. this is a test. this is a test. this is a test. this is a test. "
_$ (strlen str)
256
_$ (eq (acet-tcase-change-string str "Sentence") (LM:sentencecase str))
T


_$ (benchmark '((acet-tcase-change-string str "Sentence") (LM:sentencecase str)))
Benchmarking ...............Elapsed milliseconds / relative speed for 4096 iteration(s):

   (LM:SENTENCECASE STR)........................1295 / 5.49 <fastest>
   (ACET-TCASE-CHANGE-STRING STR "Sente...).....7114 / 1.00 <slowest>

Posted

Your code was never in doubt. How come people like you are not snapped up by autodesk is beyond me!

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...