SSGET & ERASE?

C Witt

Usenet Archive
Joined
Jun 23, 2003
Messages
396
Reaction score
0
I have a ssget lisp that searches for a given "setting".. and if it finds it.. it will delete it (atleast that is what it is suposed to do).

I'm having problems finding a way to get cad to "erase" the object if it meets the criteria i have set..

(setvar "cmdecho" 0)
(setq E (ssget "X" (list (CONS 0 "WIPEOUT"))))
(setq COUNT 0)
(setq EN (ssname E COUNT))
(setq EL (entget EN))
(WHILE (/= EN nil)
(setq EL (entget EN))
(if
(= (cdr (assoc 102 EL)) nil); we have a "tag" attached to the wipeouts thanks to reactors, so i can see if it is "correct". ; the erase command would go here (setq COUNT (1+ COUNT)) (setq EN (SSNAME E COUNT)) ) (setvar "cmdecho" 1)
(princ)

thanks.
 
Your loop is a little out of sorts. Compare this with what you had.

(setvar "cmdecho" 0)
(setq E (ssget "X" (list (CONS 0 "WIPEOUT"))))
(setq COUNT 0)
(repeat (sslength E)
(setq EN (ssname E COUNT))
(setq EL (entget EN))
(if
(= (cdr (assoc 102 EL)) nil) ; we have a "tag" attached to the wipeouts thanks to reactors, so i can see if it is "correct". (command "erase" EN "") ; the erase command would go here ) (setq COUNT (1+ COUNT)) ) (setvar "cmdecho" 1)
(princ)
 
btw works great.

one more question.. (this will work for wipeouts NOT with text).. how do i get it to delete wipeouts that the text has been removed from?
 
There are bunch of ways to step thru a slection set

(setq i (sslength ss))

(while (not (minusp (setq i (1- i)))))
(setq en (ssname ss i))
.............
)

Or:

(while ss
(setq en (ssname ss 0))
............
(ssdel en ss))

-David
 
Not to iterate through a selset. Using (while (something)..... "something" is evaluated each iteration. That something is usually your counter versus the number of items in your selset. Using (repeat (sslength selset)......There is no need to re-evaluate "something".
Hope this makes sense.
 
There are a bunch....Curious about this one though:

(while ss
(setq en (ssname ss 0))
............
(ssdel en ss))
 
would it be possible to "see" if the erase command is selecting a "group" rather than an "object"? (when erase is used the mask is grouped with it's text).. so if it selects a "group".. it won't erase it?.. just a thought...
 
nope.. that won't diferintiate between a mask with text.. and a mask without (but did have text at one time).
 
Should have been

(setq ss (ssget "X" '((0 . "LINE"))))

(while (setq en (ssname ss 0))
...............

(ssdel en ss))

-David
 
No, I want the lisp to remove wipeouts ONLY if they have no text.
 
Try this:

; delete wipeouts in the current layout that
; are not associated with a text object.

; - minimal testing -
; use at your own risk.

(defun c:deleteWipeouts (/ ss i ename)
(if
(setq ss (ssget "x" (list '(0 . "WIPEOUT")(cons 410 (getvar "ctab"))))) (progn (setq i 0) (repeat (sslength ss) (setq ename (ssname ss i)) (if (not (@cv_attached ename "GROUP")) (entdel ename) ) (setq i (1+ i)) ) ) ) (princ "\nfinished") (princ)
)

;;----------------------------------------------------------- ;; John Uhden:
;; Function to return a list of objects attached to an entity ;; by the standard AutoCAD reactors. ;; Given:
;; ename = the entity to search
;; filter = a wcmatch filter to specify the entity type of attachments ;; Returns a list of entity names matching the filter, or nil ;; Adapted (12-09-01) from @cv_attached for Jason Piercey and Alfredo Medina (defun @cv_attached (ename filter / ent items item refs) (setq ent (entget ename) filter (strcase filter) items (cdr (member '(102 . "{ACAD_REACTORS") ent)) item (car items) ) (while (= (car item) 330) (and (setq item (cdr item)) (setq ent (entget item)) (wcmatch (cdr (assoc 0 ent)) filter) (setq refs (cons item refs)) ) (setq items (cdr items) item (car items) ) ) (reverse refs)
)
 
; error: no function definition: @CV_ATTACHED

what does this mean?
 
ok.. got that fixed.. but the lisp won't delete a mask that has had the text removed.. (as it still has the reactor tag).. this one does what my original one does.. (well the tweeked version anyway)..

(setvar "cmdecho" 0)
(setq E (ssget "X" (list (CONS 0 "WIPEOUT"))))
(setq COUNT 0)
(repeat (sslength E)
(setq EN (ssname E COUNT))
(setq EL (entget EN))
(if
(= (cdr (assoc 102 EL)) nil)
(command "erase" EN "")
)
(setq COUNT (1+ COUNT))
)
(setvar "cmdecho" 1)
(princ)
 
Scrap that first one, try this

comments anyone?

; minimal testing
; delete all wipeouts from the current tab
; that are not attached to an entity.
(defun c:deleteWipeouts (/ ss i ename items)
(if
(setq ss (ssget "x" (list '(0 . "WIPEOUT")(cons 410 (getvar "ctab"))))) (progn (setq i 0) (repeat (sslength ss) (setq ename (ssname ss i)) (if (or (and (setq items (@cv_attached ename "GROUP")) (= 1 (length items)) (= 1 (length (massoc 340 (entget (car items))))) ) (not items) ) (entdel ename) ) (setq i (1+ i)) ) (princ "\nfinished deleting possible wipeouts") ) ) (princ)
)

;;----------------------------------------------------------- ;; John Uhden:
;; Function to return a list of objects attached to an entity ;; by the standard AutoCAD reactors. ;; Given:
;; ename = the entity to search
;; filter = a wcmatch filter to specify the entity type of attachments ;; Returns a list of entity names matching the filter, or nil ;; Adapted (12-09-01) from @cv_attached for Jason Piercey and Alfredo Medina (defun @cv_attached (ename filter / ent items item refs) (setq ent (entget ename) filter (strcase filter) items (cdr (member '(102 . "{ACAD_REACTORS") ent)) item (car items) ) (while (= (car item) 330) (and (setq item (cdr item)) (setq ent (entget item)) (wcmatch (cdr (assoc 0 ent)) filter) (setq refs (cons item refs)) ) (setq items (cdr items) item (car items) ) ) (reverse refs)
)

(defun massoc (key alist / x nlist)
(foreach x alist
(if (eq key (car x))
(setq nlist (cons (cdr x) nlist))
)
)
(reverse nlist)
)
 
You're welcome. Although I do think there is flaw in the logic.

(defun c:deleteWipeouts (/ ss i ename flag items)
(if
(setq ss (ssget "x" (list '(0 . "WIPEOUT")(cons 410 (getvar "ctab"))))) (progn (setq i 0) (repeat (sslength ss) (setq ename (ssname ss i)) (setq flag nil) ;; <--- added this (if (or (and (setq items (@cv_attached ename "GROUP")) (= 1 (length items)) (= 1 (length (massoc 340 (entget (car items))))) (setq flag t) ;; <--- added this ) (not flag) ;; <--- changed this ) (entdel ename) ) (setq i (1+ i)) ) (princ "\nfinished deleting possible wipeouts") ) ) (princ)
)
 
NOOOOOOOOOOO!!!

your change causes it to delete ALL wipeouts.
 

Latest threads

Back
Top