Jump to content

Alternate Method For Activating Floating Viewports


ksperopoulos

Recommended Posts

Is there a way to activate a floating viewport on a layout tab just by clicking inside the viewport's borders? I have used vla-put-mspace, but if there are multiple viewports on one tab, it will remember the last one that was activated. I want to be able to manually select the one I want to activate without selecting the viewport's border.

Link to comment
Share on other sites

  • Retrieve all viewports created in the active layout (exclude the Paperspace Viewport itself).
  • Obtain the boundary of each viewport.
  • Prompt user for point.
  • Test whether given point lies within each viewport boundary, if so, store corresponding Viewport object.
  • Set mspace property of Active Document to :vlax-true.
  • Set activepviewport property of Active Document to stored Viewport object.

Link to comment
Share on other sites

Thanks for the advice Lee. I am working on the first step. When I attempt to retrieve all the viewports, it seems like the only way to get how many there are is by getting the Count property from the PaperSpace collection. I guess I have to apply a filter on this selection to remove anything else that is in paperspace using the Item method, correct? Once I do that, how do you prevent the selection of the paperspace viewport itself? I'm thinking of the IsLayout property.

Link to comment
Share on other sites

Hi Ksperopoulos.

 

Very interesting question. I already asked myself the same kind of question. I never found any answers made by master lispers. Far from being totally sure of what i'm about to say, here'S what I think. (Maybe someone could confirm or teach us something new...)

I'm thinking of the IsLayout property.

AFAIK that property only apply to blocks.

I am working on the first step. When I attempt to retrieve all the viewports, it seems like the only way to get how many there are is by getting the Count property from the PaperSpace collection. I guess I have to apply a filter on this selection to remove anything else that is in paperspace using the Item method, correct? Once I do that, how do you prevent the selection of the paperspace viewport itself?

I would use ssget function. I tried to dump the result, and i could not see any additionnal properties/methods for the layout (ie.: I was expecting a name property). I might be totally beside the track on that, but from what I saw, the VPort ID (dxf 69) seems to always be 1 for the layout.

 

Based on that assumption, itterating thru the selection set and deleting from it any vport that has the id 1 seems to work to have a selection excluding the pspace viewport. So again, I might be totally wrong, and I'm sure that if that works there are more efficient ways to retrieve all viewports created in the active layout excluding the Paperspace Viewport itself. Here'S my code, for discussion sake. (I've added sssetfirst to help visualize the result)

(defun c:test2 ( / vpsel iteration e )
  (if (and (setq vpsel (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 (getvar 'ctab)) )))
  	 (setq iteration (1- (sslength vpsel)))
      )
      (progn
         (while (setq e (ssname vpsel iteration))
            (if (eq 1 (cdr (assoc 69 (entget e))))
                (ssdel e vpsel)
  	  )
            (setq iteration (1- iteration))
         )
      (princ (strcat "\nI think there are "(itoa (sslength vpsel)) " viewports on that layout... selecting them now"))
      (sssetfirst nil vpsel)
      (vla-Regen (vla-get-ActiveDocument (vlax-get-acad-object)) acActiveViewport)
      )
  )
  (princ)
)

 

Maybe that will help for your first step... or just up your thread to get some real help :D

Cheers!

Link to comment
Share on other sites

You're on the right lines Jef!, but you could exclude the Paperspace viewport directly from the ssget filter list:

(ssget "_X" (list '(0 . "VIEWPORT") '(-4 . "<NOT") '(69 . 1) '(-4 . "NOT>") (cons 410 (getvar 'ctab))))

Link to comment
Share on other sites

You're on the right lines Jef!
:excited:

 

but you could exclude the Paperspace viewport directly from the ssget filter list
ooops! Are we friday yet? :cute:

 

Nice catch... and thanks for the info/tip!

Link to comment
Share on other sites

  • 2 weeks later...

Where in the world did you find out how to do -4 Lee? Is it somewhere in the help file, because I can't find it?

Link to comment
Share on other sites

Thank you for showing me this Lee. Sometimes trying to use the search functionality within the help file is not as accurate as I would hope. If only Autodesk thought like I do, then my job would be a lot easier.

Link to comment
Share on other sites

  • Retrieve all viewports created in the active layout (exclude the Paperspace Viewport itself).
  • Obtain the boundary of each viewport.
  • Prompt user for point.
  • Test whether given point lies within each viewport boundary, if so, store corresponding Viewport object.
  • Set mspace property of Active Document to :vlax-true.
  • Set activepviewport property of Active Document to stored Viewport object.

 

Well, I chose to take a different path while utilizing some of the tools you mentioned above Lee. The reason I wanted the viewport to be activated, was to obtain its properties for dimensioning (as it relates to other threads I have started on this forum). So instead of activating it, I just retrieved those properties by selecting the viewport itself and then finding if my two points for dimensioning fall within the viewport boundaries (as defined in another part of my coding by the variables lowlt and uprt). Here is the code I ended up with:

 

(while
   (and
       (setq point1 (getpoint "\nSpecify first extension line origin or <Exit>: "))
       (> (car point1) (car lowlt))
       (< (car point1) (car uprt))
       (> (cadr point1) (cadr lowlt))
       (< (cadr point1) (cadr uprt))
       (= (caddr point1) (caddr lowlt))
       (= (caddr point1) (caddr uprt))
       (setq point2 (getpoint point1 "\nSpecify second extension line origin or <Exit>: "))
       (> (car point2) (car lowlt))
       (< (car point2) (car uprt))
       (> (cadr point2) (cadr lowlt))
       (< (cadr point2) (cadr uprt))
       (= (caddr point2) (caddr lowlt))
       (= (caddr point2) (caddr uprt))
   )
   (progn
       (setvar "dimlfac" dimscale)
       (setvar "osmode" 16384)
       (command "DIMLINEAR" point1 point2
           (progn
               (setvar "osmode" oldosnaps)
               (prompt "\nSpecify dimension line location: ")
               pause
           )
       )
   )
)

 

In the next part of my code, I plan on using your tip to exclude the paperspace viewport, so thank you all for your help!

Link to comment
Share on other sites

Hi Kyle,

 

 

Obviously I've been following your progress in your "translating points" thread. I've hesitated to write any code to post myself for several reasons, including a lack of time, but I couldn't help thinking that you might need to give some thought to a few other things that you may not have yet, e.g. what if the viewport has been clipped or rotated?

 

 

I've written this quickly. I'm not posting it with the thought that it covers everything; it certainly hasn't been thoroughly tested and I've not done a lot with viewports before. I'm posting it more to demonstrate some of the things you might need to be doing to check if selected points are within viewports or not. To save time, I've borrowed a "point inside" function that Lee once posted (thanks Lee). You will also note that, by necessity, it is following the same steps that Lee outlined in post 2 above.

 

 

I also posted this code to show that the state of the current coordinate system doesn't change my approach.

 

 

(defun c:fun ( /
             ; Functions
             gvpbs insidep1 insidep2 vlax-list->3D-point
             ; Variables
             doc vps pt vp
             )
 
 (vl-load-com)
 (setq doc (vla-get-activedocument (vlax-get-acad-object)))
 ;;******************************************************************
 ;; Local Functions
 ;;******************************************************************
 (defun gvpbs ( / vps i el cb bdys ctr v )
   (if (setq vps (ssget
                   "_X"
                   (list
                     '(0 . "VIEWPORT")
                     '(-4 . ">")
                     '(69 . 1)
                     (cons 410 (getvar "CTAB"))
                     )
                   )
             )
     (progn
       (repeat (setq i (sslength vps))
         (setq el (entget (ssname vps (setq i (1- i)))))
         (if (setq cb (cdr (assoc 340 el)))
           (setq bdys (cons (cons cb (cdr (assoc 69 el))) bdys))
           (progn
             (setq ctr (cdr (assoc 10 el))
                   v (list
                       (/ (cdr (assoc 40 el)) 2.)
                       (/ (cdr (assoc 41 el)) 2.)
                       0.0
                       )
                   bdys (cons
                          (cons
                            (list
                              (mapcar '- ctr v)
                              (mapcar '+ ctr v)
                              )
                            (cdr (assoc 69 el))
                            )
                          bdys
                          )
                   )
             )
           )
         )
       bdys
       )
     )
   )
 
 ;;******************************************************************
 ;; from [url]http://www.cadtutor.net/forum/showthread.php?36221-How-to-determine-if-a-point-is-within-a-boundary[/url]
 ;; ============ Insidep.lsp ===============
 ;;
 ;;  MAIN FUNCTION DESCRIPTION:
 ;;  Will determine whether a point lies
 ;;  inside or outside an object.
 ;;
 ;;  FUNCTION:   insidep
 ;;  ARGUMENTS:
 ;;  Point to be tested.
 ;;  Object Ename or VLA-Object
 ;;
 ;;  FUNCTION:   vlax-list->3D-point
 ;;  ARGUMENTS:
 ;;  List to be converted.
 ;;  Flag to determine x or y.
 ;;
 ;;  OBJECT COMPATIBILITY:
 ;;  Everything except Viewport/Polygon Mesh.
 ;;
 ;;  AUTHOR:
 ;;  Copyright (c) 2009, Lee McDonnell
 ;;  (Contact Lee Mac, CADTutor.net)
 ;;
 ;;  PLATFORMS:
 ;;  No Restrictions,
 ;;  only tested in ACAD 2004.
 ;;
 ;; ========================================
 
 (defun insidep1  ( pt Obj / Tol ang spc flag int lin xV yV )
   (or (eq 'VLA-OBJECT (type Obj))
       (setq Obj (vlax-ename->vla-object Obj)))
   
   (setq Tol  (/ pi 6) ; Uncertainty
         ang  0.0 flag T)
   
   (setq spc (if (zerop (vla-get-activespace doc))
               (if (= (vla-get-mspace doc) :vlax-true)
                 (vla-get-modelspace doc)
                 (vla-get-paperspace doc))
               (vla-get-modelspace doc)))
   
   (while (and (< ang (* 2 pi)) flag)
     (setq flag (and
                  (setq int
                         (vlax-invoke
                           (setq lin
                                  (vla-addLine spc
                                    (vlax-3D-point pt)
                                    (vlax-3D-point
                                      (polar pt ang
                                             (if (vlax-property-available-p Obj 'length)
                                               (vla-get-length Obj) 1.0)))))
                           'IntersectWith Obj
                           acExtendThisEntity))
                  (<= 6 (length int))
                  (setq xV (vl-sort (vlax-list->3D-point int T) '<)
                        yV (vl-sort (vlax-list->3D-point int nil) '<))
                  (or (<= (car xV) (car pt) (last xV))
                      (<= (car yV) (cadr pt) (last yV))))
           ang  (+ ang Tol))
     (vla-delete lin))
   flag)
 
 ;;******************************************************************
 (defun vlax-list->3D-point (lst flag)
   (if lst
     (cons ((if flag car cadr) lst)
           (vlax-list->3D-point (cdddr lst) flag)
           )
     )
   )
 
 ;;******************************************************************
 (defun insidep2 ( pt lst )
   (vl-every
     (function
       (lambda ( a )
         (apply '<= a)
         )
       )
     (apply
       'mapcar
       (list
         'list
         (car lst)
         pt
         (cadr lst)
         )
       )
     )
   )
 
 ;;******************************************************************
 ;; Main Program Code
 ;;******************************************************************
 (cond
   ((= (getvar "TILEMODE") 1)
    (princ "\nRoutine is designed to run in paperspace.")
    )
   ((null (setq vps (gvpbs)))
    (princ "\nThere are no viewports in the current layout.")
    )
   ((and (> (getvar "CVPORT") 1) (vla-put-mspace doc :vlax-false)))
   ((null (setq pt (getpoint "\nSelect point inside a viewport: "))))
   (T
    (setq pt (trans pt 1 0))
    (if (setq vp (vl-some
                   (function
                     (lambda ( x )
                       (if
                         (apply
                           (if (= (type (car x)) 'ENAME)
                             'insidep1
                             'insidep2
                             )
                           (list pt (car x))
                           )
                         (cdr x)
                         )
                       )
                     )
                   vps
                   )
              )
      (progn
        (vla-put-mspace doc :vlax-true)
        (setvar "CVPORT" vp)
        )
      (princ "\nPoint is not within a viewport.")
      )
    )
   )
 (princ)
 )

 

 

Edit:- You could take the progns out of the gvpbs function

Edited by cwake
Went away and came back... :-)
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...