Jump to content

Lisp routine for inserting brackets around text


Recommended Posts

Posted

Hi!

 

I was hoping if anyone has a lisp routine for inserting brackets around text by clicking on the text and wrapping the text in brackets or something along those lines rather than clicking on text - and inserting brackets yourself individually.

 

I've found one for curley brackets but I can't seem to get it to work and my limited knowledge of programming, I can't change the code.

 

Cheers

Posted

(strcat "[" existingtextvariable "]")

Posted

Good idea to post what you have also pretty simple code pick 1, multiple pick pick, window etc

Posted
(defun c:brackMe (/ texts i e l)
 (if (setq
       texts (ssget "_:L"
                    '((0 . "TEXT") (-4 . "<NOT") (1 . "`[*") (-4 . "NOT>"))
             )
     )
   (repeat (setq i (sslength texts))
     (setq e (entget (ssname texts (setq i (1- i))))
           l (assoc -1 e)
     )
     (entmod (list (cons 1 (strcat "[" (cdr (assoc 1 e)) "]")) l))
   )
 )(princ)
)

Posted (edited)

here is another a quick patch of add a difference to number text

 

; Adds a fixed amount to a number
;(PRINC "\nTO USE JUST TYPE A2L or A2LM for multiple ")
(Alert "TO USE JUST TYPE A2L or A2LM for multiple ")

;(setvar "cmdecho" 1)
(setq olddimzin (getvar "Dimzin"))
(setvar "dimzin" 0)
(DEFUN c:A2L ()
;(setq v2 (getreal "\nEnter ht adjustment "))
(setq test 1)
(while (= test 1)
     (setq en1 (car (entsel "\nSelect text number:" )))
      (if (/= en1 nil)
       (progn
       (setq el1 (strcat "(" (entget en1) ")" ))
      ; (setq v1   (atof (cdr (assoc 1 el1))))
      (setq v1  (cdr (assoc 1 el1)))
;(setq a (+ v1 v2))
     ;  (setq b (rtos a 2 3))
       (setq el (subst (cons 1 v1) (assoc 1 el1) el1))
       (entmod el)
;        (entupd en1)
       );progn
      (princ "\nplease pick again"); else
    );if
); while true
(setq el nil)
(setq en nil)
(setq a nil)
(setq v1 nil)
(setvar "cmdecho" 1)
(setvar "dimzin" olddimzin)
(princ)
); END a2l DEFUN
(defun c:A2LM ()
;(setq v2 (getreal "\nEnter ht adjustment "))
(setq ss (ssget (list (cons 0 "Text"))))
(setq len (sslength ss))
(setq x 0)
(repeat len
(setq en1 (ssname ss x))
       (setq el1 (strcat "("  (entget en1) ")" ))
       ;(setq v1 (atof (cdr (assoc 1 el1))))
(setq v1 (cdr (assoc 1 el1)))       
;(setq a (+ v1 v2));
;(setq b (rtos a 2 3))
       (setq el (subst (cons 1 v1) (assoc 1 el1) el1))
       (entmod el)
(setq x (+ x 1))
); repeat
(setq el nil
     ss nil)
(setq en nil)
(setq a nil)
(setq v1 nil)

(setvar "dimzin" olddimzin)
(setvar "cmdecho" 1)
(princ)
); END a2lm DEFUN

Edited by BIGAL
Posted

Slight mod on pBe's code:

 

 

(defun c:TEst (/ ss i e d s)
 (if (setq ss (ssget "_:L" '((0 . "TEXT") (-4 . "<NOT") (1 . "`[*`]") (-4 . "NOT>"))))
   (repeat (setq i (sslength ss))
     (setq e (ssname ss (setq i (1- i)))
           d (entget e)
           s (cdr (assoc 1 d))
     )
     (entmod (list (cons 1
                         (cond ((and (wcmatch s "`[*") (not (wcmatch s "*`]"))) (strcat s "]"))
                               ((and (not (wcmatch s "`[*")) (wcmatch s "*`]")) (strcat "[" s))
                               ((strcat "[" s "]"))
                         )
                   )
                   (cons -1 e)
             )
     )
   )
 )
 (princ)
)

Posted
here is another a quick patch of add a difference to number text

 

Whats adding a diffrence to a number got to do with this Bigal?

Did i miss-read the thread title? or is this a PM thing? :lol:

Posted
Slight mod on pBe's code:

 

Nice addition Alanjt :thumbsup:

Posted

Another alternative:

([color=BLUE]defun[/color] c:test ( [color=BLUE]/[/color] i e s x )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] s ([color=BLUE]ssget[/color] [color=MAROON]"_:L"[/color] '((0 . [color=MAROON]"TEXT"[/color]) (1 . [color=MAROON]"~`[*`]"[/color]))))
       ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] i ([color=BLUE]sslength[/color] s))
           ([color=BLUE]setq[/color] e ([color=BLUE]entget[/color] ([color=BLUE]ssname[/color] s ([color=BLUE]setq[/color] i ([color=BLUE]1-[/color] i))))
                 x ([color=BLUE]assoc[/color] 1 e)
           )
           ([color=BLUE]entmod[/color] ([color=BLUE]subst[/color] ([color=BLUE]cons[/color] 1 ([color=BLUE]strcat[/color] [color=MAROON]"["[/color] ([color=BLUE]vl-string-trim[/color] [color=MAROON]"[]"[/color] ([color=BLUE]cdr[/color] x)) [color=MAROON]"]"[/color])) x e))
       )
   )
   ([color=BLUE]princ[/color])
)

Posted
Another alternative:

 

Even better. I completely forgot about vl-string-trim.

Posted
Another alternative:

(setq s (ssget "_:L" '((0 . "TEXT") (1 .[color="blue"][b] "~[/b][/color]`[*`]"))))
..... )

 

Bummer, I totally forgotten all about that switch. :)

 

Even better. I completely forgot about vl-string-trim.

 

Same here dude

Posted
Bummer, I totally forgotten all about that switch. :)

 

 

It's definitely useful when only checking against one string.

Posted

Worked really well, Thanks heaps!!

Posted

For anyone code changed shouldn't drink scotch and post code at same time.

Posted
:beer:
For anyone code changed shouldn't drink scotch and post code at same time.
Good tip! I'll keep that in mind. :beer:But I can do that sort of thing without any outside help!:lol:
Posted
For anyone code changed shouldn't drink scotch and post code at same time.

 

That explains a lot Bigal :lol:

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