Jump to content

Help Select all Text Object with Content and delete it automatically


Recommended Posts

uzumaki narudin

need to modified to delete text object with specific content and automatically delete  it
 

this code i get somewhere,  i have to mannually enter the text and press dell, can someone help me ?

(defun C:FSC (/ str ss) ; = Find String(s) by Content
  (setq str (getstring "\nYour [full or partial] string content to search for: "))
  (if (setq ss (ssget "_X" (list (cons 0 "*TEXT") (cons 1 (strcat "*" str "*")) (cons 410 (getvar 'ctab)))))
    (sssetfirst nil ss); select/highlight/grip
  ); if
); defun

 

delete.jpg

Link to post
Share on other sites
rlx

you could replace (sssetfirst nil ss) with (entdel (ssname ss 0)) but in your picture I see same text twice so how whould routine know which one should be deleted? Unless you want to delete all text with this text.

Link to post
Share on other sites
uzumaki narudin
Posted (edited)

i no have lsp experience but start to learn it

 

I HAVE manage select all those text with current command and enter the text content then press delete, what i want is when i type FSC it select all texts automatically without typing it and press del 

delete2.jpg

Edited by uzumaki narudin
Link to post
Share on other sites
rlx

maybe like this :

[code]

 

(defun C:FSC (/ str ss) (setq str (getstring "\nYour [full or partial] string content to search for: "))
  (if (setq ss (ssget "_X" (list (cons 0 "*TEXT") (cons 1 (strcat "*" str "*")) (cons 410 (getvar 'ctab)))))
    (progn (setq i -1) (repeat (sslength ss) (entdel (ssname ss (setq i (1+ i))))))))

 

;;; Delete EVERY text entity

(defun C:FSC2 (/ ss)  (if (setq ss (ssget "_X" (list (cons 0 "*TEXT")  (cons 410 (getvar 'ctab)))))
    (progn (setq i -1) (repeat (sslength ss) (entdel (ssname ss (setq i (1+ i))))))))

 

[/code]

Edited by rlx
[code] formatting seems to be not working at this moment
  • Thanks 1
Link to post
Share on other sites
Isaac26a

Maybe what he meant and didn't explain was something like this.

;;; Delete all the texts with the string "0.0:"
(defun c:fsc (/ i str ss)
   (if (setq ss (ssget "_X" (list (cons 0 "*TEXT") (cons 1 (strcat "*" "0.0:" "*"))
 (cons 410 (getvar 'ctab)))))
      (progn
         (setq i -1)
         (repeat (sslength ss)
            (entdel (ssname ss (setq i (1+ i))))
         )
      )
   )
   (princ)
)

 

  • Thanks 1
Link to post
Share on other sites
uzumaki narudin
2 hours ago, Isaac26a said:

Maybe what he meant and didn't explain was something like this.


;;; Delete all the texts with the string "0.0:"
(defun c:fsc (/ i str ss)
   (if (setq ss (ssget "_X" (list (cons 0 "*TEXT") (cons 1 (strcat "*" "0.0:" "*"))
 (cons 410 (getvar 'ctab)))))
      (progn
         (setq i -1)
         (repeat (sslength ss)
            (entdel (ssname ss (setq i (1+ i))))
         )
      )
   )
   (princ)
)

 

This Works  Great Man.. , Thanks Alot 😀

Link to post
Share on other sites
Isaac26a
1 hour ago, uzumaki narudin said:

This Works  Great Man.. , Thanks Alot 😀

You're welcome

Link to post
Share on other sites
uzumaki narudin
On 4/25/2021 at 10:16 AM, Isaac26a said:

You're welcome

BTW is there anyway to enhance this lisp, so instead delete it i want to change properties of the text like change rotation, text height or even add to another layer

 

im really need those kind of routine..

 

thanks mate

Link to post
Share on other sites
Jonathan Handojo

I'm confused here. Sometimes you want the command to automatically delete, sometimes you want it to change properties, sometimes layer, etc... You can't embed everything into one command without requiring some sort of prompt from the user (for example, which property to change, what action to take [delete/property change]). If it was me, I'd rather you have one command which prompts the user for input, and after that you create your own multiple custom macros with the specific inputs to perform the required automated tasks in one shot. (For instance, you could record the macro, first running your FSC in the original post, and then ERASE. Then you can save it as a different command name.)

 

If you have no experience to LISP, I just suggest, as opposed to deleting it, selecting the text itself just as how your initial code is from OP. Afterwards all you need to do is just open up the properties palette and change as required. If you really need to use LISP, you'll need to understand the DXF codes that AutoLISP uses to associate with entities in AutoCAD. You may need to learn from the basics, but this may give you a quick head start. Downside is, unless you're adapt to writing codes such as Lee Mac and our other expert programmers here, your commands would tend to be very "fixed" and would then need consistent changing if you'd like for it to perform other tasks.

 

Link to post
Share on other sites
mhupp

No need to step thought each entity in the selection set just delete everything at once.

 

;;; Delete all the texts with the string "0.0:"
(defun c:fsc (/ ss)
  (setq ss (ssget "_X" (list (cons 0 "*TEXT") (cons 1 (strcat "*" "0.0:" "*")) (cons 410 (getvar 'ctab)))))
  (if ss (vl-cmdf "_.Erase" ss ""))
  (princ)
)

 

Quote

BTW is there anyway to enhance this lisp, so instead delete it i want to change properties of the text like change rotation, text height or even add to another layer

 

im really need those kind of routine..

 

You could always just have the lisp select everything and then the user can make the changes they want manually. (basically what Jonathan Handojo said)

 

;;; Selete all the texts from user input
(defun C:FSC (/ SS str)
  (setq str (getstring T "\nEnter Text to Search For: "))
  (setq SS (ssget "_X" (list (cons 0 "*TEXT") (cons 1 (strcat "*" str "*")) (cons 410 (getvar 'ctab)))))
  (if SS (sssetfirst nil SS))
  (princ)
)

 

Edited by mhupp
Link to post
Share on other sites
Jonathan Handojo
2 hours ago, mhupp said:

You could always just have the lisp select everything and then the user can make the changes they want manually. (basically what Jonathan Handojo said)

 


;;; Selete all the texts from user input
(defun C:FSC (/ SS str)
  (setq str (getstring T "\nEnter Text to Search For: "))
  (setq SS (ssget "_X" (list (cons 0 "*TEXT") (cons 1 (strcat "*" str "*")) (cons 410 (getvar 'ctab)))))
  (if SS (sssetfirst nil SS))
  (princ)
)

Well, that's no different to the code from Original Post... Which is why I didn't post any codes in the first place. ;)

Link to post
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
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...