Jump to content

Recommended Posts

Posted

Hey guys I found this LISP routine that allows me to change text in a drawing to anything I specify. Works great, however. My question is how do I code in here so the text updates dynamically as I click on them, instead of dashing them and waiting for user to hit enter for the changes to appear.

 

(defun c:req ( / v1 v2 v3 newtx nme oldtx)
(setvar "cmdecho" 0)
         (prompt "\nPick text to be changed.")
         (setq v1 (ssget '((0 . "TEXT")) ))
         (setq newtx "REQUIRED")
         (setq newtx (cons 1 newtx))
         (setq v2 0)
            (if (and v1 newtx)
                (while (< v2 (sslength v1))
                       (setq nme (ssname v1 v2))
                       (setq oldtx (assoc 1 (entget nme)))
                       (setq v3 (entget nme))
                       (entmod (subst newtx oldtx v3))
                       (entupd nme)
                       (setq v2 (+ v2 1))
                )
            )
)

Posted

This seems to work. I dont know if there is a better way but if so please let me know.

 

Replaced this:

(setq v1 (ssget '((0 . "TEXT"))))

 

With this:

(setq V1 (ssget "_+.:E:S" (list (cons 0 "*") (cons 8 lay_name))))

Posted

Something like this perhaps?

(defun c:req ( / ent enx )
   (while
       (progn (setvar 'errno 0) (setq ent (car (entsel)))
           (cond
               (   (= 7 (getvar 'errno))
                   (princ "\nMissed, try again.")
               )
               (   (null ent) nil)
               (   (not (wcmatch (cdr (assoc 0 (setq enx (entget ent)))) "TEXT,MTEXT"))
                   (princ "\nPlease select a text or mtext object.")
               )
               (   (entmod (subst '(1 . "REQUIRED") (assoc 1 enx) enx)))
           )
       )
   )
   (princ)
)

  • Like 1
Posted

Thank you Lee. I greatly appreciate your support to this thread, and all other threads you dedicate time too. I know we all appreciate your efforts. Blessings.

Posted

Could we get it so text of the entity being changed can switch to a layer of my choice? An example would be if I want a specific text changed to "Broken Insulation" Then I want it changed to a layer called "HIGH"..

Posted (edited)

I was able to take the simple approach and make it work. If anyone is interested in this routine please feel free to use it. thanks Lee.

 

(defun c:REQUIRED ( / ent enx )
   ;(while
       (progn (setvar 'errno 0) (setq ent (car (entsel)))
           (cond
               (   (= 7 (getvar 'errno))
                   (princ "\nMissed, try again.")
               )
               (   (null ent) nil)
               (   (not (wcmatch (cdr (assoc 0 (setq enx (entget ent)))) "TEXT,MTEXT"))
                   (princ "\nPlease select a text or mtext object.")
               )
               (   (entmod (subst '(1 . "[color=red]REQUIRED[/color]") (assoc 1 enx) enx))
                      (setq l_exist (tblsearch "layer" "[color=red]REQUIRED[/color]"))
                        (if (not l_exist)
                          (command "._-layer" "N" "[color=red]REQUIRED[/color]" "C" "[color=red]1[/color]"   "[color=red]REQUIRED[/color]" "")
                        )
                          (command "change" ENT "" "p" "LAYER" "[color=red]REQUIRED[/color]" "")
                          (command "change" ENT "" "p" "color" "bylayer" "")
               )
           )
       )
   
   (princ)
)

All you have to do is change the values in RED to suit you needs and make as many shortcut commands as you want. This is just an example, we really don't use it for the word "Required".. it saves a lot of time when you have lots of different abbreviated scenarios in your office that end up having to be typed out.

 

giphy.gif

Edited by tmelancon
Posted

               (   (entmod (subst '(1 . "[color=red]REQUIRED[/color]") (assoc 1 enx) enx))
                      (setq l_exist (tblsearch "layer" "REQUIRED"))
                        (if (not l_exist)
                          (command "._-layer" "N" "[color=red]REQUIRED[/color]" "C" "[color=red]1[/color]"   "[color=red]REQUIRED[/color]" "")
                        )
                          (command "change" ENT "" "p" "LAYER" "[color=red]REQUIRED[/color]" "")
                          (command "change" ENT "" "p" "color" "bylayer" "")
               )
           )
)

]

 

Hi,

 

Do your best to avoid using command calls into your lisp programs to keep the performance at high level unless you have no other way to achieve your goal.

 

You can also change the command call to create the layer but I left it out for you to do it by yourself.

Have a close look at the following mods and it may look difficult but here it is. :)

 

(t
      (if (not (tblsearch "layer" "REQUIRED"))
        (command "._-layer" "N" "REQUIRED" "C" "1" "REQUIRED" "")
        )
      (entmod (append (subst '(1 . "REQUIRED") (assoc 1 enx) enx) '((8 . "REQUIRED") (62 . 256))))
      )

Posted

Good stuff tmelancon - well done for modifying the code to suit.

 

FWIW, if you wanted to keep with modifying the DXF data, the program could be written:

(defun c:required ( / ent enx itm )
   (while
       (progn (setvar 'errno 0) (setq ent (car (entsel)))
           (cond
               (   (= 7 (getvar 'errno))
                   (princ "\nMissed, try again.")
               )
               (   (null ent) nil)
               (   (not (wcmatch (cdr (assoc 0 (setq enx (entget ent)))) "TEXT,MTEXT"))
                   (princ "\nPlease select a text or mtext object.")
               )
               (   (or (tblsearch "layer" "REQUIRED")
                       (entmake
                          '(   (000 . "LAYER")
                               (100 . "AcDbSymbolTableRecord")
                               (100 . "AcDbLayerTableRecord")
                               (070 . 0)
                               (002 . "REQUIRED")
                               (062 . 1)
                           )
                       )
                   )
                   (foreach dxf '((1 . "REQUIRED") (8 . "REQUIRED") (62 . 256))
                       (if (setq itm (assoc (car dxf) enx))
                           (setq enx (subst dxf itm enx))
                           (setq enx (append enx (list dxf)))
                       )
                   )
                   (entmod enx)
                   nil ;; Comment this to loop
               )
           )
       )
   )
   (princ)
)

You can then expand the list supplied to foreach to include as many or as few properties as you wish to change - here is a reference for general DXF properties common to most entities, and here is a reference for properties pertaining to TEXT objects & MTEXT objects.

Posted

Whoa I have to admit, I can read and decipher LISP and do a little bit of code modification, even creating small routines by myself... but this is a whole different ball game that I am being introduced to today. Wow. I had not idea what dxf was, nor how to read and/or understand it. I clicked around and did some reading up to start learning it. Very interesting stuff, and sort of scary at the same time. With that being said after reading up I took your basic dxf layer create using entmake. I am definitely not familiar with the foreach and everything after that part of the code so I stuck with what I could figure out.

 

(defun c:REQUIRED ( / ent enx )
   ;(while ;;;; UNCOMMENT THIS FOR LOOPING
       (progn (setvar 'errno 0) (setq ent (car (entsel)))
           (cond
               (   (= 7 (getvar 'errno))
                   (princ "\nMissed, try again.")
               )
               (   (null ent) nil)
               (   (not (wcmatch (cdr (assoc 0 (setq enx (entget ent)))) "TEXT,MTEXT"))
                   (princ "\nPlease select a text or mtext object.")
               )
               (   (or (tblsearch "layer" "REQUIRED")
                          (entmake
                            '(   (000 . "LAYER")
                                 (100 . "AcDbSymbolTableRecord")
                                 (100 . "AcDbLayerTableRecord")
                                 (070 . 0)
                                 (002 . "REQUIRED")
                                 (062 . 1)
                             )
                          )
                       )
                       (entmod (append (subst '(1 . "REQUIRED") (assoc 1 enx) enx) '((8 . "REQUIRED") (62 . 256))))
                       )
           )
       )
    ;;;; UNCOMMENT THIS FOR LOOPING
   (princ)
)

  • 4 years later...
Posted
On 5/9/2016 at 2:51 PM, Lee Mac said:

Something like this perhaps?


(defun c:req ( / ent enx )
   (while
       (progn (setvar 'errno 0) (setq ent (car (entsel)))
           (cond
               (   (= 7 (getvar 'errno))
                   (princ "\nMissed, try again.")
               )
               (   (null ent) nil)
               (   (not (wcmatch (cdr (assoc 0 (setq enx (entget ent)))) "TEXT,MTEXT"))
                   (princ "\nPlease select a text or mtext object.")
               )
               (   (entmod (subst '(1 . "REQUIRED") (assoc 1 enx) enx)))
           )
       )
   )
   (princ)
)
 

 

good morning, sorry to be in the middle of this, one quick question, this lisp routine for for selecting one text, can we do to select one text change it, select second text and change too at same time? my email is ant7lop@gmail.com   thank you

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