Nikon Posted February 3 Posted February 3 (edited) There is a lisp by the author Oliver_88 "Enclose the Text, MText in round brackets". ;; Enclose the Text, MText in (round brackets) ;; https://forum.dwg.ru/showthread.php?t=72403 ;; author Oliver_88 08.09.2011 (defun test (/ ssl active_document) (vl-load-com) (setq active_document (vla-get-activedocument (vlax-get-acad-object))) (setq ssl (vla-get-ActiveSelectionSet active_document)) (vla-Clear ssl) (vla-SelectOnScreen ssl (vlax-safearray-fill (vlax-make-safearray vlax-vbInteger '(0 . 0) ) '(0) ) (vlax-safearray-fill (vlax-make-safearray vlax-vbVariant '(0 . 0) ) '("TEXT,MTEXT") ) ) (vlax-map-collection ssl (function (lambda (x) (bes-put-vla-object-property x "TextString" (strcat "(" (bes-get-vla-object-property x "TextString") ")" ) ) ) ) ) ) (defun bes-put-vla-object-property (obj property_name property / prop) (if (not (vl-catch-all-error-p (vl-catch-all-apply 'eval (list (list (read (strcat "vla-put-" property_name) ) obj property ) ) ) ) ) property nil ) ) (defun bes-get-vla-object-property (obj property_name / prop) (if (equal nil (vl-catch-all-error-p (setq prop (vl-catch-all-apply 'eval (list (list (read (strcat "vla-get-" property_name) ) obj ) ) ) ) ) ) prop nil ) ) By analogy with this code, you can create different variants: (round brackets) [square brackets] {curly brackets} /forward slash/ \backslash\ |vertical slash| «french quotes» "computer quotes" brackets_quotes.zip Edited February 3 by Nikon Quote
Isaac26a Posted February 3 Posted February 3 (edited) At first I didn't see that you had your lisps posted, so I made this version of mine, with most of it plain lisp ;;; Enclose Texts with Round(), Square[], Curly{}, sTraight||, Forward//, Backward\\ ;;; Isaac A 20240203 (vl-load-com) (defun c:ent (/ a b c d dw e f g o oe) (setq oe (getvar 'cmdecho) o (getvar 'osmode) ) (setvar 'cmdecho 0) (vla-startundomark (setq dw (vla-get-activedocument (vlax-get-acad-object)))) (setvar 'osmode 0) (princ "\nSelect the texts.") (if (setq a (ssget (list (cons 0 "TEXT,MTEXT")))) (progn (initget "Round Square Curly sTraight Forward Backward") (setq b 0 c (sslength a) d (getkword "Round(), Square[], Curly{}, sTraight||, Forward//, Backward\\\\ <R>: ") ) (while (< b c) (setq e (entget (ssname a b)) f (cdr (setq g (assoc 1 e))) ) (cond ((= d "Round") (setq f (strcat "("f")"))) ((= d "Square") (setq f (strcat "["f"]"))) ((= d "Curly") (setq f (strcat "{"f"}"))) ((= d "sTraight") (setq f (strcat "|"f"|"))) ((= d "Forward") (setq f (strcat "/"f"/"))) ((= d "Backward") (setq f (strcat "\\"f"\\"))) (T (setq f (strcat "("f")"))) ) (setq e (subst (cons 1 f) g e)) (entmod e) (setq b (1+ b)) ) ) (princ "\nNo texts selected") ) (setvar 'cmdecho oe) (setvar 'osmode o) (vla-endundomark dw) (princ) ) Edited February 3 by Isaac26a 1 Quote
Nikon Posted February 3 Author Posted February 3 (edited) 1 hour ago, Isaac26a said: ;;; Enclose Texts with Round(), Square[], Curly{}, sTraight||, Forward//, Backward\\ ;;; Isaac A 20240203 This lisp is much more convenient, but {curly brackets} work a little incorrectly... If you select text and mtext , only text is taken in curly brackets... Is it possible to do so, to make the letters of the bracket type selection highlighted, so that you can point them out? Round(), Square[], Curly{}, sTraight||, Forward//, Backward\\ <R>: Is it possible to enclose a text fragment in brackets? Edited February 3 by Nikon Quote
Isaac26a Posted February 3 Posted February 3 Yes, as I see the curly {} brackets won't work on mtexts, because It is used as a control character to define specific types of texts. So far I don't know how to fix this, probably someone else can jump in and help with this. And to the other question, to work as a transparent command, I don't know how this could be possible. At the moment I would solve it like a find and replace text problem, but then you could solve it with the find command or keep typing it manually Quote
Nikon Posted February 3 Author Posted February 3 (edited) 10 minutes ago, Isaac26a said: Yes, as I see the curly {} brackets won't work on mtexts Interestingly, after the command, curly brackets are not visible in mtext, but are displayed in the properties... Edited February 3 by Nikon Quote
Nikon Posted February 4 Author Posted February 4 (edited) I add strings for fr quotes«» to Isaac26a's code, it works. ;;; Enclose Texts with Round(), Square[], Curly{}, sTraight||, Forward//, Backward\\, frQuotes«» ;;; Isaac A 20240203 (vl-load-com) (defun c:ent1 (/ a b c d dw e f g o oe) (setq oe (getvar 'cmdecho) o (getvar 'osmode) ) (setvar 'cmdecho 0) (vla-startundomark (setq dw (vla-get-activedocument (vlax-get-acad-object)))) (setvar 'osmode 0) (princ "\nSelect the texts.") (if (setq a (ssget (list (cons 0 "TEXT,MTEXT")))) (progn (initget "Round Square Curly sTraight Forward Backward frQuotes") (setq b 0 c (sslength a) d (getkword "Round(), Square[], Curly{}, sTraight||, Forward//, Backward\\\\, frQuotes«» <R>: ") ) (while (< b c) (setq e (entget (ssname a b)) f (cdr (setq g (assoc 1 e))) ) (cond ((= d "Round") (setq f (strcat "("f")"))) ((= d "Square") (setq f (strcat "["f"]"))) ((= d "Curly") (setq f (strcat "{"f"}"))) ((= d "sTraight") (setq f (strcat "|"f"|"))) ((= d "Forward") (setq f (strcat "/"f"/"))) ((= d "Backward") (setq f (strcat "\\"f"\\"))) ((= d "frQuotes") (setq f (strcat "«"f"»"))) (T (setq f (strcat "("f")"))) ) (setq e (subst (cons 1 f) g e)) (entmod e) (setq b (1+ b)) ) ) (princ "\nNo texts selected") ) (setvar 'cmdecho oe) (setvar 'osmode o) (vla-endundomark dw) (princ) ) But if you add ((= d "coMpquotes") (setq f (strcat """f"""))) ; error: too many arguments Apparently the program doesn't understand a lot of quotes in quotes """f""" Edited February 4 by Nikon Quote
Nikon Posted February 4 Author Posted February 4 I suggest using numbers instead of letters to select the type of brackets. (initget "Round 1Square 2Curly 3Straight 4Forward 5Backward 6Frquotes") IMHO, this is especially convenient for localized versions of AutoCAD. There is no need to switch to the English keyboard layout... ;;; Enclose Texts with Round(), 1Square[], 2Curly{}, 3Straight||, 4Forward//, 5Backward\\, 6Frquotes«» ;;; Isaac A 20240203 (vl-load-com) (defun c:ent2 (/ a b c d dw e f g o oe) (setq oe (getvar 'cmdecho) o (getvar 'osmode) ) (setvar 'cmdecho 0) (vla-startundomark (setq dw (vla-get-activedocument (vlax-get-acad-object)))) (setvar 'osmode 0) (princ "\nSelect the texts.") (if (setq a (ssget (list (cons 0 "TEXT,MTEXT")))) (progn (initget "Round 1Square 2Curly 3Straight 4Forward 5Backward 6Frquotes") (setq b 0 c (sslength a) d (getkword "Round(), 1Square[], 2Curly{}, 3Straight||, 4Forward//, 5Backward\\\\, 6Frquotes«» <R>: ") ) (while (< b c) (setq e (entget (ssname a b)) f (cdr (setq g (assoc 1 e))) ) (cond ((= d "Round") (setq f (strcat "("f")"))) ((= d "1Square") (setq f (strcat "["f"]"))) ((= d "2Curly") (setq f (strcat "{"f"}"))) ((= d "3Straight") (setq f (strcat "|"f"|"))) ((= d "4Forward") (setq f (strcat "/"f"/"))) ((= d "5Backward") (setq f (strcat "\\"f"\\"))) ((= d "6Frquotes") (setq f (strcat "«"f"»"))) (T (setq f (strcat "("f")"))) ) (setq e (subst (cons 1 f) g e)) (entmod e) (setq b (1+ b)) ) ) (princ "\nNo texts selected") ) (setvar 'cmdecho oe) (setvar 'osmode o) (vla-endundomark dw) (princ) ) Quote
Steven P Posted February 4 Posted February 4 Curley brackets, have you looked at how they are? So create an mtext, type in some text and then use (assoc 1 (entget(car(entsel)))) to show how that text string is and that is what you should use/ For example, might be something like this: (1 . "123 \\{ asd \\} 456") (on the screen this displays are "123 { asd } 456" 1 Quote
Steven P Posted February 4 Posted February 4 3 hours ago, Nikon said: But if you add ((= d "coMpquotes") (setq f (strcat """f"""))) ; error: too many arguments Apparently the program doesn't understand a lot of quotes in quotes """f""" (strcat """f""") is read as@ (strcat "[open quote] "[close quote] "[open quote] f "[close quote] "[open quote] "[close quote]) - that is you are trying to join 3 text strings and 'f' is between quotes, so will be just the character f. " is a special character to define as here, the end of a text, but to use it as a part of the text you need to add a \ in front to tell CAD to use " as a letter (strcat "\"" f "\"" ) 1 Quote
Nikon Posted February 4 Author Posted February 4 (edited) 2 hours ago, Steven P said: (strcat "\"" f "\"" ) @Steven P Thanks. The code works correctly with this string. Is it possible to enclose a text fragment in brackets? That is, go to the text editor, select a fragment, enclose it in brackets... ent3.lsp Edited February 4 by Nikon Quote
Steven P Posted February 4 Posted February 4 I'm not sure you can do that in a text editor, though you could edit the text, copy the selection to clipboard and use that snip of text as part of a find-replace type of function, with maybe (vl-string-subst new-str pattern str ). I think I know what you are meaning, not sure if it would be possible with DCL, create a pop-up box with the text string in a text box, highlight the selection required and click OK - something like that. Could use something like BigAls multi get vals to chose the bracket type in the same box.... but I am not sure how you would do the selecting text bit working 1 Quote
BIGAL Posted February 4 Posted February 4 I thought I posted this yesterday Use (chr but imply by using "\" for next character. (vlax-put obj 'Textstring (strcat (chr 92) (chr 123) "ABCDEFG" (chr 92) (chr 125))) My version of initget. Multi radio buttons.lsp 1 Quote
Nikon Posted February 5 Author Posted February 5 (edited) Curly brackets {} do not work with mtext. Curly brackets are not visible in mtext, but are displayed in the properties... Curly brackets are displayed for text only. If so (strcat "\\{"f"\\}"))), then {MText MText MText} and \{Text Text\} That is, for the text you need (strcat "{"f"}"))), but for the mtext (strcat "\\{"f"\\}"))... How can this be fixed? (strcat "\{"f"\}"))=(strcat "{"f"}"))) they work the same way... {Text Text} MText MText MText Edited February 5 by Nikon Quote
Steven P Posted February 5 Posted February 5 Nearly there, in the (setq f (strcat ...... ) line for { }, put in an if statement: ( if mtext (setq f (strcat "//{"... (setq f (strcat "{"... ) you'll have to look at the syntax for the if statement perhaps using the entity DFX codes and assoc value 0 1 Quote
Nikon Posted February 5 Author Posted February 5 (edited) 2 hours ago, Steven P said: ( if mtext (setq f (strcat "//{"... (setq f (strcat "{"... ) I'm trying: ((= d "2Curly") (progn (if mtext (setq f (strcat "\\{"f"\\}")))) (if text(setq f (strcat "{"f"}")))) or ((= d "2Curly") (if mtext (setq f (strcat "\\{"f"\\}"))) (setq f (strcat "{"f"}"))) The brackets do not appear... Edited February 5 by Nikon Quote
Steven P Posted February 5 Posted February 5 You'll need change 'mtext' in that to something else in my example it was just to show where to test for it. Perhaps add in: (setq mtext (cdr (assoc 0 e))) ) somewhere and in your new if statement ((= d "2Curly") (if (= mtext "MTEXT") (setq f (strcat "\\{"f"\\}"))) (setq f (strcat "{"f"}"))) 1 Quote
BIGAL Posted February 6 Posted February 6 (edited) Nikon look at my example. yes need to (vlax-get obj 'Textstring) (setq obj (vlax-ename->vla-object (car (entsel "Pick mtext ")))) (setq txt (vlax-get obj 'textstring)) (vlax-put obj 'Textstring (strcat (chr 92) (chr 123) txt (chr 92) (chr 125))) Ok use (ascii (getstring)) to find the ascii character code, 92=\ an odd one is {=123 and }=125, 124 is something else. Edited February 6 by BIGAL 1 Quote
Nikon Posted February 6 Author Posted February 6 (edited) 8 hours ago, BIGAL said: (vlax-put obj 'Textstring (strcat (chr 92) (chr 123) txt (chr 92) (chr 125))) this can be added separately for MText ;; Enclose the MText in {curly brackets} ASCII encoded code 123-125 (defun C:curlyBrckMText (/ ssl active_document) (vl-load-com) (setq active_document (vla-get-activedocument (vlax-get-acad-object))) (setq ssl (vla-get-ActiveSelectionSet active_document)) (vla-Clear ssl) (vla-SelectOnScreen ssl (vlax-safearray-fill (vlax-make-safearray vlax-vbInteger '(0 . 0) ) '(0) ) (vlax-safearray-fill (vlax-make-safearray vlax-vbVariant '(0 . 0) ) '("MTEXT") ) ) (vlax-map-collection ssl (function (lambda (x) (bes-put-vla-object-property x "TextString" (strcat (chr 92) (chr 123) (bes-get-vla-object-property x "TextString") (chr 92) (chr 125)) ) ) ) ) ) (defun bes-put-vla-object-property (obj property_name property / prop) (if (not (vl-catch-all-error-p (vl-catch-all-apply 'eval (list (list (read (strcat "vla-put-" property_name) ) obj property ) ) ) ) ) property nil ) ) (defun bes-get-vla-object-property (obj property_name / prop) (if (equal nil (vl-catch-all-error-p (setq prop (vl-catch-all-apply 'eval (list (list (read (strcat "vla-get-" property_name) ) obj ) ) ) ) ) ) prop nil ) ) {MText MText MText} But you won't be able to add it to @Isaac26a code, where there is a choice of the type of brackets. Edited February 6 by Nikon Quote
BIGAL Posted February 6 Posted February 6 Nikon have a look at the dcl I made using Multi Radio Buttons.lsp, when you select a button, the variable BUT is returned with the button number, so you can use a cond looking at the BUT value, for the {} just need a (cond ((= but 1)(setq str (strcat (chr 92) (chr 123)) txt (strcat (chr 92) (chr 125))))) ((= but 2)(setq str (strcat "[" txt "]"))) .... ) 1 Quote
Isaac26a Posted February 9 Posted February 9 (edited) Sorry about missing all the posts, but here it is the final version ;;; Enclose Texts with Round(), Square[], Curly{}, sTraight||, Forward//, Backward\\ ;;; Isaac A 20240208 (vl-load-com) (defun c:ent (/ a b c d dw e f g o oe) (setq oe (getvar 'cmdecho) o (getvar 'osmode) ) (setvar 'cmdecho 0) (vla-startundomark (setq dw (vla-get-activedocument (vlax-get-acad-object)))) (setvar 'osmode 0) (princ "\nSelect the texts.") (if (setq a (ssget (list (cons 0 "TEXT,MTEXT")))) (progn (initget "Round Square Curly sTraight Forward Backward frQuotes") (setq b 0 c (sslength a) d (getkword "Round(), Square[], Curly{}, sTraight||, Forward//, Backward\\\\, frQuotes«» <R>: ") ) (while (< b c) (setq e (entget (ssname a b)) f (cdr (setq g (assoc 1 e))) ) (cond ((= d "Round") (setq f (strcat "("f")"))) ((= d "Square") (setq f (strcat "["f"]"))) ((= d "Curly") (if (= (cdr (assoc 0 e)) "TEXT") (setq f (strcat "{"f"}")) (setq f (strcat "\\{"f"\\}")) ) ) ((= d "sTraight") (setq f (strcat "|"f"|"))) ((= d "Forward") (setq f (strcat "/"f"/"))) ((= d "Backward") (setq f (strcat "\\"f"\\"))) ((= d "frQuotes") (setq f (strcat "«"f"»"))) (T (setq f (strcat "("f")"))) ) (setq e (subst (cons 1 f) g e)) (entmod e) (setq b (1+ b)) ) ) (princ "\nNo texts selected") ) (setvar 'cmdecho oe) (setvar 'osmode o) (vla-endundomark dw) (princ) ) But you can Modify it with numbers @Nikon because the cyrillic alphabet is different Also @BIGAL Nice way of using your Multi Radio Buttons.lsp, I'll follow the example to include DCL code in my lisps, or is there an easier way?, maybe not, I'll let you know how it goes. Edited February 9 by Isaac26a 1 Quote
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.