Author Topic: Selection between 2 points but excluding any objects on the exact points.  (Read 6788 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: 12928
  • 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: 12928
  • 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: 12928
  • 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