TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: butzers09silverado on July 19, 2011, 01:50:36 PM

Title: tcase mleader for title case
Post by: butzers09silverado 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
Title: Re: tcase mleader for title case
Post by: CAB on July 19, 2011, 02:23:08 PM
Perhaps this will help:
http://www.theswamp.org/index.php?topic=29049.msg346098#msg346098
Title: Re: tcase mleader for title case
Post by: butzers09silverado 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.
Title: Re: tcase mleader for title case
Post by: Lee Mac 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 (http://www.theswamp.org/index.php?topic=35221.msg404519#msg404519), (ignore all the other crap that is unfortunately included with that thread).
Title: Re: tcase mleader for title case
Post by: alanjt 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.
Title: Re: tcase mleader for title case
Post by: Lee Mac 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.
Title: Re: tcase mleader for title case
Post by: alanjt 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*
Title: Re: tcase mleader for title case
Post by: Lee Mac on July 19, 2011, 02:56:50 PM
oops: *conceited*

I wasn't referring to the code that was posted.  :wink:
Title: Re: tcase mleader for title case
Post by: alanjt on July 19, 2011, 02:58:06 PM
oops: *conceited*

I wasn't referring to the code that was posted.  :wink:
suuuure  :wink:
Title: Re: tcase mleader for title case
Post by: butzers09silverado 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.
Title: Re: tcase mleader for title case
Post by: butzers09silverado 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
Title: Re: tcase mleader for title case
Post by: alanjt 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.
Title: Re: tcase mleader for title case
Post by: Lee Mac 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.
Title: Re: tcase mleader for title case
Post by: butzers09silverado 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-)
Title: Re: tcase mleader for title case
Post by: alanjt 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.
Title: Re: tcase mleader for title case
Post by: Lee Mac on July 20, 2011, 10:26:43 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-)

No sarcasm intended, it was indeed enjoyable to construct the program and satisfying to write the subfunctions to change the case of the string.

This was fun to write:
At the risk of inflating your ego anymore :wink: very nice work.

Thanks Alan, but I certainly hope I don't appear egocentric  :-(
Title: Re: tcase mleader for title case
Post by: MP on July 20, 2011, 10:41:56 AM
... I certainly hope I don't appear egocentric  :-(

Never have appeared that way to me; do keep up the awesome work.
Title: Re: tcase mleader for title case
Post by: Lee Mac on July 20, 2011, 10:45:59 AM
... I certainly hope I don't appear egocentric  :-(

Never have appeared that way to me; do keep up the awesome work.

Thanks for the reassurance Michael  :-)
Title: Re: tcase mleader for title case
Post by: butzers09silverado on July 20, 2011, 10:54:06 AM
awesome, just saying...  :kewl:
Title: Re: tcase mleader for title case
Post by: MP on July 20, 2011, 11:13:23 AM
Thanks for the reassurance Michael  :-)

you're most welcome Lee :)
Title: Re: tcase mleader for title case
Post by: alanjt on July 20, 2011, 11:35:33 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-)

No sarcasm intended, it was indeed enjoyable to construct the program and satisfying to write the subfunctions to change the case of the string.

This was fun to write:
At the risk of inflating your ego anymore :wink: very nice work.

Thanks Alan, but I certainly hope I don't appear egocentric  :-(
nah, i was just giving you a hard time from your earlier comment.