Author Topic: Selecting object and point?  (Read 10541 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.