Author Topic: tcase mleader for title case  (Read 7232 times)

0 Members and 1 Guest are viewing this topic.

butzers09silverado

  • Guest
tcase mleader for title case
« on: July 19, 2011, 01:50:36 PM »
So I had this code partially fixed... but it won't change the case to a "title case", it only changes it to upper or lower.  I'd REALLY like to have tcase work on mleaders so you can pick... here's what i've got:

Code: [Select]
(defun c:demo  (/ ent mleader sset)
  (vl-load-com)
  (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
      (strcase (vla-get-textstring mleader)))); or (strcase T (vla-get-textstring mleader))
  (princ)
  )

gracias

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: tcase mleader for title case
« Reply #1 on: July 19, 2011, 02:23:08 PM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

butzers09silverado

  • Guest
Re: tcase mleader for title case
« Reply #2 on: July 19, 2011, 02:45:48 PM »
I posted in that topic, we could close this one then i guess?  thank you, want to verify it works with multi-leaders.

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: tcase mleader for title case
« Reply #3 on: July 19, 2011, 02:47:24 PM »
Another example:

Code: [Select]
(defun c:demo ( / *error* ss obj )

  (defun *error* ( msg )
    (setvar 'NOMUTT 0)
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ)
  )

  (setvar 'ERRNO 0)
  (setvar 'NOMUTT 1)
  (princ "\nSelect Multileader: ")
  (while
    (not
      (or
        (setq ss (ssget "_+.:S:E:L" '((0 . "MULTILEADER"))))
        (= 52 (getvar 'ERRNO))
      )
    )
  )
  (if
    (and ss
      (eq acmtextcontent
        (vla-get-contenttype (setq obj (vlax-ename->vla-object (ssname ss 0))))
      )
    )
    (vla-put-textstring obj (LM:TitleCase (vla-get-textstring obj)))
  )
  (setvar 'NOMUTT 0)
  (princ)
)

(defun LM:TitleCase ( s / n )
  (vl-list->string
    (mapcar
      (function
        (lambda ( x )
          (setq n (if (and (or (not n) (= 32 n)) (< 96 x 123)) (boole 2 x 32) x))
        )
      )
      (vl-string->list (strcase s t))
    )
  )
)

It uses the titlecase function I posted here, (ignore all the other crap that is unfortunately included with that thread).

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: tcase mleader for title case
« Reply #4 on: July 19, 2011, 02:49:38 PM »
(ignore all the other crap that is unfortunately included with that thread).
Damn, that's pretty conceded.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: tcase mleader for title case
« Reply #5 on: July 19, 2011, 02:52:08 PM »
(ignore all the other crap that is unfortunately included with that thread).
Damn, that's pretty conceded.

conceded?

Quote
conceded past participle, past tense of con·cede (Verb)
1. Admit that something is true or valid after first denying or resisting it.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: tcase mleader for title case
« Reply #6 on: July 19, 2011, 02:53:59 PM »
(ignore all the other crap that is unfortunately included with that thread).
Damn, that's pretty conceded.

conceded?

Quote
conceded past participle, past tense of con·cede (Verb)
1. Admit that something is true or valid after first denying or resisting it.
oops: *conceited*
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: tcase mleader for title case
« Reply #7 on: July 19, 2011, 02:56:50 PM »
oops: *conceited*

I wasn't referring to the code that was posted.  :wink:

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: tcase mleader for title case
« Reply #8 on: July 19, 2011, 02:58:06 PM »
oops: *conceited*

I wasn't referring to the code that was posted.  :wink:
suuuure  :wink:
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

butzers09silverado

  • Guest
Re: tcase mleader for title case
« Reply #9 on: July 20, 2011, 08:02:23 AM »
haters gonna hate... lol   :lmao:

We'll give-it-a-go today, I'll let ya know thanks again this could be huge.

butzers09silverado

  • Guest
Re: tcase mleader for title case
« Reply #10 on: July 20, 2011, 08:16:08 AM »
tested
it works, AWESOME

just wondering what it would take to get the options in a command line to pick what case we want or some quick direction on how to modify that so i have separate lisp files for:
title
sentence
upper
lower

thoughts?  thanks

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: tcase mleader for title case
« Reply #11 on: July 20, 2011, 09:09:43 AM »
Copyright won't allow me to post, but with little effort I was able to hack a mod into the Express Tool: TCASE to work with MLeaders.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: tcase mleader for title case
« Reply #12 on: July 20, 2011, 09:35:52 AM »
This was fun to write:

Code: [Select]
(defun c:tcase2 ( / acsel func name ) ;; © Lee Mac 2011
  (if
    (ssget "_:L"
     '(
        (-4 . "<OR")
          (0 . "ARCALIGNEDTEXT,ATTDEF,*TEXT")
          (-4 . "<AND")
            (0 . "INSERT")
            (66 . 1)
          (-4 . "AND>")
          (-4 . "<AND")
            (0 . "*DIMENSION")
            (1 . "*?*")
          (-4 . "AND>")
          (-4 . "<AND")
            (0 . "MULTILEADER")
            (304 . "~LEADER_LINE{")
          (-4 . "AND>")
        (-4 . "OR>")
      )
    )       
    (progn
      (initget "Sentence Lower Upper Title toGgle")
      (setq func
        (eval
          (cdr
            (assoc
              (setq case
                (cond
                  (
                    (getkword
                      (strcat "\nSpecify Case [Sentence/Lower/Upper/Title/toGgle] <"
                        (setq case (cond ( case ) ( "Upper" ))) ">: "
                      )
                    )
                  )
                  ( case )
                )
              )
             '(
                ("Upper" . strcase)
                ("Lower" . (lambda ( x ) (strcase x t)))
                ("Title" . EE:TitleCase)
                ("Sentence" . LM:SentenceCase)
                ("toGgle" . LM:ToggleCase)
              )
            )
          )
        )
      )
      (vlax-for obj
        (setq acsel
          (vla-get-activeselectionset
            (vla-get-activedocument (vlax-get-acad-object))
          )
        )
        (cond
          ( (wcmatch (setq name (vla-get-objectname obj)) "AcDb*Dimension")
            (vla-put-textoverride obj (func (vla-get-textoverride obj)))
          )
          ( (or (eq "RText" name)(eq "AcDbArcAlignedText" name))
            (vlax-put-property obj 'contents (func (vlax-get-property obj 'contents)))
          )
          ( (eq "AcDbMLeader" name)
            (if (eq acmtextcontent (vla-get-contenttype obj))
              (vla-put-textstring obj (func (vla-get-textstring obj)))
            )
          )
          ( (eq "AcDbBlockReference" name)
            (foreach att (vlax-invoke obj 'getattributes)
              (vla-put-textstring att (func (vla-get-textstring att)))
            )
          )
          ( t
            (vla-put-textstring obj (func (vla-get-textstring obj)))
          )
        )
      )
      (vla-delete acsel)
    )
  )
  (princ)
)

(defun EE:TitleCase ( s ) ;; ElpanovEvgeniy
  (vl-list->string
    (mapcar
      (function
        (lambda ( a b c ) (if (= 32 a) b c))
      )
      (cons 32 (vl-string->list s))
      (vl-string->list (strcase s))
      (vl-string->list (strcase s t))
    )
  )
)

(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))
    )
  )
)

(defun LM:ToggleCase ( s )
  (vl-list->string
    (mapcar
      (function
        (lambda ( a b c ) (if (< 96 a 123) b c))
      )
      (vl-string->list s)
      (vl-string->list (strcase s))
      (vl-string->list (strcase s t))
    )
  )
)

(vl-load-com) (princ)

Note that it won't work with formatted MText however.
« Last Edit: July 20, 2011, 09:40:45 AM by Lee Mac »

butzers09silverado

  • Guest
Re: tcase mleader for title case
« Reply #13 on: July 20, 2011, 10:06:53 AM »
by fun do you mean "fun" sarcastically or was it really fun?  lisping is not fun for me because I can't write it... it's fun to try and figure out though..   8-)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: tcase mleader for title case
« Reply #14 on: July 20, 2011, 10:18:39 AM »
This was fun to write:

At the risk of inflating your ego anymore :wink: very nice work.



Note that it won't work with formatted MText however.
TCase doesn't handle all the new formatting very well.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox