sslength with no object

Discussion in 'AutoCAD' started by felixlee, Nov 24, 2004.

  1. felixlee

    felixlee Guest

    I use ssget to define objects. By determining if there is a object in the ssget slection, I decide to do certain action. For example, here is my lisp.
    (setq INTOFBOUND41 (ssget "F" (list pt16 pt13) '((8 . "bb") (0 . "HATCH"))))
    (if (= 1 (sslength INTOFBOUND41)) (setq INTOFBOUND4 (sslength INTOFBOUND41)) (setq INTOFBOUND4 nil))

    then if INTOFBOUND4 equals to 1, I will make action. If not, that action will be skiped.
    If there are objects in the selection, the lisp works fine. However, if there is no object, then lisp runs with error. That lisp will be interupted.
    Is there any way to determine if there is any object in the selection?
    Thanks for your help
     
    felixlee, Nov 24, 2004
    #1
  2. felixlee

    Jürg Menzi Guest

    Hi felixlee

    Code:
    (setq INTOFBOUND41 (ssget "F" (list pt16 pt13) '((8 . "bb") (0 . "HATCH"))))
    (cond
    ((not INTOFBOUND41))
    ((= 1 (sslength INTOFBOUND41)) (setq INTOFBOUND4 (sslength INTOFBOUND41)))
    (T (setq INTOFBOUND4 nil))
    )
    
    Cheers
     
    Jürg Menzi, Nov 24, 2004
    #2
  3. felixlee

    Joe Burke Guest

    Just curious... It sounds like you trying to check whether a hatch was created using
    the bhatch command. If so, try it this way.

    (setq mark (entlast))
    (command "bhatch" ... )
    (if (equal mark (entlast))
    ;then bhatch failed...
    ;else bhatch found a boundary...

    BTW, you'll usually get better answers here by presenting the intent of the code, or
    the code in its entirety, rather than a code snip. As a developer used to say to me,
    "don't tell me what the solution should be, tell me about the problem." I only
    appreciated his meaning in hindsight.

    Joe Burke
     
    Joe Burke, Nov 24, 2004
    #3
  4. felixlee

    Tom Smith Guest

    Seemed clear to me. He's trying to check the length of a selection set, and
    couldn't understand why sslength on an empty selection cased an error. It's
    because if nothing is selected, the sset is nil, and (sslength nil) causes a
    bad argument type error.

    This is a rare case where Jürg's solution is a little more verbose than it
    needs to be. Usually he's the master of simplicity!

    (if (and
    (setq INTOFBOUND41 (ssget "F" (list pt16 pt13) '((8 . "bb") (0 .
    "HATCH"))))
    (= 1 (sslength INTOFBOUND41))
    )
    (setq INTOFBOUND4 1) ;you already know the sslength is 1, don't need to
    count it again
    (setq INTOFBOUND4 nil) ;this line may not be necessary if INFOBOUND4 is
    a local which hasn't had a value assigned yet
    )
     
    Tom Smith, Nov 24, 2004
    #4
  5. felixlee

    Joe Burke Guest

    Tom,

    IMO, clear as mud. As your reply demonstrates.

    Joe Burke
     
    Joe Burke, Nov 24, 2004
    #5
  6. felixlee

    Tom Smith Guest

    IMO, clear as mud. As your reply demonstrates.

    Here were my clues:

    Title: sslength with no object

    Code:
    (setq INTOFBOUND41 (ssget <etc> )) ;ssget returns a selection set or nil
    (if (= 1 (sslength INTOFBOUND41)) ;you can't do (sslength nil)
    <etc>)

    Question: "If there are objects in the selection, the lisp works fine.
    However, if there is no object, then lisp runs with error ... Is there any
    way to determine if there is any object in the selection?"

    The way to determine whether anything is in the selection, in order to avoid
    the error, is to test whether INTOFBOUND41is nil. Both Jürg's suggestion and
    mine do this in slightly different ways.

    It's possible to create a zero length selection set with ssadd, but ssget
    doesn't do that.
     
    Tom Smith, Nov 24, 2004
    #6
  7. felixlee

    Jürg Menzi Guest

    Bad hair day...<g>

    Cheers
     
    Jürg Menzi, Nov 24, 2004
    #7
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.