SSGET & ERASE?

Discussion in 'AutoCAD' started by C Witt, Aug 11, 2003.

  1. C Witt

    C Witt Guest

    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.
     
    C Witt, Aug 11, 2003
    #1
  2. 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)

    --
    Ken Alexander
    Acad2000
    Windows2000 Prof.

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Aug 11, 2003
    #2
  3. C Witt

    C Witt Guest

    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?
     
    C Witt, Aug 11, 2003
    #3
  4. C Witt

    David Bethel Guest

    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
     
    David Bethel, Aug 11, 2003
    #4
  5. 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.

    --
    Ken Alexander
    Acad2000
    Windows2000 Prof.

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Aug 11, 2003
    #5
  6. There are a bunch....Curious about this one though:

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



    --
    Ken Alexander
    Acad2000
    Windows2000 Prof.

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Aug 11, 2003
    #6
  7. C Witt

    C Witt Guest

    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...
     
    C Witt, Aug 11, 2003
    #7
  8. C Witt

    C Witt Guest

    nope.. that won't diferintiate between a mask with text.. and a mask
    without (but did have text at one time).
     
    C Witt, Aug 11, 2003
    #8
  9. Is the PICKSTYLE variable of any help?
     
    Jason Piercey, Aug 11, 2003
    #9
  10. C Witt

    David Bethel Guest

    Should have been

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


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

    (ssdel en ss))


    -David
     
    David Bethel, Aug 11, 2003
    #10
  11. C Witt

    C Witt Guest

    No, I want the lisp to remove wipeouts ONLY if they have no text.
     
    C Witt, Aug 11, 2003
    #11
  12. 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)
    )
     
    Jason Piercey, Aug 11, 2003
    #12
  13. C Witt

    C Witt Guest

    ; error: no function definition: @CV_ATTACHED

    what does this mean?
     
    C Witt, Aug 11, 2003
    #13
  14. Did you copy/paste all of the code?
     
    Jason Piercey, Aug 11, 2003
    #14
  15. C Witt

    C Witt Guest

    oops.. lol
     
    C Witt, Aug 11, 2003
    #15
  16. C Witt

    C Witt Guest

    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)
     
    C Witt, Aug 11, 2003
    #16
  17. 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)
    )
     
    Jason Piercey, Aug 12, 2003
    #17
  18. 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)
    )
     
    Jason Piercey, Aug 12, 2003
    #18
  19. C Witt

    C Witt Guest

    NOOOOOOOOOOO!!!

    your change causes it to delete ALL wipeouts.
     
    C Witt, Aug 12, 2003
    #19
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.