TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Brick_top on December 28, 2010, 06:02:12 AM

Title: Question about selecting an object from a point
Post by: Brick_top 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
Title: Re: Question about selecting an object from a point
Post by: Kerry 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. ;)
Title: Re: Question about selecting an object from a point
Post by: Brick_top 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
Title: Re: Question about selecting an object from a point
Post by: Brick_top 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
Title: Re: Question about selecting an object from a point
Post by: Lee Mac on December 28, 2010, 12:53:29 PM
Another way would be to use nentselp
Title: Re: Question about selecting an object from a point
Post by: DEVITG 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

Title: Re: Question about selecting an object from a point
Post by: cmwade77 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.
Title: Re: Question about selecting an object from a point
Post by: Brick_top 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
Title: Re: Question about selecting an object from a point
Post by: Brick_top 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
Title: Re: Question about selecting an object from a point
Post by: Kerry on January 07, 2011, 05:10:14 AM
apparently it isn't working,

Brick_top
Do you know what that code is doing ??
Title: Re: Question about selecting an object from a point
Post by: Brick_top 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
Title: Re: Question about selecting an object from a point
Post by: Kerry on January 07, 2011, 05:31:53 AM

Does it select objects on screen ??
Title: Re: Question about selecting an object from a point
Post by: Brick_top on January 07, 2011, 05:35:25 AM
yes it does

I guess I can just do a zoomextents
Title: Re: Question about selecting an object from a point
Post by: Brick_top 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
Title: Re: Question about selecting an object from a point
Post by: Kerry 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 ..
Title: Re: Question about selecting an object from a point
Post by: Kerry 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
)
Title: Re: Question about selecting an object from a point
Post by: Brick_top 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?
Title: Re: Question about selecting an object from a point
Post by: Brick_top 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
Title: Re: Question about selecting an object from a point
Post by: Kerry 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.
Title: Re: Question about selecting an object from a point
Post by: Kerry 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.


Title: Re: Question about selecting an object from a point
Post by: Brick_top 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
Title: Re: Question about selecting an object from a point
Post by: Kerry 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. 
Title: Re: Question about selecting an object from a point
Post by: Kerry 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)
Title: Re: Question about selecting an object from a point
Post by: Brick_top 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
Title: Re: Question about selecting an object from a point
Post by: Kerry 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 :)
Title: Re: Question about selecting an object from a point
Post by: Brick_top 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
Title: Re: Question about selecting an object from a point
Post by: Kerry 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  :|
Title: Re: Question about selecting an object from a point
Post by: Brick_top 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



Title: Re: Question about selecting an object from a point
Post by: Brick_top on January 07, 2011, 07:05:55 AM
Here is the drawing
Title: Re: Question about selecting an object from a point
Post by: Brick_top 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
Title: Re: Question about selecting an object from a point
Post by: Kerry 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.
Title: Re: Question about selecting an object from a point
Post by: Brick_top 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





Title: Re: Question about selecting an object from a point
Post by: Kerry 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  :-)
Title: Re: Question about selecting an object from a point
Post by: Brick_top 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