sorting selection sets

Discussion in 'AutoCAD' started by chuck, Nov 10, 2004.

  1. chuck

    chuck Guest

    Why would this not work?
    It appears that I can only create three of the four selection sets, the
    parent set "ss1" and two out of the three "child" sets. Anyone know what I'm
    doing wrong here?
    Thanks

    ____________________________________________________________________________
    _____________

    (defun c:dimsort ()
    (setvar "cmdecho" 0)
    (setq ss1 (ssget "X" '((0 . "DIMENSION"))))
    ; This grabs all dims in drawing.


    (setq ssr (ssadd)) ;This creates a new empty selection set.
    (setq ssa (ssadd)) ;This creates a new empty selection set.
    (setq ssd (ssadd)) ;This creates a new empty selection set.

    (setq R (cons 100 "AcDbRadialDimension"))
    (setq A (cons 100 "AcDb2LineAngularDimension"))
    (setq D (cons 100 "AcDbDiametricDimension"))
    ;Establish what you are looking for in the selection sets.

    (setq index 0)
    (repeat (sslength ss1)
    (setq dimobj (ssname ss1 index)) ; This grabs one dim object from the
    selection set.
    (setq dimguts (entget dimobj)) ; This shows the guts of the dim object.
    (if (member R dimguts)
    (progn (setq ssr (ssadd dimobj ssr))
    (setq ss1 (ssdel dimobj ss1))
    )
    ) ;if radial add to ssr remove from ss1
    (if (member A dimguts)
    (progn (setq ssa (ssadd dimobj ssa))
    (setq ss1 (ssdel dimobj ss1))
    )
    ) ;if angularl add to ssa remove from ss1
    (if (member D dimguts)
    (progn (setq ssd (ssadd dimobj ssd))
    (setq ss1 (ssdel dimobj ss1))
    )
    ) ;if diametric add to ssd remove from ss1
    (setq index (1+ index))
    )
    )
    ;should have four selection sets of dimensions
    ;one radial "ssr" one angular "ssa"one diametric "ssd"
    ; and one with all the others "ss1"
     
    chuck, Nov 10, 2004
    #1
  2. I think you're running into trouble because you are deleting items from the
    original selection set
    as you go. When you get to a certain point, your counter incrementally grows
    to beyond
    the number of items left in the selection set and then your call for that
    entity data returns nil.
    Better to just always use the first item in SS1 as SS1 shrinks, or don't
    remove the items from
    SS1 until you are finished.
     
    Michael Bulatovich, Nov 10, 2004
    #2
  3. chuck

    Jeff Guest

    Compare this code to yours and find the errors of your ways ;-)

    (defun c:dimsort (/ A D DIMGUTS DIMOBJ INDEX R); SS1 SSA SSD SSR)
    (setvar "cmdecho" 0)
    (setq ss1 (ssget "X" '((0 . "DIMENSION"))))
    ; This grabs all dims in drawing.


    (setq ssr (ssadd)) ;This creates a new empty selection set.
    (setq ssa (ssadd)) ;This creates a new empty selection set.
    (setq ssd (ssadd)) ;This creates a new empty selection set.

    (setq R (cons 100 "AcDbRadialDimension"))
    (setq A (cons 100 "AcDb2LineAngularDimension"))
    (setq D (cons 100 "AcDbDiametricDimension"))
    ;Establish what you are looking for in the selection sets.

    (setq index 0)
    (repeat (sslength ss1)
    (setq dimobj (ssname ss1 index)) ; This grabs one dim object from
    theselection set.
    (setq dimguts (entget dimobj)) ; This shows the guts of the dim object.
    (if (member R dimguts)
    (progn (ssadd dimobj ssr)
    (ssdel dimobj ss1)
    (setq index (1- index))
    )
    ) ;if radial add to ssr remove from ss1
    (if (member A dimguts)
    (progn (ssadd dimobj ssa)
    (ssdel dimobj ss1)
    (setq index (1- index))
    )
    ) ;if angularl add to ssa remove from ss1
    (if (member D dimguts)
    (progn (ssadd dimobj ssd)
    (ssdel dimobj ss1)
    (setq index (1- index))
    )
    ) ;if diametric add to ssd remove from ss1
    (setq index (1+ index))
    )
    )
    ;should have four selection sets of dimensions
    ;one radial "ssr" one angular "ssa"one diametric "ssd"
    ; and one with all the others "ss1"
     
    Jeff, Nov 10, 2004
    #3
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.