Author Topic: Question about selecting an object from a point  (Read 5645 times)

0 Members and 3 Guests are viewing this topic.

Brick_top

  • Guest
Question about selecting an object from a point
« on: December 28, 2010, 06:02:12 AM »
I'm trying to select an object from a selected point, I'm able to do it but only if the object is on screen

Here is the code
Code: [Select]
(defun c:bd ()
   (setq pt1 (getpoint "\nPonto para detectar ilha:")
         pre 0.0001
         xpt1 (car pt1)
         ypt1 (cadr pt1)
         ss1 nil
   )
   (while       
       (if
          (= (setq ss1 (ssget (list xpt1 ypt1))) nil)
              (setq xpt1 (- xpt1 pre))
         
       );if                 
   );while
)

I'm only testing in "-x" direction.

How can I select the object if it is "off screen"?

Off Topic - Also would it be better to stop creating topics? I have three already with this one

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Question about selecting an object from a point
« Reply #1 on: December 28, 2010, 06:09:17 AM »
Off Topic - Also would it be better to stop creating topics? I have three already with this one

I assume you mean 'three including this one'

That seems fine to me ... If they were all related to the same topic someone will probably have a little whinge though.

The topic is well named, so that will save you some grief. ;)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Brick_top

  • Guest
Re: Question about selecting an object from a point
« Reply #2 on: December 28, 2010, 06:11:33 AM »
I found out that I can just zoom to extents and it will select the object with no problem.

So this is not a problem anymore

It would be interesting to see if anyone has the answer though

Thanks a lot

Brick_top

  • Guest
Re: Question about selecting an object from a point
« Reply #3 on: December 28, 2010, 06:13:43 AM »
Off Topic - Also would it be better to stop creating topics? I have three already with this one

I assume you mean 'three including this one'

That seems fine to me ... If they were all related to the same topic someone will probably have a little whinge though.

The topic is well named, so that will save you some grief. ;)

Yeah that was what I meant!

My english could be better

Thanks for the clarification

Lee Mac

  • Seagull
  • Posts: 12923
  • London, England
Re: Question about selecting an object from a point
« Reply #4 on: December 28, 2010, 12:53:29 PM »
Another way would be to use nentselp

DEVITG

  • Bull Frog
  • Posts: 481
Re: Question about selecting an object from a point
« Reply #5 on: December 31, 2010, 06:04:17 PM »
I'm trying to select an object from a selected point, I'm able to do it but only if the object is on screen

Here is the code
Code: [Select]
(defun c:bd ()
   (setq pt1 (getpoint "\nPonto para detectar ilha:")
         pre 0.0001
         xpt1 (car pt1)
         ypt1 (cadr pt1)
         ss1 nil
   )
   (while       
       (if
          (= (setq ss1 (ssget (list xpt1 ypt1))) nil)
              (setq xpt1 (- xpt1 pre))
         
       );if                 
   );while
)

I'm only testing in "-x" direction.

How can I select the object if it is "off screen"?

Off Topic - Also would it be better to stop creating topics? I have three already with this one


SSGET works only with object on screen , except by( ssget  ¨X¨

You can do a ZOOM center point

Location @ Córdoba Argentina Using ACAD 2019  at Window 10

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Question about selecting an object from a point
« Reply #6 on: January 06, 2011, 06:33:05 PM »
My suggestion is to use something like the following (unless there is more than one object at the point):
Code: [Select]
(defun c:bd ()
   (setq pt1 (getpoint "\nPonto para detectar ilha:")
         pre 0.0001
         xpt1 (car pt1)
         ypt1 (cadr pt1)
         ss1 nil
   )
   (while       
       (if
          (= (setq ss1 (nentselp "" (list cpt1 ypt1)) nil)
              (setq xpt1 (- xpt1 pre))
         
       );if                 
   );while
)
This should select items off the screen as well.

Brick_top

  • Guest
Re: Question about selecting an object from a point
« Reply #7 on: January 07, 2011, 04:21:06 AM »
thats interesting, i have to look into that nentselp "" part, I don't know about.

but yeah there is one more object at that point, and that is a closed polyline. I have to check if pt1 is inside the selected closed polyline and if not select another one.

I found a routine that checks if a point is inside a closed polyline but, I'll have to understand how it works

thanks for all the help guys
« Last Edit: January 07, 2011, 05:27:02 AM by Brick_top »

Brick_top

  • Guest
Re: Question about selecting an object from a point
« Reply #8 on: January 07, 2011, 04:53:12 AM »
apparently it isn't working, I typed the missing parenthesis and corrected the misspelled variable
Code: [Select]
(defun c:bd ( / ss1)
   (setq pt1 (getpoint "\nPonto para detectar ilha:")
         pre 0.01
         xpt1 (car pt1)
         ypt1 (cadr pt1)
   )
   (while       
       (if
          (= (setq ss1 (nentselp "" (list xpt1 ypt1))) nil)
              (setq xpt1 (- xpt1 pre))
         
       );if                 
   );while
)

it works if the object is onscreen
« Last Edit: January 07, 2011, 05:14:19 AM by Brick_top »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Question about selecting an object from a point
« Reply #9 on: January 07, 2011, 05:10:14 AM »
apparently it isn't working,

Brick_top
Do you know what that code is doing ??
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Brick_top

  • Guest
Re: Question about selecting an object from a point
« Reply #10 on: January 07, 2011, 05:19:26 AM »
I haven't really understood the part of the nentselp.

It is changing the value of the x coordinate until it selects an object. I wrote the code, I just don't understand the tip about the nentselp.

edit - but I guess that the user that gave the tip was trying to tell me how to select the object if it is offscreen

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Question about selecting an object from a point
« Reply #11 on: January 07, 2011, 05:31:53 AM »

Does it select objects on screen ??
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Brick_top

  • Guest
Re: Question about selecting an object from a point
« Reply #12 on: January 07, 2011, 05:35:25 AM »
yes it does

I guess I can just do a zoomextents
« Last Edit: January 07, 2011, 05:48:06 AM by Brick_top »

Brick_top

  • Guest
Re: Question about selecting an object from a point
« Reply #13 on: January 07, 2011, 05:45:09 AM »
I tried doing zoom extents
Code: [Select]
(defun c:bd ()
   (setq pt1 (getpoint "\nPonto para detectar ilha:")
         pre 0.01
         xpt1 (car pt1)
         ypt1 (cadr pt1)
         ss1 nil
   )
 (command "zoom" "E")
   (while       
       (if
          (= (setq ss1 (ssget (list xpt1 ypt1))) nil)
              (setq xpt1 (- xpt1 pre))           
       );if                 
   );while
 (command "zoom" "P")

)

But I guess this introduces some kind of precision error since it selects objects in other directions

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Question about selecting an object from a point
« Reply #14 on: January 07, 2011, 05:50:11 AM »
yes,
Selecting objects using a point off screen has always been an issue.

regarding your code ... I'll be back is a bit ..
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Question about selecting an object from a point
« Reply #15 on: January 07, 2011, 05:58:31 AM »
Have a play with something like this
Code: [Select]
[color=green];; bd1.lsp[/color]
(defun [color=blue]c:bd1[/color] (/ Limit Pre Pt1 Sel Xpt1 Ypt1)
  (vl-load-com)
  [color=green];; sample by kdub@theSwamp
  ;; Select an object at or in in a relative position to the selected Point.
  ;; If the Object is not found, change the point negative X vector 0.01
  ;; untill the search limit is reached
  ;; Will only select object if the point is ON screen.[/color]
  (setq pt1   (getpoint [color=Maroon]"\nPoint to Test:"[/color])
        pre   0.01
        xpt1  (car pt1)
        ypt1  (cadr pt1)
        limit (- xpt1 15)
  )
  (vl-cmdf [color=Maroon]"zoom"[/color] [color=Maroon]"E"[/color])
  (while (and (> xpt1 limit)
              (not (setq SEL (nentselp [color=Maroon]""[/color] (list xpt1 ypt1))))
         )
    (setq xpt1 (- xpt1 pre))
  )
  (vl-cmdf [color=Maroon]"zoom"[/color] [color=Maroon]"P"[/color])
  SEL
)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Brick_top

  • Guest
Re: Question about selecting an object from a point
« Reply #16 on: January 07, 2011, 06:17:17 AM »
thanks a lot for your code

Unfortunately I've not been able to understand if it is working or not

It prompts me to an entity name and a coordinate of the point I picked right?

Brick_top

  • Guest
Re: Question about selecting an object from a point
« Reply #17 on: January 07, 2011, 06:25:41 AM »
if I remove the vl-cmdf parts it gives me the coordinate of the object I want to select

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Question about selecting an object from a point
« Reply #18 on: January 07, 2011, 06:27:24 AM »
Retutns the value of SEL

If it works :
returns the entity and pickpoint from nentselp

if it fails :
returns nil

//-----------------------
The entity MAY NOT be at the point selected.

Please note  the selection functions return the point selected but select onjects inside the pickbox.

The example shown is using a circle with a 10.0 radius ... the selected point was (-9.87 0.0 0.0) and the circle circumference was just in the pickbox.

There are several ways to determine the actual entity point  ... but will not be required if you only want the entity.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Question about selecting an object from a point
« Reply #19 on: January 07, 2011, 06:31:44 AM »
if I remove the vl-cmdf parts it gives me the coordinate of the object I want to select


NO !

removing the Zoom commands will just stop the point being selected if it's off screen.


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Brick_top

  • Guest
Re: Question about selecting an object from a point
« Reply #20 on: January 07, 2011, 06:34:31 AM »
I removed the declared variable sel to test from the command line what entity it was but it isn't the one I want

But if I remove the vl-cmdf parts it selects the entity I expect it to select, it if is on screen

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Question about selecting an object from a point
« Reply #21 on: January 07, 2011, 06:39:14 AM »
I removed the declared variable sel to test from the command line what entity it was but it isn't the one I want

But if I remove the vl-cmdf parts it selects the entity I expect it to select, it if is on screen

Everything will work just as you expect it to, unless your expectations are incorrect. 
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Question about selecting an object from a point
« Reply #22 on: January 07, 2011, 06:45:38 AM »
But if I remove the vl-cmdf parts it selects the entity I expect it to select, it if is on screen

I will select the correct entity with the zoom commands left in ..

I removed the declared variable sel to test from the command line what entity it was but it isn't the one I want

Care to explain this in more detail. ?
Is the entity within the 'limit' distance as nominated in the code ?
(if a limit is not expressed, the code will continue untill it runs out of memory or finds something 5 kilometers away)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Brick_top

  • Guest
Re: Question about selecting an object from a point
« Reply #23 on: January 07, 2011, 06:47:41 AM »
I guess I have found out what I was doing wrong

I was testing without a closed object, when I try your routine with a closed polyline it works

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Question about selecting an object from a point
« Reply #24 on: January 07, 2011, 06:51:04 AM »
I guess I have found out what I was doing wrong

I was testing without a closed object, when I try your routine with a closed polyline it works

NO!

a closed object is NOT required.


Please don't make assumptions based on limited and possibly faulty testing ... you'll remain sane longer :)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Brick_top

  • Guest
Re: Question about selecting an object from a point
« Reply #25 on: January 07, 2011, 06:53:42 AM »
but when I don't use a closed object it "doesn't select the next object in the -x direction" In case this was what it was expected to do

I'm sorry for all the trouble

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Question about selecting an object from a point
« Reply #26 on: January 07, 2011, 06:55:30 AM »
but when I don't use a closed object it doesn't select the next object in the -x direction

I'm sorry for all the trouble

Can you post a drawing of the data you've using, and a description of what you expect.

What do you mean NEXT object ... there was never discussion of a NEXT object  :|
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Brick_top

  • Guest
Re: Question about selecting an object from a point
« Reply #27 on: January 07, 2011, 07:02:38 AM »
I'm sorry for not being clear enough

I was trying to select the next object in the -x direction from picked point



« Last Edit: January 07, 2011, 07:06:20 AM by Brick_top »

Brick_top

  • Guest
Re: Question about selecting an object from a point
« Reply #28 on: January 07, 2011, 07:05:55 AM »
Here is the drawing

Brick_top

  • Guest
Re: Question about selecting an object from a point
« Reply #29 on: January 07, 2011, 07:07:58 AM »
there might be a precision error, because if I test this in a drawing with a smaller zoom extents area it works as I was expecting, which was for it to select the "next" object in the -x direction from the picked point

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Question about selecting an object from a point
« Reply #30 on: January 07, 2011, 07:10:47 AM »

I'm not going to waste my time looking at a drawing with a couple of thousand entitys in it and no description of what you are trying to achieve.

please post a simple example of what you are trying to do.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Brick_top

  • Guest
Re: Question about selecting an object from a point
« Reply #31 on: January 07, 2011, 07:18:19 AM »
This was the drawing in which I was doing the tests since I thought I didn't have to use any specific drawing to test it.

I was expecting to select the next object the routine would found in the -x direction from the picked point.

The real usage I wanted it for is already working, which as for it to select a closed polyline surrounding the picked point.

I'm really sorry if I made some confusion because of being too vague and not giving the correct information and wasting your time






Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Question about selecting an object from a point
« Reply #32 on: January 07, 2011, 07:26:12 AM »

I surpose there's a lesson there for all of us.

I'm pleased you have what you want.


//-----------

OFF TOPIC :
I don't think your client will get those cars out of the garage  :-)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Brick_top

  • Guest
Re: Question about selecting an object from a point
« Reply #33 on: January 07, 2011, 09:17:44 AM »
Thanks for your patience!

yeah it will be hard to get the cars out, I'm working on it still