Filter and erase then purge text

Filter and erase then purge text

Anonymous
Not applicable
927 Views
4 Replies
Message 1 of 5

Filter and erase then purge text

Anonymous
Not applicable

I am trying to erase all text objects and all the block objects from a drawing then purge all unused layers from the drawing. I have named filters set up to select the objects I need.

 

(defun C:CleanDXF ()

(command "erase" "window" "607.454,4976.357" "613.677,4997.599" "") ;erases an unneeded legend
(command "zoom" "e") ;zoom to fit all objects into the window
(command "filter" "window" "0,0" "9999999,9999999" "" "erase" ""      ;if I close the routine before the "" here it works
                    "filter" "window" "0,0" "9999999,9999999" "" "erase" "")    ;Adding the second filter command breaks it

);defun

 

Here is the command history from when I run the routine.

 

Command: CLEANDXF
erase
Select objects: window
Specify first corner: 607.454,4976.357 Specify opposite corner: 613.677,4997.599 0 found
Select objects:
Command: zoom
Specify corner of window, enter a scale factor (nX or nXP), or
[All/Center/Dynamic/Extents/Previous/Scale/Window/Object] : e
Command: filter Applying filter to selection.
Select objects: window
Specify first corner: 0,0 Specify opposite corner: 9999999,9999999 12 found

Select objects: Exiting filtered selection.
Command: erase
Select objects:
Command: filter Applying filter to selection.
Select objects: window
Specify first corner: 0,0 Specify opposite corner: 9999999,9999999 12 found

Select objects: Exiting filtered selection.
Command: erase
Select objects:
Command: nil

 

Is there a way to automate the named filter selection?

Why is erase not seeing the selected objects?

What can I do to fix this routine?

0 Likes
Accepted solutions (1)
928 Views
4 Replies
Replies (4)
Message 2 of 5

dlanorh
Advisor
Advisor
Accepted solution

Try the attached, It does away with the filter command as you can create a selection set using ssget with a filter list.

 

This lisp will ask if want to delete all text and block objects in Model space, Paper space (all tabs) or Both (default is Both)

 

(defun c:cleandxf ( / sv_lst sv_vals ans ss)
  (setq sv_lst (list 'dynmode 'dynprompt)
        sv_vals (mapcar 'getvar sv_lst)
  );end_setq
  
  (mapcar 'setvar sv_lst (list 3 1))
  
  (initget "Both Model Paper")
  (setq ans (cond ( (getkword "Select Space to delete all Text and Blocks : [Both/Model/Paper] <Both>")) ("Both")))
  (cond ( (= ans "Model") (setq filter (list '(0 . "INSERT,TEXT") (cons 410 "Model"))))
        ( (= ans "Paper") (setq filter (list '(0 . "INSERT,TEXT") (cons 410 "Paper"))))
        (t (setq filter (setq filter (list '(0 . "INSERT,TEXT")))))
  );end_cond
  
  (setq ss (ssget "_X" filter))
  (repeat (setq cnt (sslength ss)) (entdel (ssname ss (setq cnt (1- cnt)))))
  (mapcar 'setvar sv_lst sv_vals)
  (princ)
);end_defun

I am not one of the robots you're looking for

0 Likes
Message 3 of 5

dlanorh
Advisor
Advisor

Just noticed that the posted lisp is wrong.  This is correct.

 

(defun c:cleandxf ( / sv_lst sv_vals ans ss)
  (setq sv_lst (list 'dynmode 'dynprompt)
        sv_vals (mapcar 'getvar sv_lst)
  );end_setq
  
  (mapcar 'setvar sv_lst (list 3 1))
  
  (initget "Both Model Paper")
  (setq ans (cond ( (getkword "Select Space to delete all Text and Blocks : [Both/Model/Paper] <Both>")) ("Both")))
  (cond ( (= ans "Model") (setq filter (list '(0 . "INSERT,TEXT") (cons 410 "Model"))))
        ( (= ans "Paper") (setq filter (list '(0 . "INSERT,TEXT") (cons 410 "~Model"))))
        (t (setq filter (setq filter (list '(0 . "INSERT,TEXT")))))
  );end_cond
  
  (setq ss (ssget "_X" filter))
  (repeat (setq cnt (sslength ss)) (entdel (ssname ss (setq cnt (1- cnt)))))
  (mapcar 'setvar sv_lst sv_vals)
  (princ)
);end_defun

Once again find and replace is overzealous 🙄 ☹️

I am not one of the robots you're looking for

Message 4 of 5

john.uhden
Mentor
Mentor
"~Model"
Very clever... every layout except "Model"

John F. Uhden

0 Likes
Message 5 of 5

devitg
Advisor
Advisor

Hi John , nice answer about 

 

"~Model"

I was wonder what it was???

 

 

 

0 Likes