Author Topic: Selecting object and point?  (Read 10547 times)

0 Members and 1 Guest are viewing this topic.

whdjr

  • Guest
Selecting object and point?
« on: September 17, 2004, 12:14:34 PM »
I am trying to select an object and the selection point, but sometimes the object may overlap another object at the selection point.  How can I "weed" out the other objects and return the object I want and the selction point.  

I have tried using entsel, but it may select the other object and I don't want the other object.

I tried using getpoint, but then couldn't get the object.

I have tried using ssget, but I don't get a selection point.

After reading some of the threads here I tried nentselp, but that didn't return all of the objects at the selection point.

My situation here is I am trying to select a segment of a polyline at my selection point, but sometimes the polyline might overlap another line and I can't filter out the other line.

I am lost at what to try next.  Does anybody have any ideas?

Thanks,

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Selecting object and point?
« Reply #1 on: September 17, 2004, 12:35:43 PM »
You can use a variety of methods. It will be necessary to do a bit of testing to see which works best for you, but what you could do is...
pseudocode
Code: [Select]

select point using getpoint
pass point to ssget with filter for object type


To accomplish the ssget filter use this scenario
Code: [Select]

(ssget (getpoint) '((0 . "line")))


This will however create another problem whenever you have overlapping entities and the draworder. The one on top will always be selected.
To resolve this you would need to pass more than one point to the ssget command. This would likely be the original point and another point that is ever so slightly away from the original, say at 0.0001, making sure you turn off osnaps when you grab the selection set.

As I said this is not a simple solution, but it can be made to work.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Selecting object and point?
« Reply #2 on: September 17, 2004, 12:56:30 PM »
Something like this?

Code: [Select]
(defun c:test ()
  (setq pt (getpoint)
        dis 2 ; could be a function of DimScale
        p1 (polar pt 0.785 dis)
        p2 (polar pt 3.93 dis))
  (setq ss (ssget "_C" p1 p2 '((0 . "*polyline")) ))
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Selecting object and point?
« Reply #3 on: September 17, 2004, 01:01:55 PM »
CAB that is what I had in mind ... incedently CAB I am going to be in Tampa this evening...gonna try and go to MOSI tomorrow...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Selecting object and point?
« Reply #4 on: September 17, 2004, 03:18:20 PM »
Quote from: Keith
CAB that is what I had in mind ... incedently CAB I am going to be in Tampa this evening...gonna try and go to MOSI tomorrow...

Thanks for the invite, gonna have to pass though.
I'm sure you'll have a good time, wish I could be there. :?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Serge J. Gianolla

  • Guest
Selecting object and point?
« Reply #5 on: September 17, 2004, 10:19:44 PM »
If it is for in-house use and for your own benefit, this trick about cycling thru objects may help, when using the entsel hold the Ctrl key down and position the cursor on numerous objects while left-clicking to highlight one object at a time.
If it is for coding and distribution, and considering that not everyone is familiar with that previous tool, then these 2 sub-routines may help you. Being close to 15 years-old; they need a bit of massaging.
Code: [Select]
;---This function gets the selection set of the objects crossing the AutoCAD pickbox extents.
;   (ssgetc centerpt number)
; centerpt: the center of the pickbox or nil.
; number: Requires a value working as a refiner

(defun pixel () (setq pix (/ (getvar "viewsize") (cadr (getvar "screensize"))) ))

(defun ssgetc (pt finer / c1 c2 delta)
 (setq pt (trans pt 1 2)  delta (* (getvar "pickbox") (* (pixel) finer)))
 (ssget "_C" (trans (mapcar '(lambda (x) (+ x delta)) pt) 2 1)
             (trans (mapcar '(lambda (x) (- x delta)) pt) 2 1) )
)

SMadsen

  • Guest
Selecting object and point?
« Reply #6 on: September 18, 2004, 05:47:59 AM »
The SSGET ":E" method automatically selects objects within the cursor .. makes the pickbox a crossing rectangle.

To make it act like ENTSEL but still return objects crossed by the pickbox, combine it with ":S"

(setq ss (ssget ":E:S"))

This does the same as the SSGETC function.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Selecting object and point?
« Reply #7 on: September 18, 2004, 02:22:13 PM »
Will you may be interested in this thread as well.

http://theswamp.org/phpBB2/viewtopic.php?t=2404&start=30
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Selecting object and point?
« Reply #8 on: September 18, 2004, 10:31:41 PM »
There you have it whdjr... plenty of options ... let us know how you fare....
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

whdjr

  • Guest
Selecting object and point?
« Reply #9 on: September 19, 2004, 02:15:56 PM »
Hey guys.  The comments and suggestions that were made are excellent.

Thank you very much.

Stig's comments to use (ssget ":E:S") is where I need to be except I need to add the point that was selected.

Any more thoughts?

Thanks,

whdjr

  • Guest
Selecting object and point?
« Reply #10 on: September 19, 2004, 02:30:57 PM »
I just had a brain fart and this came to me.

Code: [Select]

(setq pt (getpoint))
(setq ss (ssget ":E:S"))


After the ssget instead of picking a point use the lastpoint variable "@" or (getvar "lastpoint") and it works, but how do you get it to select the point automatically.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Selecting object and point?
« Reply #11 on: September 19, 2004, 03:02:30 PM »
Try this instead:
Code: [Select]

(if (setq ss (ssget ":E:S"))
  (setq ent (ssname ss 0)
pickpt (last (last (car (ssnamex ss 0)))))
  )

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Selecting object and point?
« Reply #12 on: September 19, 2004, 08:18:37 PM »
And I though the pick point was unavailable.
I'll have to read up on ssnamex.

Very nice Jeff.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

whdjr

  • Guest
Selecting object and point?
« Reply #13 on: September 21, 2004, 08:19:07 AM »
SHOUT OUT!!!!!!

To Stig for his insight on (ssget ":E:S") for selecting the objects at the pickbox, and to Jeff_M for his insight on (ssnamex) to access the selected point.

These are great tools guys, but still does not ensure that the selected what you want them to select.  So I had to wrap this in a while loop to test to see if the object I wanted the user to pick was in the selection set.  If it was not it passed back a (nil) and the started over.

Cool huh!

Thanks again guys.

Code: [Select]
(while (or (null sel) (not pt))
  (setq sel (ss_get ":E:S"))
  (mapcar '(lambda (x)
    (if (not (eq x obj))
      (ssdel x sel)
    )
  )
 (ssnames sel)
  )
  (if (or sel (null sel))
    (setq ent (ssname sel 0)
 pt  (last (last (car (ssnamex sel 0))))
    )
    (princ "\nPoint not on Polyline.  Please try again. ")
  )
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Selecting object and point?
« Reply #14 on: September 21, 2004, 09:48:51 AM »
whdjr

Tested you function & found that it crashed if the 'Pick Point' was not on an object.
That is you picked out in space. So i added an IF stmt. I also felt that the WHILE loop
only needed to test the pt var as it will only have a value if the object was found.
Also changed ( or sel ( null sel )) because it is always true. null sel does not test
for an empty selection set. Hope this is helpful.

Code: [Select]
(defun c:test (/ sel obj pt ent)
  (setq obj (car (entsel "\nPick ent to match."))
        pt  nil
  )
  (prompt "\nSelect point on object.")
  (while (not pt) ; only valid when obj is selected
    (if (setq sel (ssget ":E:S"))
      (mapcar
        '(lambda (x)(if (not (eq x obj)) (ssdel x sel)))
        (ssnames sel)
      )
    )
    (if (and sel (> (sslength sel) 0))
      (setq ent (ssname sel 0)
            pt  (last (last (car (ssnamex sel 0))))
      )
      (princ "\nPoint not on Polyline.  Please try again. ")
    )
  )
)

(defun ssnames (ss / idx lst)
  (setq idx (sslength ss)
        lst (list)
  )
  (while (>= (setq idx (1- idx)) 0)
    (setq lst (cons (ssname ss idx) lst))
  )
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Selecting object and point?
« Reply #15 on: September 21, 2004, 10:44:28 AM »
This is how great programming is developed ... by users helping users ....

Ok .. lemme wipe the tear from my eye ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Selecting object and point?
« Reply #16 on: September 21, 2004, 12:03:32 PM »
Quote from: Keith
Ok .. lemme wipe the tear from my eye ...

heyheyheyhey.............
TheSwamp.org  (serving the CAD community since 2003)

whdjr

  • Guest
Selecting object and point?
« Reply #17 on: September 21, 2004, 01:42:23 PM »
Cab,
Quote
Tested you function & found that it crashed if the 'Pick Point' was not on an object.
That is you picked out in space.

Thanks for your insight on the code.  I didn't post my ss_get function, but it doesn't allow for missed or empty selection sets.
Code: [Select]
(defun ss_get (lst / ent)
  (while (not ent)
    (prompt "\nSelect side to extend:  ")
    (cond ((setq ent (ssget lst)))
 ((= (getvar "ErrNo") 52)
  (exit)
 )
 ((null ent)
  (princ "\nSelection missed.  Please try again.")
 )
    )
  )
  ent
)


BUT (and its a big one), if the pline your after is not in the selection set then the program returns an empty selection set ( and thats BAD).
Quote
I also felt that the WHILE loop
only needed to test the pt var as it will only have a value if the object was found.
Also changed ( or sel ( null sel )) because it is always true. null sel does not test
for an empty selection set.

So I removed some code per your advise and added more:
Code: [Select]
(while (not pt)
  (setq sel (ss_get ":E:S"))
  (mapcar '(lambda (x)
    (if (not (eq x obj))
      (ssdel x sel)
    )
  )
 (ssnames sel)
  )
  (if (and sel (/= 0 (sslength sel)))
    (setq ent (ssname sel 0)
 pt  (last (last (car (ssnamex sel 0))))
    )
    (princ "\nPoint not on Polyline.  Please try again. ")
  )
)

If you know of a better way to tell if a selection set is empty please let me know.

Thanks.

whdjr

  • Guest
Selecting object and point?
« Reply #18 on: September 21, 2004, 01:44:03 PM »
Keith,

Quote
This is how great programming is developed ... by users helping users ....

Ok .. lemme wipe the tear from my eye ...

Do you need a Kleenex buddy?

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Selecting object and point?
« Reply #19 on: September 21, 2004, 02:15:55 PM »
Quote from: Mark Thomas
Quote from: Keith
Ok .. lemme wipe the tear from my eye ...

heyheyheyhey.............


Sorry ... I only said it because it is the epitome of happiness in that different users can share code, improve, expand their personal knowledge .. never meant it as an insult ....
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

whdjr

  • Guest
Selecting object and point?
« Reply #20 on: September 21, 2004, 02:25:20 PM »
Quote
never meant it as an insult ....

No insult taken.  Just poking fun.

By the way, how do you get the quote function in the forum to display who wrote the quote?  Mine doesn't display.

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Selecting object and point?
« Reply #21 on: September 21, 2004, 02:32:47 PM »
Quote from: Keith
Quote from: Mark Thomas
Quote from: Keith
Ok .. lemme wipe the tear from my eye ...

heyheyheyhey.............


never meant it as an insult ....

It wasn't taken that way either. Perhaps my keyboard skills are some what lacking. "heyheyheyhey...." was meant to be laughter, with you not at you.
TheSwamp.org  (serving the CAD community since 2003)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Selecting object and point?
« Reply #22 on: September 21, 2004, 02:33:04 PM »
you must do the following in your opening quote ....

Quote from: Put something here


If you do that then it will work without problem...

The above code will look like this:

Quote from: Put something here

Sombody said this
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

whdjr

  • Guest
Selecting object and point?
« Reply #23 on: September 21, 2004, 02:57:53 PM »
Quote from: This is cool stuff.  Thanks Keith
you must do the following in your opening quote ....

Quote from: Put something here


If you do that then it will work without problem...


Like that?

Cool!
Thanks,

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Selecting object and point?
« Reply #24 on: September 21, 2004, 03:31:10 PM »
Not to criticize but to show you the normal convention of how things are coded.
In your ss_get routine, the name ss_get implies that you are going after a selection set.
'ent' is used for entites and 'ss' for selection sets, & 'lst' for list.
There may only be one entity in you selection set but it is still a selection set.

I see, as you say the ss_get will not return nil so the IF I had added is not needed.
Also not needed is the test in the next IF ( and ss because the ss will always be a
selection set with 0 or 1 entity in it. See the revised code.

Code: [Select]
(defun c:test (/ sel obj pt ent)
  (setq obj (car (entsel "\nPick ent to match."))
        pt  nil
  )
  (prompt "\nSelect point on object.")
  (while (not pt) ; only valid when obj is selected
    (setq sel (ss_get ":E:S"))
    (mapcar
        '(lambda (x)(if (not (eq x obj)) (ssdel x sel)))
        (ssnames sel)
    )
    (if (> (sslength sel) 0)
      (setq ent (ssname sel 0)
            pt  (last (last (car (ssnamex sel 0))))
      )
      (princ "\nPoint not on Polyline.  Please try again. ")
    )
  )
)

(defun ssnames (ss / idx lst)
  (setq idx (sslength ss)
        lst (list)
  )
  (while (>= (setq idx (1- idx)) 0)
    (setq lst (cons (ssname ss idx) lst))
  )
)

(defun ss_get (lst / ss)
  (while (not ss)
    (prompt "\nSelect side to extend:  ")
    (cond ((setq ss (ssget lst)))
          ((= (getvar "ErrNo") 52)
            (exit)) ; ENTER pressed
          ((null ss)
            (princ "\nSelection missed.  Please try again."))
    )
  )
  ss ; return a selectionset, never nil
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

whdjr

  • Guest
Selecting object and point?
« Reply #25 on: September 21, 2004, 03:45:20 PM »
I see your point exactly and I thank you for illustrating that.
Actually I made the same routine for the entsel command and then just changed it to work with ssget for this application.
Code: [Select]
(defun ent_sel (msg / ent)
  (while (not ent)
    (cond ((setq ent (entsel msg)))
 ((= (getvar "ErrNo") 7)
  (princ "\nSelection missed.  Please try again.")
 )
 ((= (getvar "ErrNo") 52)
  (exit)
 )
    )
  )
  ent
)


I have another question (hehe, this is tricky, haha).
In your example you show "pt" as a local var on the first line, therefore until you assign it a value it will be "nil".  So why do set it to nil in the first statement of the code?

This is me being curious.  I have seen others do it as well, but if "pt" is already "nil" why set it "nil" again.[/code]

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Selecting object and point?
« Reply #26 on: September 21, 2004, 04:03:49 PM »
Good question. :)
This was a 'Test' function and the code may have been copied to a larger routine.
That is to say the local pt may then be global and as pt is a common var name I
want to be sure it was nil when the while was executed for the first time.
So it was a CYA move on my part.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Selecting object and point?
« Reply #27 on: September 21, 2004, 04:10:29 PM »
And another thing. When I wrote the first draft of the routine I had no
local vars declared. I often do that during debugging early on in a routine.
It gets me in trouble with vars that need to be some value and I run the routine.
The vars are set to something & are global, then I run the routine again and I
start scratching my head  :shock: as to why the routine is behaving a certain way.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

whdjr

  • Guest
Selecting object and point?
« Reply #28 on: September 21, 2004, 04:22:29 PM »
Quote from: CAB
I often do that during debugging

Is this a common practice in Florida?  

You know...picking bugs off ones self...

<snicker><snicker>

It is here in Georgia.

<haha>

Big fat ugly mosquitos.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Selecting object and point?
« Reply #29 on: September 21, 2004, 04:37:43 PM »
I have stayed in the mountains of north GA many times during even the middle of the summer and never have I had the misfortune of being bitten by a mosquito.

Hijacked thread now returned to original owner ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

whdjr

  • Guest
Selecting object and point?
« Reply #30 on: September 21, 2004, 04:55:08 PM »
Quote from: Keith
I have stayed in the mountains of north GA many times during even the middle of the summer and never have I had the misfortune of being bitten by a mosquito.


Operative phrase being "in the mountains".
The mountains are great, but anywhere else is pure Hell full of mosquitos, gnats, flies, etc..

It sounds like I hate the South, but I don't just the humidity.  It feels like your in the shower all day long without the shower fresh aroma.

The South...Ya gotta love it!...huh!

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Selecting object and point?
« Reply #31 on: September 21, 2004, 05:49:29 PM »
No problem with the bugs here as long as you get in the house before dark.
You can come back out after feeding time with only minor risk.
Two cases of West Nile here. I love the smell of OFF in the evening. 8)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.