Author Topic: Test to see if user has something selected  (Read 10032 times)

0 Members and 1 Guest are viewing this topic.

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Test to see if user has something selected
« on: September 15, 2003, 05:00:56 PM »
This function will test to see if the user has something selected on the screen when your program takes control.

As featured in the afralisp news letter.
Code: [Select]

;;;===================================================================;
;;; Selected-p                                                        ;
;;;-------------------------------------------------------------------;
;;; This function will test to see if something is selected on screen ;
;;;                                                                   ;
;;; Returns: T or nil                                                 ;
;;;                                                                   ;
;;; Author: John Kaul                                                 ;
;;;                                                                   ;
;;; Usage: (if (not (Slected-p))                                      ;
;;;          (vlax-ename->vla-object (car (entsel))))                 ;
;;;===================================================================;
(defun Slected-p ()
  (and (cadr (ssgetfirst)))
 )


...more to come.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Test to see if user has something selected
« Reply #1 on: September 16, 2003, 07:12:24 AM »
Very nice John. You don't mind id I use that....... right? :D
Code: [Select]
;;; FUNCTION
;;; catchs any errors in selection process
;;; returns a valid VLA-OBJECT or nil
;;; *requires* 'Selected-p' by John Kaul
;;;
;;; ARGUMENTS
;;; none
;;;
;;; USAGE
;;; (setq obj (MST-Select-It))
;;;
;;; PLATFORMS
;;; 2000+
;;;
;;; AUTHOR
;;; Copyright© 2003 Mark S. Thomas
;;; mark.thomas@theswamp.org
;;;
;;; VERSION
;;; 1.0 Tue Sep 16, 2003 07:04:21
(defun MST-Select-It (/ obj)
  (if
    (vl-catch-all-error-p
      (if
        (not (Slected-p))
        (setq obj
              (vl-catch-all-apply
                'vlax-ename->vla-object
                (list (car (entsel)))
                )
              )
        )
      )
    (setq obj nil)
    )
  obj
  )
TheSwamp.org  (serving the CAD community since 2003)

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Test to see if user has something selected
« Reply #2 on: September 16, 2003, 11:02:16 AM »
Sure. But i got another one for ya. (I was gonna wait to show you this, but ...)

Code: [Select]

;;;===================================================================;
;;; Get-EntSelcted                                                    ;
;;;-------------------------------------------------------------------;
;;; This function 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-EntSelcted (/ 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))))))
    ((= xlength nil)
     (while (not (setq x (entsel "\nselect object: "))))
     (setq x (car x))
     (sssetfirst nil)
     (redraw x 3)))
  (if (= nil xlist) x xlist)
)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Test to see if user has something selected
« Reply #3 on: September 16, 2003, 12:46:26 PM »
So I take it's not ready for general use.

2 lines selected
(setq a (vlax-ename->vla-object (Get-EntSelcted)))
; error: bad argument type: lentityp (<Entity name: 7ef5bd70> <Entity name: 7ef5bd68>)

:D

Or am I using it wrong?

2 lines selected
(Get-EntSelcted)
(<Entity name: 7ef5bd70> <Entity name: 7ef5bd68>)

guess I was  :oops:

Ok, it's going in the tool box...
thanks 7
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Test to see if user has something selected
« Reply #4 on: September 16, 2003, 12:50:37 PM »
One question, is the name really supposed to be Get-EntSelcted ?

Sorry, but you know how that stuff bugs me :D
TheSwamp.org  (serving the CAD community since 2003)

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Test to see if user has something selected
« Reply #5 on: September 16, 2003, 01:20:33 PM »
Quote from: Mark Thomas
One question, is the name really supposed to be Get-EntSelcted ?

Sorry, but you know how that stuff bugs me :D
Yeah, that kinda bothers me too. ...I wish we had the source code so we can chage it.  

 :P

(Sorry, I had to do that.) Change it to what ever you want, that is just as i had it in my "junk file" so i can find it faster with a search.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org