Jump to content

Recommended Posts

Posted

hi all.! im new here and hoping to get answers to my query. Its about a routine on the text inside mtext. i have to edit 1 by one and its so many of the. all i want is just to click the mtext and it will change automatically. here is the routine i make:.

 

1. edit the mtext (which is a two line mtext)

2. change the style of the text.

3. Highlight the first line to make it bold.

4. Highlight the second line to make it italic.

5. exit.

 

Result should be like this:

 

First Line

Second Line

 

can this be achieved by a lisp code? thank you in advance and i hope that this can be made. God bless all.

  • Replies 42
  • Created
  • Last Reply

Top Posters In This Topic

  • LearningLisP

    19

  • Lee Mac

    13

  • irneb

    10

  • Spinxy

    1

Posted

Certainly - just not directly as your step by step. A few questions though:

 

  1. Are all the MText's containing the exact same text? I.e. do you want to copy the changes as you can do using normal DText and the Properties Palette?
  2. If not, does the 1st line always end with a Enter pressed, or does it just wrap automatically?
  3. When you say change the style (in your point 2), it seems you're doing so inside the editor. Do you 1st select all the text?
  4. If so would you rather want to change the MText's style itself - rather than the format codes inside?

With lisp you'd actually change the data of the MText instead of using the MTEdit command. The bold and italic is simply format codes of the text value.

Posted

Thanks irneb for the reply. and sorry for the late reply. to answer your questions:

 

1. Are all the MText's containing the exact same text? - No. it is a series. i.e, FIRSTLINE1, FIRSTLINE2, SECONDLINE1, SECONDLINE2,... and so on.

2. If not, does the 1st line always end with a Enter pressed, or does it just wrap automatically? - Yes. i pressed enter after the first line.

3. When you say change the style (in your point 2), it seems you're doing so inside the editor. Do you 1st select all the text? - No. after i press the mtext to edit it, i just choose the style i want and the style of the text automatically changes without selecting them all.

4. If so would you rather want to change the MText's style itself - rather than the format codes inside? No. i tried to change the MText's style but the font style did not change. only the style of the Mtext change. so i sort in doing what i ask.

 

I hope this clears you out irneb. it will be of great help to me and maybe to others. Thank you once again and god bless.

Posted

I was thinking something along these lines, but this will currently only work with TextStyles using the Arial font - I'm not sure how to set MText to bold/italic and specify the correct font string in the formatting code. I thought perhaps vla-get-fontfile, but this is only the filename of the font file.

 

(defun c:test ( / *error* ss ) (vl-load-com)
 ;; © Lee Mac 2010, www.lee-mac.com

 (defun *error* ( msg )
   (LM:ReleaseObject RegEx)
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )

 (if (setq ss (ssget "_:L" '((0 . "MTEXT") (1 . "*\\P*"))))
   (
     (lambda ( i / RegEx e ) (setq RegEx (vlax-create-object "VBScript.RegExp"))
       (while (setq e (ssname ss (setq i (1+ i))))  
         (entupd
           (cdr
             (assoc -1
               (entmod
                 (subst
                   (cons 1
                     (LM:RegExReplace RegEx "{\\fArial|b1|i0|c0|p34;$1\\P\\fArial|b0|i1|c0|p34;$2}" "^(.*)\\\\P(.*)$"
                       (cdr (assoc 1 (entget e)))
                     )
                   )
                   (assoc 1 (entget e)) (entget e)                      
                 )
               )
             )
           )
         )
       )
       (LM:ReleaseObject RegEx)
     )
     -1
   )
 )

 (princ)
)

(defun LM:RegExReplace ( regex new pat str )
 ;; © Lee Mac 2010
 (mapcar
   (function
     (lambda ( prop value ) (vlax-put-property regex prop value))
   )
  '(pattern global ignorecase) (list pat actrue acfalse)
 )
 (vlax-invoke regex 'replace str new)
)

;;------------------=={ Release Object }==--------------------;;
;;                                                            ;;
;;  Releases a VLA Object from memory via plentiful error     ;;
;;  trapping                                                  ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  obj - VLA Object to be released from memory               ;;
;;------------------------------------------------------------;;
;;  Returns:  T if Object Released, else nil                  ;;
;;------------------------------------------------------------;;

(defun LM:ReleaseObject ( obj ) (vl-load-com)
 ;; © Lee Mac 2010
 (and obj (eq 'VLA-OBJECT (type obj)) (not (vlax-object-released-p obj))
   (not
     (vl-catch-all-error-p
       (vl-catch-all-apply
         (function vlax-release-object) (list obj)
       )
     )
   )
 )
)

 

What are your thoughts Irne?

Posted

hello Lee. thanks for your reply and trying to help out. i have tested your code but nothing happens when i select an MText. maybe im lost here, sorry. anyway, i did go to your website and browse your list of lisp codes. i tried the MatchTextProp but it did not change the font style, just the Mtext style. if only it can change the font style, it would be ok.

 

Thank you guys and God bless.

Posted

Actually I'd advise NOT changing any fonts inside the MText. Due to this exact reason: You can't modify easily on multiple texts. I prefer "cleaning" such format codes using StripMText to get rid of these fonts. Then the font can be changed by selecting multiple MTexts and setting the Style in properties palette.

 

Lee, as for your code ... again just ensure you don't use any DXF code 40, 41 or 42 as these would screw up annotative text. You could use vl-remove-if to get rid of them in your entmod.

 

I see you've also made your own Regular Expression function, it might just save a lot of coding when performing this type of thing. I wish I had more knowledge of RegExp search strings. But I'm getting there, see my attached version.

RegExp.LSP

Posted (edited)

First a HUGE thanks to you irn. it must have taken some of your time writing that code. i see that it is not an ordinary lisp as i thought. thanks once again. now for the code, what shall i type to command line? i did not see defun c:. am i getting this wrong?. thanks.

 

edit:

 

i used the StripMtext and it works. i can change the style of the mtext now.

 

my question is, can i format an Mtext (with bold FIRSTLINE1 and italic SECONDLINE1) to make it as a reference and match it on to the rest of the mtexts? thanks..

Edited by LearningLisP
Posted

Sorry no, that's just some functions for use when you want to search and replace stuff in a string of text. It would be used when searching for that {\fArial|b..... format code and allowing it to be replaced. I'll have a got at it myself, but I think Lee's code has promise ... just need to figure out what to do when there's already some formatting codes inside the text.

Posted
Actually I'd advise NOT changing any fonts inside the MText. Due to this exact reason: You can't modify easily on multiple texts. I prefer "cleaning" such format codes using StripMText to get rid of these fonts. Then the font can be changed by selecting multiple MTexts and setting the Style in properties palette.

 

Ditto: IMO, avoid MText formatting codes where possible - they are a nightmare for developers to deal with.

 

Lee, as for your code ... again just ensure you don't use any DXF code 40, 41 or 42 as these would screw up annotative text. You could use vl-remove-if to get rid of them in your entmod.

 

Actually, I originally used entmod with only the entity name and string in my initial testing, however this didn't seem to work when updating formatting codes - a nice idea to use vl-remove-if: thanks for indicating the codes to remove, I wouldn't have known.

 

I see you've also made your own Regular Expression function, it might just save a lot of coding when performing this type of thing. I wish I had more knowledge of RegExp search strings. But I'm getting there, see my attached version.

 

I'll take a look over your code when I get some time - I've been using RegExp strings in my Batch Find & Replace program (can be found on my site), which I worked on with Joe Burke; although, after spending quite some time to allow for formatting codes, it still has a few bugs where heavily formatted MText is concerned. And I'll admit, I didn't account for there already being formatting codes within the string in this situation.

 

Lee

Posted
Sorry no, that's just some functions for use when you want to search and replace stuff in a string of text. It would be used when searching for that {\fArial|b..... format code and allowing it to be replaced. I'll have a got at it myself, but I think Lee's code has promise ... just need to figure out what to do when there's already some formatting codes inside the text.

 

oic. we'll have to wait for Lee's then. more power to you both.

Posted

If you just create a new Mtext object with two lines of text and no formatting, does mine produce the correct result?

Posted (edited)
If you just create a new Mtext object with two lines of text and no formatting, does mine produce the correct result?

 

IT REALLY WORKS! I was not able to use it 'cause i focused on irneb's. THANK YOU SO MUCH LEE! one thing i change to the lisp though, its the font. We use Calibri font in our drawing standards. so i replace the Areal to Calibri and it works like a charm. :)... thanks once again!

Edited by LearningLisP
Posted
IT REALLY WORKS! I was not able to use it 'cause i focused on irneb's. THANK YOU SO MUCH LEE! one thing i change to the lisp though, its the font. We use Calibri font in our drawing standards. so i replace the Areal to Calibri and it works like a charm. :)... thanks once again!

 

Excellent - good to hear mate :)

Posted

It works for the new mtext only Lee, i cant use it on the existing Mtext objects. I use StripMtext to clean the Mtext object and after i clean it, I cant select the Mtext objects. Is there something wrong Lee.? thanks.

Posted
It works for the new mtext only Lee, i cant use it on the existing Mtext objects. I use StripMtext to clean the Mtext object and after i clean it, I cant select the Mtext objects. Is there something wrong Lee.? thanks.

 

Depends how much you strip out. If you strip out the paragraph formatting, then no, you won't be able to select the Mtext as I have included a selectionset filter for only Mtext with two or more lines.

Posted

and irn, how do i use your program?

Posted (edited)
Depends how much you strip out. If you strip out the paragraph formatting, then no, you won't be able to select the Mtext as I have included a selectionset filter for only Mtext with two or more lines.

 

Still can't select an object Lee. This is what i did: I strip an Mtext then dialogbox apear. i press Select All button and then uncheck the Paragraph checkbox. press ok. but still i cant select the Mtext.

 

edit:

 

After exploring Stripmtext for some time, i finally made it to work Lee. :).. what i did above mentioned makes the mtext have only one line of text. So what i did was i uncheck all except for the Font. AND IT WORKS!.... :) thank you once again Lee for helping out..

Edited by LearningLisP
Posted

One more thing Lee, is it possible for the StripMtext to be incorporated to your code? well, i can make a button to incorporate the two command though. but it would be nice to see and type only one command. :). but i will settle for this one for now Lee. God bless and more power!

Posted

Forget my code, it's only a very small portion of the whole. As to using StripMText in Lee's code, try this (modifications in red):

[b][color=red](if (not (or StripMText (load "StripMtext v5-0b" nil)))
 (princ "\nStripMText couldn't be loaded.")
)[/color][/b]
(defun c:test ( / *error* ss ) (vl-load-com)
 ;; © Lee Mac 2010, www.lee-mac.com

[b][color=gray]  ;; Keep the error handler function as is[/color][/b]

(if (setq ss (ssget "_:L" '((0 . "MTEXT") (1 . "*\\P*"))))
[b][color=red]    (progn[/color][/b]
[b][color=red]      (if StripMText (StripMtext ss '("F")))
[/color] [/b]     (
       (lambda ( i / RegEx e ) (setq RegEx (vlax-create-object "VBScript.RegExp"))
         [color=dimgray][b];; Keep the internal of lambda as is[/b][/color]
       )
       -1
     )
[b][color=red]    )[/color][/b]
 )

 (princ)
)

Make sure the StripMText ....LSP file is saved in one of ACad's support folders - since the 1st added set of lines makes sure it's loaded, otherwise the load will fail. Also if you have a different file version name - modify the relevant "StripMtext v5-0b" to suit.

Posted

thanks for the revision irn. well do test it now...

 

edit:

 

i incorporate the code you added irn and the result.... PERFECT!!!!!!!! :)

Just the way i want it.! I'm really grateful i found this forum to meet such nice persons like you guys.. you are here to help solve problems that most of us (like me) couldn't think it will be possible.

 

THANK YOU very much for the help and God Bless you all.!

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