Jump to content

Help Select all Text Object with Content and delete it automatically


uzumaki narudin

Recommended Posts

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 comment
Share on other sites

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 comment
Share on other sites

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 comment
Share on other sites

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 comment
Share on other sites

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 comment
Share on other sites

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 comment
Share on other sites

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 comment
Share on other sites

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 comment
Share on other sites

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 comment
Share on other sites

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 comment
Share on other sites

  • 2 weeks later...
On 4/29/2021 at 4:29 AM, Jonathan Handojo said:

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.

 

im sorry for confusing you all folks,

 

but sometimes there are repetitive  task which i have to do in order to change the layer ,properties and also delete some texts or any object such polyline , line or event block in my drawing

 

 To do it every time using dialog box is consuming time and manual  using keyboard and mouse click, im just in the middle of working to learn such lisp

 

i have already done some task using record macro but still lisp and vba always interest me more.

 

but thanks anyway mate, im beginning to learn 

 

 

Link to comment
Share on other sites

55 minutes ago, uzumaki narudin said:

im sorry for confusing you all folks,

 

but sometimes there are repetitive  task which i have to do in order to change the layer ,properties and also delete some texts or any object such polyline , line or event block in my drawing

 

 To do it every time using dialog box is consuming time and manual  using keyboard and mouse click, im just in the middle of working to learn such lisp

 

i have already done some task using record macro but still lisp and vba always interest me more.

 

but thanks anyway mate, im beginning to learn 

 

 

 

That's alright.

 

This here is a dirty ssget routine that I punched up myself and regularly use for object selections. Like you, I hate going through dialogs. However, the downside is, the user needs to have a good understanding of how the ssget routine works in AutoLISP, or else it's pointless. The bright side is, I can choose whatever I want with ease using macros for each type of selection filters.

 

(defun c:ssget ( / *error* lst num val acadobj activeundo adoc b fil l ltp mod p1 p2 wid)
    (defun *error* ( msg )
	(mapcar '(lambda (a b) (and b (setvar a b))) '(plinewid celtype) (list wid ltp))
	(vla-EndUndoMark adoc)
	(if (not (wcmatch (strcase msg T) "*break*,*cancel*,*exit*"))
	    (princ (strcat "Error: " msg))
	    )
	)
    (setq acadobj (vlax-get-acad-object)
	  adoc (vla-get-ActiveDocument acadobj)
	  )
    (if (= 0 (logand 8 (getvar "UNDOCTL"))) (vla-StartUndoMark adoc) (setq activeundo T))
    
    (while
	(setq num (getint "\nSpecify ssget DXF code number <end>: "))
	(if
	    (cond
		((or
		     (member num '(-4 100 102 105 410 470))
		     (<= 0 num 8)
		     (<= 300 num 310)
		     )
		 (setq val (getstring t "\nSpecify DXF text: "))
		 )
		((or
		     (<= 10 num 17)
		     (<= 110 num 112)
		     (= num 210)
		     (<= 1010 num 1012)
		     )
		 (setq val (getpoint "\nSpecify point: "))
		 )
		((or
		     (<= 38 num 54)
		     (<= 140 num 147)
		     (<= 211 num 239)
		     (<= 460 num 463)
		     )
		 (setq val (getreal "\nSpecify DXF floating number: "))
		 )
		((or
		     (member num '(370 420 421 440 450 451 452 453))
		     (<= 60 num 79)
		     (<= 90 num 99)
		     (<= 170 num 179)
		     (<= 270 num 297)
		     )
		 (setq val (getint "\nSpecify DXF integer: "))
		 )
		((or
		     (member num '(-2 -1 390))
		     (<= 330 num 361)
		     )
		 (alert "Entities not allowed for selection")
		 )
		((alert "Invalid code"))
		)
	    (setq lst (cons (cons num val) lst))
	    )
	)
    (initget (setq mod "A C CP F I L +.:E:S W WP X"))
    (and
	(setq fil (getkword (strcat "\nSpecify ssget mode string [" (vl-string-translate " " "/" mod) "] <none>: ")))
	(setq fil (strcat "_" fil))
	)
    (sssetfirst
	nil
	(apply
	    'ssget
	    (append
		(cond
		    ((not fil) nil)
		    ((member fil '("_C" "_W"))
		     (if
			 (and
			     (setq p1 (getpoint "\nSpecify first point <cancel>: "))
			     (setq p2 (getcorner p1 "\nSpecify second point <cancel>:"))
			     )
			 (list fil p1 p2)
			 )
		     )
		    ((member fil '("_CP" "_F" "_WP"))
		     (setq l (entlast)) (mapcar '(lambda (a b) (set a (getvar b))) '(wid ltp) '(plinewid celtype))
		     (mapcar 'setvar '(plinewid celtype) '(0.0 "Continuous"))
		     (command "_PLINE")
		     (while (= (getvar 'cmdactive) 1) (command "\\"))
		     (mapcar 'setvar '(plinewid celtype) (list wid ltp))
		     (if (setq l (entnext l))
			 (progn
			     (setq fil (list fil (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget l)))))
			     (entdel l) fil
			     )
			 )
		     )
		    ((eq fil "_L") (list "_:L"))
		    ((list fil))
		    )
		(if lst (list (reverse lst)))
		)
	    )
	)
    (and (not activeundo) (vla-EndUndoMark adoc))
    (princ)
    )

 

Link to comment
Share on other sites

i cannot thank you enough for all the  help you guys, this encourage me more to start learning lisp.😀

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