TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: whdjr on October 01, 2005, 12:14:56 PM

Title: ssget filter errors
Post by: whdjr on October 01, 2005, 12:14:56 PM
Why does this not work?
Are you allowed to put handles in your ssget filters?

Code: [Select]
(ssget '((0 . "INSERT")
          (66 . 1)
          (2 . "R-NAME")
          (-4 . "<NOT")
          (5 . "345AD7"))
)

It gives me an error 63 (filter error) when I try to run it.  I tried the '<not' before and after the handle with no luck.  It only works without the handle.  Can anyone verify this for me?
Title: Re: ssget filter errors
Post by: Peter Jamtgaard on October 01, 2005, 12:36:34 PM
Try this. The not filter requires 2 parts
It might work

Code: [Select]
(ssget '((0 . "INSERT")
          (66 . 1)
          (2 . "R-NAME")
          (-4 . "<NOT")
          (5 . "345AD7")
          (-4 . "NOT>"); revised
         )
)

It gives me an error 63 (filter error) when I try to run it.  I tried the '<not' before and after the handle with no luck.  It only works without the handle.  Can anyone verify this for me?
Title: Re: ssget filter errors
Post by: whdjr on October 01, 2005, 01:02:21 PM
Try this. The not filter requires 2 parts
It might work
No go.  I tried that already but I tried it again and it still didn't work.
Title: Re: ssget filter errors
Post by: LE on October 01, 2005, 01:19:39 PM
You cannot use group 5 with ssget.... it won't be recognize.... that's why
Title: Re: ssget filter errors
Post by: MP on October 01, 2005, 01:25:32 PM
You cannot filter on group 5, you have to do something like this --

Code: [Select]
(defun RemoveHandlesFromSS ( ss handles / i ename )

    (setq handles (mapcar 'strcase handles))
   
    (if (eq 'pickset (type ss))
        (repeat (setq i (sslength ss))
            (if
                (member
                    (cdr
                        (assoc 5
                            (entget
                                (setq ename
                                    (ssname ss
                                        (setq i (1- i))
                                    )
                                )
                            )
                        )
                    )
                    handles
                )
                (ssdel ename ss)
            )
        )
    )
   
    ss
   
)

Then --

Code: [Select]
(setq ss
    (RemoveHandlesFromSS
        (ssget
           '(   (0 . "INSERT")
                (66 . 1)
                (2 . "R-NAME")
            )
        )
       '("345AD7")
    )
)

Coded blind so may need massaging.
Title: Re: ssget filter errors
Post by: MP on October 01, 2005, 01:37:11 PM
Think you have it backwards Luis, he DOESN'T want the entity sporting that handle.
Title: Re: ssget filter errors
Post by: CAB on October 01, 2005, 01:43:54 PM
Scratching Head
If the handle is unique then he does want a specific object, no? :?
Title: Re: ssget filter errors
Post by: MP on October 01, 2005, 01:46:58 PM
Looks to me like he wants all blocks named "R-NAME" that have attributes except the one with the handle "345AD7", at least that is what the code in the first post suggests to me.

:)
Title: Re: ssget filter errors
Post by: CAB on October 01, 2005, 01:49:37 PM
Oh, I missed the NOT. :-o
In that case your solution look perfect for that.
Title: Re: ssget filter errors
Post by: MP on October 01, 2005, 02:03:59 PM
Something a little more flexible might be --

Code: [Select]
(defun RemoveFromPicksetIf ( ss func )
    ;;  The supplied func must take one
    ;;  argument, an ename. What it does
    ;;  we don't care, but if it returns
    ;;  a non nil result remove the entity
    ;;  from the pickset
    (if (eq 'pickset (type ss))
        (repeat (setq i (sslength ss))
            (if
                (func
                    (setq ename
                        (ssname ss
                            (setq i (1- i))
                        )
                    )
                )
                (ssdel ename ss)
            )
        )
    )
    ss
)

Then he'd might use it thusly --

Code: [Select]
(setq ss
    (RemoveFromPicksetIf
        (ssget
           '(   (0 . "INSERT")
                (2 . "R-NAME")
                (66 . 1)
            )
        )
        (lambda (ename)
            (eq "345AD7"
                (cdr
                    (assoc 5
                        (entget ename)
                    )
                )
            )
        )
    )
)
Title: Re: ssget filter errors
Post by: whdjr on October 01, 2005, 02:32:16 PM
Thanks guys you answered my question and gave more as always.

What I did while I was waiting was to get the entities supplied from 'ssget' and then used 'vl-remove' to remove the entity I didn't need because I already had the entity name from earlier in my code.  I was just trying to shorcut that by ecluding that block via it's handle; but that's a no go.

Thanks again guys.
Title: Re: ssget filter errors
Post by: Crank on October 01, 2005, 02:36:55 PM
Code: [Select]
(ssdel (handent "345AD7") (ssget '((0 . "INSERT")(66 . 1)(2 . "R-NAME"))))
Title: Re: ssget filter errors
Post by: MP on October 01, 2005, 02:38:07 PM
Good stuff Mr. Crank. For succinctness that's a winner.
Title: Re: ssget filter errors
Post by: whdjr on October 01, 2005, 10:30:56 PM
Code: [Select]
(ssdel (handent "345AD7") (ssget '((0 . "INSERT")(66 . 1)(2 . "R-NAME"))))


I Like!  :-)
Title: Re: ssget filter errors
Post by: MP on October 02, 2005, 11:42:15 AM
Make sure you use a valid handle for the succinct version lest there be an immediate "earth shattering kaboom".

/Marvin

:lol:
Title: Re: ssget filter errors
Post by: CAB on October 02, 2005, 12:44:14 PM
How about this?
Code: [Select]
(setq ss
       (vl-catch-all-apply 'ssdel
                           (list (handent "345AD7")
                                 (ssget '((0 . "INSERT") (66 . 1) (2 . "R-NAME")))
                           )
       )
)
Title: Re: ssget filter errors
Post by: Andrea on October 02, 2005, 02:32:50 PM
WHd...

what you realy need to do ?
Title: Re: ssget filter errors
Post by: MP on October 02, 2005, 03:48:03 PM
I like the new indenting style Alan, very easy to discern the parentage.

:-o
Title: Re: ssget filter errors
Post by: Kerry on October 02, 2005, 03:53:33 PM
hehehe ..
yeah, nothing worse than illegitimate code.

Title: Re: ssget filter errors
Post by: MP on October 02, 2005, 03:54:15 PM
 :-D
Title: Re: ssget filter errors
Post by: MP on October 02, 2005, 04:32:16 PM
Humour aside, I don't think that's a good approach Alan, and here's why --

If we assume we have a drawing that has valid entities in it you'll agree, this should retrieve all the entities correct?

Code: [Select]
(ssget "x")
Now let's filter it using your code and supply a bogus handle to the affore mentioned code --

Code: [Select]
(setq ss
    (vl-catch-all-apply 'ssdel
        (list (handent "BOGUS")
            (ssget "x")
        )
    )
)

Instead of a selection set containing all the entities being assigned to variable ss we get a bound error object. Not so good me thinks.

If you're bent on using vl-catch-all-apply here's an interesting alternate (of many) just for fun --

Code: [Select]
(vl-catch-all-apply
   '(lambda ( )
        (setq ss
            (ssdel (handent "BOGUS")
                (setq ss
                    (ssget "x")
                )
            )
        )   
    )
)

If the supplied handle is valid AND the corresponding ename a member of the inner most ss it will be removed and the resulting (slimmed down) selection set assigned to ss, otherwise the original selection set will remain assigned to ss. The entire code snip does return an error object which we have chosen to discard in this case.

:)
Title: Re: ssget filter errors
Post by: CAB on October 02, 2005, 06:12:59 PM
I see, I guess I would drop back to this.
Code: [Select]
(setq ss (ssget "x"))
(and (handent "BOGUS")
     (ssdel (handent "BOGUS") ss))
I wasn't married to that code just tried to figure a way to catch the error. :-)
Title: Re: ssget filter errors
Post by: MP on October 02, 2005, 07:07:50 PM
Yep.

(http://www.theswamp.org/screens/mp/nodding.gif)
Title: Re: ssget filter errors
Post by: whdjr on October 03, 2005, 09:14:35 AM
WHd...

what you realy need to do ?
What I am doing is selecting a block with attributes as a reference block.  I am then asking the user to select more of the same block; however I wanted the ssget filter to remove the original block if it was selected in the selection set.  I have it set up right now that after it makes the selection set and returns all the entities I use vl-remove to delete the original referenced block.  If the block is in the set then it is deleted or if the block is not in the set then the set is passed back with no errors to worry about.

I just was looking for a way to remove the block using the ssget function. :-)

Thanks for all the help you guys have given and ofcourse the great discussion I started. :mrgreen: