Author Topic: Selection between 2 points but excluding any objects on the exact points.  (Read 7115 times)

0 Members and 1 Guest are viewing this topic.

LSElite

  • Newt
  • Posts: 65
Hey All

I want to select all objects between 2 points however I want to exclude all objects that are directly under either of the points.

so if the 2 points are midpoints of 2 lines I would like the 2 lines at the beginning and end to be excluded, or if there are multiple objects under the points I want them all be excluded from the selection.

Anyone have any ideas?

Cheers
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw

Lee Mac

  • Seagull
  • Posts: 12940
  • London, England
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #1 on: November 28, 2015, 06:52:07 PM »
Option 1: Calculate two points a small distance inside of the two given points, and then obtain a Fence selection using ssget with the two new points.

Option 2: Obtain a Fence selection using ssget with the two points, and a point selection using each point. Remove entities in the Fence selection which are members of the other two selectons.

LSElite

  • Newt
  • Posts: 65
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #2 on: November 28, 2015, 07:13:51 PM »
I had option 1 in mind but it seemed a bit tedious.
Option 2 is quite clever, perhaps a little slower on execution but i think it will be simpler to program.

Cheers LM
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw

LSElite

  • Newt
  • Posts: 65
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #3 on: November 28, 2015, 07:52:52 PM »
Hey Lee

Hopefully this is a quick one, how can I select all objects on a point?
Can i do this through point selection ":E", or must I use a window selection a little bigger than the point?
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw

Lee Mac

  • Seagull
  • Posts: 12940
  • London, England
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #4 on: November 29, 2015, 01:45:29 PM »
Hopefully this is a quick one, how can I select all objects on a point?
Can i do this through point selection ":E", or must I use a window selection a little bigger than the point?

You could use:
Code: [Select]
(ssget pt)
to select objects which pass through the point 'pt', though, to allow some tolerance you may want to use something like:
Code: [Select]
(ssget "_C" (mapcar '- pt '(1e-3 1e-3)) (mapcar '+ pt '(1e-3 1e-3)))

LSElite

  • Newt
  • Posts: 65
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #5 on: November 30, 2015, 04:42:32 AM »
I think im going to lose my mind with this one.

So i am trying to make a function from LM's idea but it wont work.
It keeps spitting out:
** Error: too many arguments **

I have a neaking suspicion it has something to do with the view extents so I have been playing with the view window but to no avail.

Anyone have any ideas before I lose my last marble?

Code - Auto/Visual Lisp: [Select]
  1. (defun ObjectIdentification (p1 p2 / ss1 ss2 ss3 ct)
  2.         (setq SelRange 10)
  3.         (command "zoom" "W" p1 p2)
  4.         (if (setq ss1 (ssget "_F" (list p1 p2)))
  5.                 (progn
  6.                         (command "zoom" "o" "p" "")
  7.                         (if (setq ss2 (ssget "_C" (mapcar '- pt '(1e-3 1e-3)) (mapcar '+ pt '(1e-3 1e-3))))
  8.                                 (progn
  9.                                         (repeat (setq ct (sslength ss2))
  10.                                                 (setq ss1 (ssdel (ssname ss2 ct) ss1))
  11.                                                 (setq ct (1- ct))
  12.                                         )
  13.                                 )
  14.                         )
  15.                         (if (setq ss3 (ssget "_C" (mapcar '- pt '(1e-3 1e-3)) (mapcar '+ pt '(1e-3 1e-3))))
  16.                                 (progn
  17.                                         (repeat (setq ct (sslength ss3))
  18.                                                 (setq ss1 (ssdel (ssname ss3 ct) ss1))
  19.                                                 (setq ct (1- ct))
  20.                                         )
  21.                                 )
  22.                         )
  23.                 )
  24.         )
  25.         princ ss1
  26. )
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw

Lee Mac

  • Seagull
  • Posts: 12940
  • London, England
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #6 on: November 30, 2015, 05:09:50 AM »
Code - Auto/Visual Lisp: [Select]
  1. (setq ss2 (ssget "_C" (mapcar '- pt '(1e-3 1e-3)) (mapcar '+ pt '(1e-3 1e-3))))
Code - Auto/Visual Lisp: [Select]
  1. (setq ss3 (ssget "_C" (mapcar '- pt '(1e-3 1e-3)) (mapcar '+ pt '(1e-3 1e-3))))

You have used variables p1 & p2 in your function, therefore the variable pt will be nil.

Code - Auto/Visual Lisp: [Select]
  1. (ssname ss2 ct)

Variable ct will need to be decremented first, as selection set indexes are zero-based.

Code - Auto/Visual Lisp: [Select]
  1. (setq ss1 (ssdel (ssname ss2 ct) ss1))

Be careful with this, as ssdel will return nil if (ssname ss2 ct) is not a member of ss1, thereby redefining ss1 to nil.
« Last Edit: November 30, 2015, 05:12:55 AM by Lee Mac »

LSElite

  • Newt
  • Posts: 65
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #7 on: November 30, 2015, 05:57:03 AM »
LM to the rescue again, Cheers mate.  :-D

Be careful with this, as ssdel will return nil if (ssname ss2 ct) is not a member of ss1, thereby redefining ss1 to nil.
This advice probably just saved me a few hours of programming.
Do you know of any efficient ways of removing one selection set from another or a way of bypassing this problem with ssdel?
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #8 on: November 30, 2015, 06:02:26 AM »

Do you know of any efficient ways of removing one selection set from another or a way of bypassing this problem with ssdel?

Something like this is a bit crude, but it may do the job for you.

Code - Auto/Visual Lisp: [Select]
  1.  
  2.   (if (and ss1 ss0)
  3.     (progn (vl-cmdf "_.Select" ss0 "_Remove" ss1 "")
  4.            (setq ss0 (ssget "_P"))
  5.     )
  6.   )
  7.   (if (and ss2 ss0)
  8.     (progn (vl-cmdf "_.Select" ss0 "_Remove" ss2 "")
  9.            (setq ss0 (ssget "_P"))
  10.     )
  11.   )
  12.   (if (setq sslen (sslength ss0))
  13.     (alert (strcat "Selected : " (itoa sslen)))
  14.   )
  15.  
  16.  
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: Selection between 2 points but excluding any objects on the exact points.
« Reply #9 on: November 30, 2015, 06:07:38 AM »

LSElite,
Keep in mind that Lee may be working imperial measurements

His 1e-3
may be different to your 1e-3
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.

LSElite

  • Newt
  • Posts: 65
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #10 on: November 30, 2015, 06:24:23 AM »
Something like this is a bit crude, but it may do the job for you.
Cheers mate, crude works for me.  :-)

Keep in mind that Lee may be working imperial measurements

His 1e-3
may be different to your 1e-3
Cheers for the heads up, something is givng me some wierd output here, I think that may be it.
To be honest I dont know how the 1e-3 actually works in lisp, is it an exponent or something to do with imperial?
Is there anything I can sub it out for to check if that is whats causing it?
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #11 on: November 30, 2015, 06:27:04 AM »
1e-3 is one unit of measurement with the decimal kicked left 3 places.

added:
Command: (rtos 1e-3 2 9)
"0.001000000"
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.

LSElite

  • Newt
  • Posts: 65
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #12 on: November 30, 2015, 06:42:11 AM »
1e-3 is one unit of measurement with the decimal kicked left 3 places.

added:
Command: (rtos 1e-3 2 9)
"0.001000000"

Cheers mate, I suspected as much.

I found the bugs, so many dumb mistakes on my part.

here is the what ive got so far:
Code - Auto/Visual Lisp: [Select]
  1. (defun ObjectIdentification  (p1 p2 / ss1 ss2 ss3 ct)
  2.         (setq osmode (getvar "osmode"))
  3.         (command "osmode" "0")
  4.         (setq SelRange 10)
  5.         (command "zoom" "W" p1 p2)
  6.         (if (setq ss1 (ssget "_F" (list p1 p2)))
  7.                 (progn
  8.                         (command "zoom" "o" "p" "")
  9.                         (if (setq ss2 (ssget "_C" (mapcar '- p1 '(0.001 0.001)) (mapcar '+ p1 '(0.001 0.001))))
  10.                                 (progn
  11.                                         (vl-cmdf "_.select" ss1 "_remove" ss2 "")
  12.                                         (setq ss1 (ssget "_P"))
  13.                                 )
  14.                         )
  15.                         (if (setq ss3 (ssget "_C" (mapcar '- p2 '(0.001 0.001)) (mapcar '+ p2 '(0.001 0.001))))
  16.                                 (progn
  17.                                         (vl-cmdf "_.select" ss1 "_remove" ss3 "")
  18.                                         (setq ss1 (ssget "_P"))
  19.                                 )
  20.                         )
  21.                 )
  22.         )
  23.         (command "osmode" osmode)
  24.         princ ss1
  25. )
The only downside is it will not detect a line that is running directly under the selection in parallel.
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #13 on: November 30, 2015, 06:48:54 AM »

What is the line length relative to the 2 points ?

Chances are if it passes through either point it will be excluded
... or if it's within 0.001 of either point :)
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.

LSElite

  • Newt
  • Posts: 65
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #14 on: November 30, 2015, 06:55:02 AM »
the line just happens to pass directly under the line of selection, it is essentially identical apart from the length. it is a strange it misses it, i guess I just need to find a way to up the tolerance a bit to grab it.
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #15 on: November 30, 2015, 07:14:26 AM »

Quote
directly under the line of selection

do you mean behind,  or do you mean below ?

Unless excluded by the endpoint locations I'd expect behind or in front  would be selected, not below or above.


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.

Lee Mac

  • Seagull
  • Posts: 12940
  • London, England
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #16 on: November 30, 2015, 09:04:36 AM »
With the additional conditions & selection criteria that you mention, it may be easier to follow a variation of the 'Option 1' method I suggest earlier, for example:
Code - Auto/Visual Lisp: [Select]
  1. (defun ObjectIdentification ( pt1 pt2 fuz / ang app per rtn )
  2.           ang (angle pt1 pt2)
  3.           per (- ang (/ pi 2.0))
  4.           pt1 (polar pt1 ang fuz)
  5.           pt2 (polar pt2 ang (- fuz))
  6.     )
  7.     (setq rtn
  8.         (ssget "_CP"
  9.             (list
  10.                 (polar pt1 per fuz)
  11.                 (polar pt2 per fuz)
  12.                 (polar pt2 per (- fuz))
  13.                 (polar pt1 per (- fuz))
  14.             )
  15.         )
  16.     )
  17.     (vla-zoomprevious app)
  18.     rtn
  19. )

To test:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / p q )
  2.     (if
  3.         (and
  4.             (setq p (getpoint "\n1st point: "))
  5.             (setq q (getpoint "\n2nd point: " p))
  6.         )
  7.         (sssetfirst nil (ObjectIdentification p q 1e-3))
  8.     )
  9. )

LSElite

  • Newt
  • Posts: 65
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #17 on: November 30, 2015, 05:31:58 PM »
Cheers LM, I will test it out tonight.
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw

LSElite

  • Newt
  • Posts: 65
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #18 on: December 01, 2015, 06:21:37 AM »
It worked a treat, Cheers LM and cheers Kerry.
I learned alot over this post, and I got my problem solved  :-D
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw

Lee Mac

  • Seagull
  • Posts: 12940
  • London, England
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #19 on: December 01, 2015, 07:46:40 AM »
Excellent to hear LSElite - you're most welcome.  :-)

And of course, if you have any questions concerning the method used in the last code posted, feel free to ask.

LSElite

  • Newt
  • Posts: 65
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #20 on: December 01, 2015, 08:07:48 AM »
And of course, if you have any questions concerning the method used in the last code posted, feel free to ask.
I was going to put it down to magic.
I think I understand though I am not certain.

It finds the internal points from the inital points.
It then zooms the screen on the internal points leaving the intial points off the screen.
It them does a selection from the initial points and skips the objects because they are off the screen?

Am I close?
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw

Lee Mac

  • Seagull
  • Posts: 12940
  • London, England
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #21 on: December 01, 2015, 12:24:41 PM »
Close -

The function is essentially retrieving a selection using the following crossing-polygon selection window (hence the "_CP" mode string), which is offset from the supplied endpoints by the given fuzz value, and has a width equal to the given fuzz value:


LSElite

  • Newt
  • Posts: 65
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #22 on: December 01, 2015, 05:25:48 PM »
Ahhh!, Of course!
Now I get it, that is really cool.
I could be wrong but could the zoom possibly cause issues?
because it uses the internal points instead of the supplied points and moves the perpendicular points off the screen?

I think it would be an easy fix if it is an issue, to simply move the zoom to the start of the function before pt1 and pt2 are changed.
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw

Lee Mac

  • Seagull
  • Posts: 12940
  • London, England
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #23 on: December 01, 2015, 05:54:03 PM »
I could be wrong but could the zoom possibly cause issues?
because it uses the internal points instead of the supplied points and moves the perpendicular points off the screen?

Perhaps, but in reality since the fuzz value will be very small (~1e-3 or less), this shouldn't have too much effect.

LSElite

  • Newt
  • Posts: 65
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #24 on: December 02, 2015, 06:23:01 AM »
Okay so after close inspection this program still is not giving back 100% accurate output.

I need it to remove lines that are collinear with the line made by the selection.
ie, crosses between both points.

Any Ideas?
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw

Lee Mac

  • Seagull
  • Posts: 12940
  • London, England
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #25 on: December 02, 2015, 07:32:23 AM »
Iterate over the selection and remove those lines which do not intersect the selection line (use the inters function to test this).

LSElite

  • Newt
  • Posts: 65
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #26 on: December 02, 2015, 09:50:38 PM »
I was wrong again :(
I just need it to remove all objects on the initial points from the selection set.
I will keep playing around with my initial code but if anyone knows a better way of removing one selection set from another please let me know.
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #27 on: December 02, 2015, 11:28:30 PM »
Have a play

Code - Auto/Visual Lisp: [Select]
  1.  
  2.  
  3. ;; Subtracts one selection set from another and returns their difference
  4. ;; ssMain - Selection set to Subtract from
  5. ;; ssSub  - Selection set to subtract
  6.  
  7. (defun kdub:SSSubtract (ssMain ssSub / ssResult n s)
  8.   (setq n   -1
  9.         ssResult ssMain
  10.   )
  11.   (repeat (sslength ssSub)
  12.     (if (ssmemb (setq s (ssname ssSub (setq n (1+ n)))) ssResult)
  13.       (ssdel s ssResult)
  14.     )
  15.   )
  16.   ssResult
  17. )
  18.  


Image added:
« Last Edit: December 02, 2015, 11:46:03 PM by Kerry »
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.

LSElite

  • Newt
  • Posts: 65
Re: Selection between 2 points but excluding any objects on the exact points.
« Reply #28 on: December 03, 2015, 05:30:51 PM »
It worked perfectly.
Cheers Kerry, you are a life saver!

Here is the function if anyone wants it:
Code - Auto/Visual Lisp: [Select]
  1. (defun ObjectIdentification ( pt1 pt2 app / p1 p2 p3 p4 ang per fuz ss ss1 ss2)
  2.         ;; Subtracts one selection set from another and returns their difference
  3.         ;; ssMain - Selection set to Subtract from
  4.         ;; ssSub  - Selection set to subtract
  5.         (defun kdub:SSSubtract (ssMain ssSub / ssResult n s)
  6.                 (setq n -1 ssResult ssMain)
  7.                 (repeat (sslength ssSub)
  8.                         (if (ssmemb (setq s (ssname ssSub (setq n (1+ n)))) ssResult)
  9.                                 (ssdel s ssResult)
  10.                         )
  11.                 )
  12.         ssResult)
  13.        
  14.         (vla-zoomwindow app (vlax-3D-point pt1) (vlax-3D-point pt2))
  15.         (setq   fuz             5
  16.                         ang     (angle pt1 pt2)
  17.                         per     (- ang (/ pi 2.0))
  18.                         pnt1    (polar pt1 ang fuz)
  19.                         pnt2    (polar pt2 ang (- fuz))
  20.                         ss              (ssget "_CP"
  21.                                                 (list   (polar pnt1 per fuz)
  22.                                                                 (polar pnt2 per fuz)
  23.                                                                 (polar pnt2 per (- fuz))
  24.                                                                 (polar pnt1 per (- fuz)))
  25.                                         )
  26.         )
  27.         (if ss
  28.                 (progn
  29.                         (setq   ang1    (/ pi 4)
  30.                                         p1              (polar pt1 (* ang1 3) fuz)
  31.                                         p2              (polar pt1 (* ang1 7) fuz)
  32.                                         p3              (polar pt2 (* ang1 3) fuz)
  33.                                         p4              (polar pt2 (* ang1 7) fuz)
  34.                         )
  35.                         (vla-zoomwindow app (vlax-3D-point p1) (vlax-3D-point p2))
  36.                         (setq ss1       (ssget "_C"     p1 p2))
  37.                         (vla-zoomwindow app (vlax-3D-point p3) (vlax-3D-point p4))
  38.                         (setq ss2       (ssget "_C"     p3 p4 ))
  39.  
  40.                         (if (and ss ss1) (setq ss (kdub:SSSubtract ss ss1)))
  41.                         (if (and ss ss2) (setq ss (kdub:SSSubtract ss ss2)))
  42.                         (if ss (if (= (sslength ss) 0) (setq ss nil)))
  43.                 )
  44.         )
  45.         princ ss
  46. )
« Last Edit: December 03, 2015, 05:39:05 PM by LSElite »
“A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.”
― George Bernard Shaw