Author Topic: (code) Dealing with pre-selected entities  (Read 3417 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
(code) Dealing with pre-selected entities
« on: April 08, 2004, 07:42:50 AM »
Some examples:
Code: [Select]

;;; dealing with pre-selected entities
;;; example;
;;; select entities in the dwg then enter 'ssda', the pre-selected
;;; entities will be erased. Now try it by NOT selecting anything
;;; first, the program prompts you for a selection
(defun c:ssda (/ ss)
  (setq ss (last (ssgetfirst)))
  (if (not ss)
    (setq ss (ssget))
    )
  (if ss
    (command "._erase" ss "")
    )
  (princ)
  )

;;; clear pre-selected entities
(defun c:ssdb ( / ss)
  (sssetfirst nil)
  (if (setq ss (ssget))
    (command "._erase" ss "")
    )
  (princ)
  )

;;; erase all entities in current dwg that match selected
;;; entity
(defun c:ssdc (/ ent ss)
  (if (setq ent (entsel "\nSelect an Entity to Filter: "))
    (if (setq ss (ssget "x" (list (assoc 0 (entget (car ent))))))
      (command "._erase" ss "")
      )
    )
  (princ)
  )

;;; put them all togther
(defun c:ssdd (/ ss ent)
  (setq ss (last (ssgetfirst)))

  (if ss
    (cond
      ((= (sslength ss) 1)
       (setq ss (ssget "x" (list (assoc 0 (entget (ssname ss 0))))))
       )
      ((> (sslength ss) 1)
       (sssetfirst nil)
       (if (setq ent (entsel "\nSelect an Entity to Filter: "))
         (setq ss (ssget "x" (list (assoc 0 (entget (car ent))))))
         ); if
       )
      ); cond
    ; else if
    (progn
      (if (setq ent (entsel "\nSelect an Entity to Filter: "))
        (setq ss (ssget "x" (list (assoc 0 (entget (car ent))))))
        )
      ); progn
    ); if

  (if ss
    (command "._erase" ss "")
    )

  (princ)

  )
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
(code) Dealing with pre-selected entities
« Reply #1 on: April 08, 2004, 09:28:57 AM »
Roll your own ssget
Code: [Select]

;;; returns a selection set or nil
;;;
(defun my-ssget (clear / ss)

  (gc); take out the garbage

  ;; collect anything selected
  (setq ss (last (ssgetfirst)))

  (cond (clear
         (sssetfirst nil)
         (setq ss (ssget))
         ); 1st cond
        ((and ss) ss
         ); 2nd cond
        ((not ss)
         (setq ss (ssget))
         ); 3rd cond
        )
  )

;;; 1st cond
;;; if 'clear' is not nil then clear any selected entities
;;; and start over by prompting for a selection set
;;; example;
;;; (setq ss (my-ssget T)) clears any pre-selected items
;;; (setq ss (my-ssget nil)) does not
;;;
;;; 2nd cond
;;; if ss is not nil then it must contain selected entities,
;;; so return 'ss' as the selection set
;;;
;;; 3rd cond
;;; ss is nil there are no pre-selected entities, so prompt
;;; the user for a selection.
TheSwamp.org  (serving the CAD community since 2003)

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
(code) Dealing with pre-selected entities
« Reply #2 on: April 12, 2004, 02:36:59 PM »
Hey, i think got some code for this situation too.

...Hold on, ill go try to find it. ...Found it!
Code: [Select]
;;;===================================================================;
;;; Get-EntSelected                                                   ;
;;;-------------------------------------------------------------------;
;;; This procedure will offer a way for the programer to get an       ;
;;; entity or entities already slected on the screen before the       ;
;;; program took control. This program was intended for use in an     ;
;;; ActiveX program. I have chosen not to use the "Pickfirst" method  ;
;;; in accomplishing this task because I wanted a way to do this even ;
;;; if the "pickfirst" variable was toggled to zero. If no entity is  ;
;;; currently selected on the screen, this function will prompt the   ;
;;; end user to select an entity.                                     ;
;;;                                                                   ;
;;; Author: John Kaul                                                 ;
;;;                                                                   ;
;;; Returns: Either previously selected entity, a selected entity, or ;
;;;          a list of selected entities.                             ;
;;;                                                                   ;
;;; Usage: (vlax-ename->vla-object (Get-EntSelcted))                  ;
;;;                                                                   ;
;;;-------------------------------------------------------------------;
;;; Version: 1.1 Added the ability to have more then one selected     ;
;;;              objects on the screen.                               ;
;;;===================================================================;
(defun Get-EntSelected (/ x cntr xlength xlist)
  (setq x (cadr (ssgetfirst)))
  (if x (setq xlength (sslength x)))
  (cond
    ((= xlength 1)
     (setq x (ssname x 0))
     (sssetfirst nil)
     (redraw x 3))
    ((> xlength 1)
     (setq cntr xlength)
     (cond
       ((>= cntr 2)
        (setq cntr (1- xlength))
        (while (>= cntr 0)
               (setq xlist (cons (ssname x cntr) xlist)
                     cntr  (1- cntr)))
        (foreach a xlist (progn (sssetfirst nil) (redraw a 3))))))
    ;; Might not want to have this function do any selecting for you.
    ;; if you do, un-comment this block.
;;;      ((= xlength nil)
;;;       (while (not (setq x (entsel "\nselect object: "))))
;;;       (setq x (car x))
;;;       (sssetfirst nil)
;;;       (redraw x 3))
    )
  (if (= nil xlist) x xlist)
)


How's that?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
(code) Dealing with pre-selected entities
« Reply #3 on: April 12, 2004, 02:44:48 PM »
I just found this one too. (Its small, but...)

Code: [Select]
;;;===================================================================;
;;; Get-EntSelcted                                                    ;
;;;-------------------------------------------------------------------;
;;; This function will offer a way for the programer to tell if any   ;
;;; items are selected on the screen before the program runs.         ;
;;;                                                                   ;
;;; Author: John Kaul                                                 ;
;;;                                                                   ;
;;; Usage: (if (not (Slected-p))                                      ;
;;;          (vlax-ename->vla-object (car (entsel))))                 ;
;;;===================================================================;
(defun Slected-p ()
  (and (cadr (ssgetfirst)))
 )
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org