gmmdinesh Posted June 28, 2017 Share Posted June 28, 2017 Hi Everyone..Could anyone please tell me, how to select all red colored text and mtext from model space through lisp. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted June 28, 2017 Share Posted June 28, 2017 (sssetfirst nil (ssget "_x" '((0 . "TEXT,MTEXT") (62 . 1)))) Quote Link to comment Share on other sites More sharing options...
tmelancon Posted June 28, 2017 Share Posted June 28, 2017 (setq ss (ssget "X" '((0 . "text,mtext")(62 . 1)))) Quote Link to comment Share on other sites More sharing options...
tmelancon Posted June 28, 2017 Share Posted June 28, 2017 or (setq ss (ssget "X" (list (cons 0 "TEXT,MTEXT")(cons 62 1)))) Quote Link to comment Share on other sites More sharing options...
gmmdinesh Posted June 28, 2017 Author Share Posted June 28, 2017 Hi All, Thanks for your quick reply.. Need one more help..how can change selected text and mtext to BOLD. Quote Link to comment Share on other sites More sharing options...
tmelancon Posted June 28, 2017 Share Posted June 28, 2017 Made a quick search. Found something from Grand Master Lee Mac. Hope it helps. ;; Args:- ;; tStyle ~ Valid TextStyle Name ;; flags [bit-coded] ;; 0 ~ Regular ;; 1 ~ Bold ;; 2 ~ Italic (defun PutFontStyle (tStyle flags / TypeFace Bold Italic CharSet P&Fam) (vl-load-com) ;; Lee Mac ~ 19.02.10 (if (not (vl-catch-all-error-p (setq tStyle (vl-catch-all-apply (function vla-Item) (list (vla-get-TextStyles (vla-get-ActiveDocument (vlax-get-acad-object))) tStyle))))) (progn (vla-getFont tStyle 'TypeFace 'Bold 'Italic 'CharSet 'P&Fam) (vla-SetFont tStyle TypeFace (if (= 1 (logand 1 flags)) :vlax-true :vlax-false) (if (= 2 (logand 2 flags)) :vlax-true :vlax-false) CharSet P&Fam) t))) Example of Usage: (PutFontStyle "myStyle" 3) ; ~ Sets the font for 'MyStyle' textstyle to Bold & Italic. Quote Link to comment Share on other sites More sharing options...
gmmdinesh Posted June 28, 2017 Author Share Posted June 28, 2017 Hi tmelancon, Thanks for your effort..I have tried this one..but in this code we have to select the object as manually..i need select all red colored text and mtext and change to BOLD. Can you modify the lisp. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 29, 2017 Share Posted June 29, 2017 Do a search here for modifying mtext there is some good coding examples of finding even a single word that is red and changing its colour etc. The coding uses direct modification of the hidden code in mtext. Bold is an item that can be added. HEADING TextString = "{\\fArial|b0|i0|c0|p34;HE\\fArial|b1|i0|c0|p34;ADI\\fArial|b0|i0|c0|p34;NG}" Quote Link to comment Share on other sites More sharing options...
tmelancon Posted June 29, 2017 Share Posted June 29, 2017 Only thing I found and edited a little bit is this. I am going to keep at it. I am just trying to select all RED, MTEXT, TEXT but in VL. (defun c:mtval( / ent objmtext stroldval strnewval) (setq ent (car (entsel)) objMText (vlax-ename->vla-object ent) strOldval (vlax-get-property objMText "TEXTSTRING") strnewval (STRCAT "{\\fArial|b1|i0|c0|p34;" stroldval) ) (if strnewval (vlax-put-property objmtext "TEXTSTRING" strnewval) ) (vlax-release-object objmtext) ) Quote Link to comment Share on other sites More sharing options...
ronjonp Posted June 29, 2017 Share Posted June 29, 2017 Be careful when adding these hard coded values .. you could make a real mess if you don't check for existing: "{\\fArial|b1|i0|c0|p34;{\\fArial|b1|i0|c0|p34;{\\fArial|b1|i0|c0|p34;{\\fArial|b1|i0|c0|p34;asdfsafsdfsaff" Maybe use something like this: (strcat "{\\fArial|b1|i0|c0|p34;" (vl-string-left-trim "{\\fArial|b1|i0|c0|p34;" (vlax-get-property objmtext "TEXTSTRING") ) ) Quote Link to comment Share on other sites More sharing options...
tmelancon Posted June 29, 2017 Share Posted June 29, 2017 Wow see... perfect example of me being a beginner programmer and getting ahead of myself just because the result on the "surface" seems legit.. Thank you for that input I definitely need to discipline myself more to double-triple check everything when it comes to these routines. This code is so close to doing what the op is looking for. The problem I am having is when I edit it to Selected all MTEXT with color red I get an error "Error: bad argument type: VLA-OBJECT nil". I am sure its a crossover issue. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted June 29, 2017 Share Posted June 29, 2017 Try this .. it filters out text that is currently bold so you don't have to check in the loop (defun c:hcb (/ _ps->ss o ss) ;; Use a function like this to convert a selection set to a list of items (defun _ps->ss (ps) (if (= 'pickset (type ps)) (vl-remove-if 'listp (mapcar 'cadr (ssnamex ps))) ) ) (if (setq ss (_ps->ss (ssget ":L" '((0 . "mtext") (1 . "~{\\fArial|b1|i0|c0|p34;*"))))) (foreach mtext ss (setq o (vlax-ename->vla-object mtext)) (vla-put-textstring o (strcat "{\\fArial|b1|i0|c0|p34;" (vla-get-textstring o))) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
tmelancon Posted June 29, 2017 Share Posted June 29, 2017 Wow yea look at that. Hope you dont mind but I took your code and modified it slightly to give the OP exactly what he/she was looking for: (defun c:hcb (/ _ps->ss o ss) ;; Use a function like this to convert a selection set to a list of items (defun _ps->ss (ps) (if (= 'pickset (type ps)) (vl-remove-if 'listp (mapcar 'cadr (ssnamex ps))) ) ) (if (setq ss (_ps->ss (ssget [color=red]"X"[/color] '((0 . "mtext") (1 . "~{\\fArial|b1|i0|c0|p34;*")[color=red](62 . 1)[/color])))) (foreach mtext ss (setq o (vlax-ename->vla-object mtext)) (vla-put-textstring o (strcat "{\\fArial|b1|i0|c0|p34;" (vla-get-textstring o))) ) ) (princ) ) gmmdinesh, copy and paste this code into your main file. Run it and I think you will find it is exactly what you are looking for. Plus all the extra benefits Ron added. Hope you like. Quote Link to comment Share on other sites More sharing options...
tmelancon Posted June 30, 2017 Share Posted June 30, 2017 gmmdinesh, has this worked for you? Please post either way so anyone else viewing will know. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.