Jump to content

Recommended Posts

Posted

In my ongoing study into DFX group codes I wrote the following little lisp, which works fine.

 

(defun c:rrr ( / ent entdef n ss x)
 (setq x (getstring t "\nEnter text to overwrite: "))
 (if (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
       (progn
(setq n 0)
(repeat (sslength ss)
(setq ent (ssname ss n))
(setq entdef (entget ent))
(setq entdef (subst (cons 1 x) (assoc 1 entdef) entdef))
(entmod entdef)
(setq n (1+ n))
)
)
   (princ "No Text Selected. Please Try Again")
   )
 (princ)
)

 

My question is, can the lines:

            (setq ent (ssname ss n))
            (setq entdef (entget ent))
            (setq entdef (subst (cons 1 x) (assoc 1 entdef) entdef))

Be reduced to two (or even one) line without changing anything else or using those fancy vl-functions?

It's the entget bit I'm struggling with, to put into the other lines

Posted

Perhaps something like this

 (defun c:rrr (/ entdef ss x)
   (if (and (setq x (getstring t "\nEnter text to overwrite: "))
            (not (eq x ""))
       )
       (if (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
           (repeat (setq i (sslength ss))
               (entmod (subst (cons 1 x) (assoc 1 (setq entdef (entget (ssname ss (setq i (1- i)))))) entdef))
           )
           (princ "No Text Selected. Please Try Again")
       )
       (princ "No valid text to overwrite was entered. Please Try Again")
   )
   (princ)
) 

EDIT: Sorry, fast reading...

In my ongoing study into DFX group codes I wrote the following little lisp, which works fine.

 

My question is, can the lines:

            (setq ent (ssname ss n))
            (setq entdef (entget ent))
            (setq entdef (subst (cons 1 x) (assoc 1 entdef) entdef))

Be reduced to two (or even one) line without changing anything else or using those fancy vl-functions?

It's the entget bit I'm struggling with, to put into the other lines

(setq entdef (subst (cons 1 x) (assoc 1 (setq entdef (entget (ssname ss n)))) entdef)) 

Henrique

Posted

Thank you very much Henrique.

(setq entdef (subst (cons 1 x) (assoc 1 (setq entdef (entget (ssname ss n)))) entdef))

That's much tidier & shorter. And not one vl-gizmo anywhere! That’s the best thing about this forum, there’s always an expert like you or Lee willing to help a newbie like me.

 

I admit that it took me quite a long time to write this short lisp, several of the functions are new to me.

As for your initial post, I had intended adding the “(if (and” error prevention, but simply hadn’t got that far, I still need to keep it as simple as possible before adding such luxuries!

Posted

You're welcome, Happy Hobbit

Glad I could help

 

Henrique

Posted

Happy Hobbit you may want to think about using a library of little defuns, pushing my own wheelbarrow from now on I use the getvals.lsp that allows me via 2 lines to 1 2 3 or more lines of a dialouge to appear without writing any dcl code ; sample code (ah:getval3 "Length" 5 4 "Width" 8 7 "Height" 6 4) http://www.cadtutor.net/forum/showthread.php?93002-1-line-2-line-3line-dcl-auto-generator-plus-more-if-required&p=636641&viewfull=1#post636641

 

Working on a commercial product which in nearly every routine changed layers and other settings had 3-4 lines in every routine but each line was worth around 20 lines of code in the library.

 

You probably need to compare number of characters typed v's actual number of lines you have not saved much in this particular example. People like Lee & Tharwat are great on reducing size of actual code.

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