Author Topic: "NENTSEL" from paperspace - anyone know a better way?  (Read 3694 times)

0 Members and 1 Guest are viewing this topic.

PKENEWELL

  • Bull Frog
  • Posts: 317
"NENTSEL" from paperspace - anyone know a better way?
« on: April 04, 2014, 02:56:53 PM »
Hi All,

I just created this function to be able to return entity data from a modelspace viewport while in paperspace. Does anyone have a better method than switching back and forth from Paperspace to Modelspace viewport to get the entity under the cursor? Any coding improvements would also be welcome.

Code - Auto/Visual Lisp: [Select]
  1. ;|==============================================================================
  2.   Function Name: (pjk-PS-Nentsel)
  3.  
  4.   Written By: Phil Kenewell
  5.         Date: 4/4/2014
  6.     Revision: 0.1 -   4/4/2014; First Release.
  7.               0.2  - 4/14/2014; Added a way to active the viewport intended by the user.
  8.               Thanks to Kruuger on theSwamp.org
  9.  
  10.   Arguments: pr = string; A user prompt for the command line
  11.              kw = Keyword Codes for (initget)
  12.  
  13.   Usage: (pjk-PS-Nentsel <Prompt>)
  14.  
  15.   Returns:
  16.            if an object is present in modelspace or paperspace under the cursor,
  17.            it returns a list in the format returned by (nentsel).
  18.            i.e. (<Entity name: 7ffffb088e0> (3.74275 3.40795 0.0)) for standard entity
  19.            or (<Entity name: 7ffffb14090> (3.68518 4.04064 0.0) ((1.0 0.0 0.0 3.65343)
  20.               (0.0 1.0 0.0 4.16154) (0.0 0.0 1.0 0.0) (0.0 0.0 0.0 1.0)) (<Entity name: 7ffffb140a0>))
  21.            if the entity is nested
  22.  
  23.   Description:
  24.      This function is similar to (nentsel), except that:
  25.         1) it tests for missed picks by the pointing device and loops to
  26.            allow the user to re-select,
  27.         2) Honors Keywords if "kw" argument is supplied, and
  28.         3) it finds objects under the cursor from a modelspace viewport if
  29.            no object exists to select in paperspace.
  30.  
  31.      NOTE: This function causes a slight flash when switching to a modelspace viewport
  32.            and back if in paperspace. It would be nice to find a better way to do this!
  33. ================================================================================|;
  34. (defun pjk-PS-Nentsel (pr kw / ad cnt ent flg p ss)
  35.    (if kw (initget kw))
  36.    (if (> (getvar "CVPORT") 1) ; if in Modelspace
  37.       (while (and (not (setq ent (nentsel pr)))(= (getvar "errno") 7))
  38.          (princ "\nNo Object Selected. Try Again...\n")
  39.          (if kw (initget kw))
  40.       )
  41.       (while (not ent)
  42.          (if (and (not (setq ent (nentsel pr)))(= (getvar "errno") 7))
  43.             (progn
  44.                (setq p  (cadr (grread nil 1)) cnt 0
  45.                      ss (ssget "_X" (list (cons 0 "VIEWPORT")(cons 410 (getvar "CTAB"))))
  46.                      ad (vla-get-activedocument (vlax-get-acad-object))
  47.                )
  48.                (vla-put-mspace ad :vlax-true)
  49.                (while (and (not ent) (< cnt (sslength ss)))
  50.                    (vla-put-activepviewport ad (vlax-ename->vla-object (ssname ss cnt)))
  51.                    (if (setq p1 (osnap (trans p 3 2) "nea"))(setq ent (nentselp p1) flg T))
  52.                    (setq cnt (1+ cnt))
  53.                )
  54.                (vla-put-mspace ad :vlax-false)
  55.             )
  56.             (if (not ent)(setq ent T))
  57.          )
  58.          (if (not ent)
  59.             (progn (if kw (initget kw))(princ "\nNo Object Selected. Try Again...\n"))
  60.             ;; translate the point picked back into paperspace.
  61.             (if (and flg (= (type ent) 'LIST))
  62.                 (if (> (length ent) 2)
  63.                     (setq ent
  64.                        (list
  65.                           (car ent)
  66.                           (trans (cadr ent) 2 3)
  67.                           (cdr (member (cadr ent) ent))
  68.                        )
  69.                     )
  70.                     (setq ent (list (car ent) (trans (cadr ent) 2 3)))
  71.                 )
  72.             )
  73.          )
  74.       )
  75.    )
  76.    (if (= ent T) nil ent)
  77. );; End Function (pjk-PS-Nentsel)
  78.  

Thanks!

EDIT: I added an argument and code to the function to honor Keywords.

EDIT 2: I realized that if the data was a block as returned by (nentsel), I was trunicating the rest of the data - corrected.

EDIT 3: added a flag to prevent translating the picked point if the selected object was already in paperspace.

EDIT 4: Version 0.2 - Updated code to iterate through the all viewports in the current layour to find the picked object.
« Last Edit: April 14, 2014, 04:12:37 PM by PKENEWELL »
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: "NENTSEL" from paperspace - anyone know a better way?
« Reply #1 on: April 07, 2014, 02:38:43 PM »
No ideas from anyone on this?
« Last Edit: April 10, 2014, 05:00:39 PM by PKENEWELL »
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: "NENTSEL" from paperspace - anyone know a better way?
« Reply #2 on: April 10, 2014, 05:03:33 PM »
Silence? Well - either:
1) No one has any suggestions at all for my code,
2) I broke some rule on this forum and I'm getting shunned, Or
3) I accidently engaged that cloaking device MP was talking about?
 :-D
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

danallen

  • Guest
Re: "NENTSEL" from paperspace - anyone know a better way?
« Reply #3 on: April 10, 2014, 06:10:35 PM »
I see you, but have no ideas...

Dan

kruuger

  • Swamp Rat
  • Posts: 633
Re: "NENTSEL" from paperspace - anyone know a better way?
« Reply #4 on: April 11, 2014, 05:09:53 AM »
Silence? Well - either:
1) No one has any suggestions at all for my code,
2) I broke some rule on this forum and I'm getting shunned, Or
3) I accidently engaged that cloaking device MP was talking about?
 ;D
is your code know on above which viewport your make a "click" ?
there was great code to translate coord. form paper to model by gile:
http://www.theswamp.org/index.php?topic=29231.msg347755#msg347755
also need viewport selection for point translation.
question is, can we make point selection in model but being in paper space ?
k

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: "NENTSEL" from paperspace - anyone know a better way?
« Reply #5 on: April 11, 2014, 09:49:55 AM »
@danallen: Thanks for the reply. Even if you couldn't give an answer, it's nice to have an acknowledgement of a post.  :-)

is your code know on above which viewport your make a "click" ?
there was great code to translate coord. form paper to model by gile:
http://www.theswamp.org/index.php?topic=29231.msg347755#msg347755
also need viewport selection for point translation.
question is, can we make point selection in model but being in paper space ?
k

Hi Kruuger - Thanks much for your reply! This function made the assumption that switching to a modelspace viewport, it will activate the viewport under the cursor. I was incorrect. If there is another viewport - it will activate the last created. In this case the function does not work properly. Thanks also for the link from gile. I will study this to try and figure out a better way to do what i'm attempting. The problem I have now is how to determine what viewport the user is trying to select objects in.

Maybe some of the experts here will have some ideas?
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

kruuger

  • Swamp Rat
  • Posts: 633
Re: "NENTSEL" from paperspace - anyone know a better way?
« Reply #6 on: April 11, 2014, 04:01:16 PM »
If there is another viewport - it will activate the last created. In this case the function does not work properly... The problem I have now is how to determine what viewport the user is trying to select objects in.
exactly.


you can catch VIEWPORT with this:
Code: [Select]
[code]
(setg pt (getpoint "\nSelect point: ")
      ds (getvar "VIEWSIZE")
      p1 (polar Pt (* 0.5 pi) ds)
      ss (ssget "_F" (list Pt p1)'((0 . "VIEWPORT")))
)
than check if point is inside - see image. all three points grab the VIEWPORT but only green is correct.
maybe it will be useful.
kruuger

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: "NENTSEL" from paperspace - anyone know a better way?
« Reply #7 on: April 11, 2014, 06:07:53 PM »

you can catch VIEWPORT with this:
Code: [Select]
(setg pt (getpoint "\nSelect point: ")
      ds (getvar "VIEWSIZE")
      p1 (polar Pt (* 0.5 pi) ds)
      ss (ssget "_F" (list Pt p1)'((0 . "VIEWPORT")))
)
than check if point is inside - see image. all three points grab the VIEWPORT but only green is correct.
maybe it will be useful.
kruuger

Thanks Kruuger! I will look into this and get back with updated code as soon as I can.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: "NENTSEL" from paperspace - anyone know a better way?
« Reply #8 on: April 14, 2014, 04:33:30 PM »
1st post updated with my latest version of the function.


you can catch VIEWPORT with this:
Code: [Select]
(setg pt (getpoint "\nSelect point: ")
      ds (getvar "VIEWSIZE")
      p1 (polar Pt (* 0.5 pi) ds)
      ss (ssget "_F" (list Pt p1)'((0 . "VIEWPORT")))
)
than check if point is inside - see image. all three points grab the VIEWPORT but only green is correct.
maybe it will be useful.
kruuger

Kruuger,

Thanks. Your post got me thinking about it. Your suggested code has a few problems:
1) If the viewport is not completely visible in the current view - the ssget "F" option does not work.
2) if the viewports layer is turned off, the above ssget code also does not work.

Fortunately - your reply got me thinking about another bit of code you posted: http://www.theswamp.org/index.php?topic=38197.0
In that post you were selecting *all* the viewports and iterating through them. I tried this method - iterating through all viewports and trying to find a viewport that has the object under the cursor - and it seems to work well so far. It seems that (nentselp) will not find anything that is not visible within a viewport if the coordinates are not within the boundary.

For now - this function does what I need it to do. Although I will still look further into this for problems, and to find out a way to get the entity without activating a viewport (Like AutoCAD's dimensions can do). I dont know if this is possible without using nenselp, which only works in the active space.

Thanks again! Phil.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

danallen

  • Guest
Re: "NENTSEL" from paperspace - anyone know a better way?
« Reply #9 on: April 14, 2014, 05:57:32 PM »
I tried this method - iterating through all viewports and trying to find a viewport that has the object under the cursor - and it seems to work well so far. It seems that (nentselp) will not find anything that is not visible within a viewport if the coordinates are not within the boundary.

if visually overlapping objects can be found in multiple viewports, will your routine give an option to the user?

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: "NENTSEL" from paperspace - anyone know a better way?
« Reply #10 on: April 15, 2014, 09:50:25 AM »
if visually overlapping objects can be found in multiple viewports, will your routine give an option to the user?

Hi Danallen,

No I don't believe this will allow for overlapping objects, and I'm not sure if it would be possible to do so, or at least I would not know how to do it. I was hoping the experts on this forum would point me towards a better method.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt