Author Topic: Determine coordinates selection windows ssget  (Read 3325 times)

0 Members and 1 Guest are viewing this topic.

Lupo76

  • Bull Frog
  • Posts: 343
Determine coordinates selection windows ssget
« on: April 11, 2015, 09:21:57 AM »
Hello everyone,

after starting the following line of code:

(setq slobj (ssget))
how can I determine the coordinates of the points selected by the user to specify the selection window?

Alternatively I can get around this by determining the coordinates of the point chosen by the user with the function (entsel). Unfortunately in this case I want the coordinates of this point, even when the user has not selected any item.

Do you have any idea?

ribarm

  • Gator
  • Posts: 3297
  • Marko Ribar, architect
Re: Determine coordinates selection windows ssget
« Reply #1 on: April 11, 2015, 09:55:50 AM »
Use (getpoint) and follow with (getcorner) functions to firstly obtain points...
Then use (ssget "_W" llpt urpt)...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lupo76

  • Bull Frog
  • Posts: 343
Re: Determine coordinates selection windows ssget
« Reply #2 on: April 11, 2015, 09:59:39 AM »
Use (getpoint) and follow with (getcorner) functions to firstly obtain points...
Then use (ssget "_W" llpt urpt)...

I have already thought of this solution but unfortunately in my context is not the right way.
I need to check if the user has selected an object directly, or if you specified a selection window  :-(

ribarm

  • Gator
  • Posts: 3297
  • Marko Ribar, architect
Re: Determine coordinates selection windows ssget
« Reply #3 on: April 11, 2015, 10:07:49 AM »
I need to check if the user has selected an object directly, or if you specified a selection window  :-(

Then use (setq ss (ssget))... After selection was made examine list obtained after :

(if ss (ssnamex ss))

If it returns coordinates of picked window, then selection was made with picking window, and if it returns just single point coordinates then selection was made by picking that entity directly... If its empty window selection, or empty pick selection, ss variable will be nil and then it will be pointless to examine ss via (ssnamex)...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lupo76

  • Bull Frog
  • Posts: 343
Re: Determine coordinates selection windows ssget
« Reply #4 on: April 11, 2015, 10:09:57 AM »
I managed to solve by myself :-)
instead of using (entsel) I can use:

Code: [Select]
(ssget "_+.:E:S")
(setq p1 (getvar 'lastpoint))
(setq p2 (getcorner p1)
(setq selobj (ssget "_C" p1 p2))

Lupo76

  • Bull Frog
  • Posts: 343
Re: Determine coordinates selection windows ssget
« Reply #5 on: April 11, 2015, 10:13:01 AM »
I need to check if the user has selected an object directly, or if you specified a selection window  :-(

Then use (setq ss (ssget))... After selection was made examine list obtained after :

(if ss (ssnamex ss))

If it returns coordinates of picked window, then selection was made with picking window, and if it returns just single point coordinates then selection was made by picking that entity directly... If its empty window selection, or empty pick selection, ss variable will be nil and then it will be pointless to examine ss via (ssnamex)...

Thank You !!
I only know ssname.
I did not know namex

Lupo76

  • Bull Frog
  • Posts: 343
Re: Determine coordinates selection windows ssget
« Reply #6 on: April 11, 2015, 12:49:19 PM »
I thought I had solved all the problems but ......

I need to determine if the user pressed enter.
In summary I have to see if after starting (ssget), the user:

- Has selected a single object
- Has selected a group of selection
- Has created a selection window empty
- Has hit enter.

For the first three points I have no problems, I know how to do, but how can I determine if the user pressed "enter"?

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Determine coordinates selection windows ssget
« Reply #7 on: April 11, 2015, 02:06:44 PM »
how can I determine if the user pressed "enter"?

As far as I am aware, I don't believe it is possible to distinguish between the user not making a selection and the user pressing ENTER at the prompt, since in both cases the ssget prompt is completed using either ENTER or right-click (which is equivalent to ENTER); you could only differentiate between an empty selection and a 'dismissal' of the prompt if the user were to press ESC and force an error which you could subsequently catch.

A related thread:
http://www.theswamp.org/index.php?topic=43926

Lupo76

  • Bull Frog
  • Posts: 343
Re: Determine coordinates selection windows ssget
« Reply #8 on: April 12, 2015, 05:05:07 AM »
A related thread:
http://www.theswamp.org/index.php?topic=43926

Thanks to your link, I solved using (= (getvar "ERRNO") 52) to determine when the user presses enter.
Here is my complete code:

Code: [Select]
(defun c:test (/ var snapcorr ss next)
  ;*************************************
  (setq var (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (setq snapcorr (getvar "OSMODE"))
  (setvar "OSMODE" 0)
  ;*************************************

  (princ "\nSelect: ")
  (setq ss (ssget ":S"))
  (setq next T)
  (while (= next T)
    (progn
      (if ss
        (if (= (sslength ss) 1)
          (progn
            (alert "I have selected only an object, then I continue again.")
            (setq ss (ssget ":S"))
          )
          (progn
            (alert "I have selected more object, then I continue again")
            (setq ss (ssget ":S"))
          )
        )
        (progn
          (if (/= (getvar "ERRNO") 52)
            (progn
              (alert "I don't have selected any objects, then I continue again")
              (setq ss (ssget ":S"))
            )
            (progn
              (alert "I have press Enter, then END")
              (setq next nil)
            )
          )
        )
      )
    )
  )   

  ;*************************************
  (setvar "OSMODE" snapcorr)
  (setvar "cmdecho" var)
  (princ)
  ;*************************************
)