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

0 Members and 1 Guest are viewing this topic.

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