Jump to content

Enclose the Text, the Text in brackets ( ), [ ], { }...


Nikon

Recommended Posts

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 by Nikon
Link to comment
Share on other sites

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 by Isaac26a
  • Like 1
Link to comment
Share on other sites

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?

Мtext fragment.png

 

text fragment.png

Edited by Nikon
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

image.png.30e3c008c195a719b16b14a9af59fb0b.png

Edited by Nikon
Link to comment
Share on other sites


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 by Nikon
Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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"

 

  • Thanks 1
Link to comment
Share on other sites

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 "\"" )

 

 

  • Thanks 1
Link to comment
Share on other sites

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

image.png.e8887de7e2c0aa98bbcac25e771ffa1a.png

ent3.lsp

Edited by Nikon
Link to comment
Share on other sites

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

 

 

  • Thanks 1
Link to comment
Share on other sites

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 by Nikon
Link to comment
Share on other sites

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

  • Thanks 1
Link to comment
Share on other sites

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 by Nikon
Link to comment
Share on other sites

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"}")))

 

 

  • Thanks 1
Link to comment
Share on other sites

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

 

image.png.f35c71fa98ecd7bab1d81bfc6b1f83db.png

 

Ok use (ascii (getstring)) to find the ascii character code, 92=\ an odd one is {=123 and }=125, 124 is something else.

Edited by BIGAL
  • Thanks 1
Link to comment
Share on other sites

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 by Nikon
Link to comment
Share on other sites

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 "]")))
....
)

 

  • Thanks 1
Link to comment
Share on other sites

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 by Isaac26a
  • Like 1
Link to comment
Share on other sites

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