Jump to content

Recommended Posts

Posted

Before I begin, I have searched the web and the forums.

 

In a previous post I asked for help using a user defined variable to create layers. The help was quick and successful, I was able to complete a lisp that automates some of the work that I do. Thanks for the help.

 

I have decided to expand my lisp to include the ability to replace text on a layout with the user input.

 

I am looking for an example find and replace that will replace predefined text with the user input on a specific layout.

 

Example:

User input = 1

A layout is copied from an existing layout and named 1

I would like to replace all occurances of "AA" on layout 1 with 1 (User input)

 

Thanks

Posted

Here is a quick code not tested at all sorry

 

 
(defun C:FIR (/ elist en find replace sset txt)
 (if (not find)
   (setq find (getstring t "\nFind What? : "))
 )
 (if (not replace)
   (setq replace (getstring t "\nReplace Whith? : "))
 )

 (if (setq sset (ssget "_X" (list (cons 0 "text,mtext");<-- search for text and mtext
  ;(cons 410 (getvar "ctab");<-- search on current layout
     (cons 410 "1";<-- search on layout named "1"  
        ))))

   ;; iterating through selection set
(while
 ;; grab first entity from selection
 (setq en (ssname sset 0))
 ;; get entity list
 (setq elist (entget en))
 ;; get text string from entity list
 (setq txt (cdr (assoc 1  elist)))
 ;; check if this string is equal to what you look up
 (if (eq find txt)
   (progn
     ;; substitute string with new value
     (setq elist (subst (cons 1 replace)(assoc 1 elist) elist))
     ;; modifies the definition data of an entity
(entmod elist)
   )
 )
 ;; remove first entity from selection to go to the next one within the loop
 (ssdel en sset)
 )
   )

 (princ)
)
(princ "\n\t   ---   Start command with FIR   ---")
(princ)

 

~'J'~

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