Paperspace Viewports

 Most of this is probably due to my limited knowledge of BricsCAD / AutoCAD, but I do have some questions:

  1. Is there an easy way to link what is visible in the model space with what shows in a paperspace viewport? (keeping them linked).
  2. Where are the properties that define what a viewport "is looking at"? They don't appear to be accessible (which is crazy!).
  3. What controls the initial view of the viewport? For instance, if I start a new drawing, draw a circle and then look at the default layouts, the viewport is zoomed to the extents of the circle. If I draw another circle outside the first, the viewports don't then 're-zoom' to extents. Similarly, if I add a layout from a template, it doesn't start with a 'zoomed to extents' view in the viewport.

Comments

  • Viewports show a zoomed extents view when they are created, they don't change until you zoom or pan inside the viewport.
    Double click inside the viewport lets you work inside it, then double click outside the box to return to pspace view.
    Set the scale either inside the viewport, or by picking its perimeter and selecting a scale from the Properties menu.
    I usually have to pan around to place the contents properly, and maybe stretch the edges of the vport to fit what's inside.
  • 1. I usually draw an outline in modelspace around a drawing, then create a viewport, zoom/pan to the drawing, set the scale, and drag two opposite corners of the viewport to the corners of the outline. But you can also do the reverse -- you can position the viewport around the drawing, and then create the modelspace outline using this custom command:
    [code]; http://www.theswamp.org/index.php?topic=3131.0
    ; http://theswamp.org/phpBB2/viewtopic.php?t=2224
    ; Tip1687: VPLIM.LSP  Pspace Limits in Mspace (c)2001, Murray Clack
    ; VPLIM.lsp draws the limits of a Paperspace Viewport Boundary in MODELSPACE
    ; VP - Get ViewPort object
    ; HT - Get Outside HeighT of Viewport
    ; WD - Get Oustide WiDth of Viewport
    ; VN - Get Viewport Number
    ; CTR - Get CenTeR of Viewport
    ; CTRX - Caluculate X of Viewport CenTeR
    ; CTRY - Caluculate Y of Viewport CenTeR
    ; VS - Get View Size of viewport
    ; XP - Calculate XP factor of viewport
    ; IW - Calculate Width of viewport
    ; BL - Calculate Bottom Left corner of viewport
    ; BR - Calculate Bottom Right corner of viewport
    ; TR - Calculate Top Right corner of viewport
    ; TL - Calculate Top Left corner of viewport
    (defun C:VPO (/        VP       HT      WD     VN    CTR    CTRX   CTRY
             VS     XP       IW      BL     BR    TR    TL     PW   OS  )
      (setvar "cmdecho" 0) ;turn off command echoing
      (command ".pspace") ;enter pspace
      (setq    VP ;select viewport boundary
        (entget
          (car
            (entsel
              "\nVPO draws a viewport's boundary in modelspace. Select Viewport: "
            ) ;_ end of entsel
          ) ;_ end of car
        ) ;_ end of entget
      ) ;_ end of setq
      (setq HT (cdr (assoc 41 VP))) ;Get Viewport height with
      (setq WD (cdr (assoc 40 VP))) ;Get Viewport width with
      (setq VN (cdr (assoc 69 VP))) ;Get Viewport Number
      (command ".mspace") ;enter mspace
      (setvar "cvport" VN) ;set correct viewport
      (command ".ucs" "v") ;set UCS to View
      (setq CTR (getvar "viewctr")) ;Get VIEWCTR store as CTR
      (setq CTRX (car CTR)) ;Get X of CTR
      (setq CTRY (cadr CTR)) ;Get Y of CTR
      (setq VS (getvar "viewsize")) ;Get inside Viewport height
      (setq XP (/ HT VS)) ;Get XP Factor with HeighT / View Size
      (setq IW (* (/ VS HT) WD)) ;Get inside width of Viewport by
      (setq BL (list (- CTRX (/ IW 2)) (- CTRY (/ VS 2)))) ;Find four corners of Viewport
      (setq BR (list (+ CTRX (/ IW 2)) (- CTRY (/ VS 2))))
      (setq TR (list (+ CTRX (/ IW 2)) (+ CTRY (/ VS 2))))
      (setq TL (list (- CTRX (/ IW 2)) (+ CTRY (/ VS 2))))
      (command ".pline" BL BR TR TL "c") ;Draw pline inside border
      (command ".pspace") ;Exit from the viewport
      (setvar "TileMode" 1) ;Switch to the model tab
      (princ) ;Clean up command prompt
    )[/code]

    2. That information is given in the DXF group codes and VBA properties of the viewport.
    [code]; EntList command - lists DXF group code pairs for a selected entity
    (defun c:EntList () (entget (ssname (ssget) 0)))

    ; DumpPM - lists an object's ActiveX & VBA Properties & Methods
    (defun c:DumpPM ()   (setq Ent1 (car (entsel)))
    (setq VLname (vlax-ename->vla-object Ent1))   (vlax-dump-object VLname T)  )[/code]

    3. As John said.

  • The primary property of a Viewport object (i.e., where it is centred in the model space) cannot be accessed except through code? You've gone to the trouble of exposing the Viewport centre, height, width and scale, but not it's model space location? You have to resort to workarounds like matching to a model space outline?

    Will definitely have to code around that. :o/
  •  Thanks Roy - that gives me some ideas :)
  • Dan,

    This site might help? http://u-cad.eu/
    Has an OpenDCL app for creating vports from model space. In the blog there is quite a lot of useful info on working with view ports.

    Regards,
    Jason Bourhill

  • But you can also do the reverse -- you can position the viewport around the drawing, and then create the modelspace outline using this custom command:


    [code]; Return a list giving the bottom & top coordinates of the selected vport
    ; if telltale is true it will place an indicating line in mspace
    (defun ms-dims (ent telltale / oDoc oVport BotCorner TopCorner psCoords msCoords mspace)
        (setq oDoc (vla-get-ActiveDocument (vlax-get-acad-object))) ;get current drawing object
        (setq oVport (vlax-ename->vla-object ent)) ; convert to vl object
        (vla-GetBoundingBox oVport 'BotCorner 'TopCorner) ; retrieve corners coords as safearray
        (setq psCoords (mapcar '(lambda (pt) (vlax-safearray->list pt)) (list BotCorner TopCorner))) ; convert from safearray to a list of points
        (vla-put-mspace oDoc :vlax-true) ; change to mspace
        (vla-put-activepviewport oDoc oVport) ; change to our vport
        ;transform psCoords to mscoords. Trans is called twice. 1st to convert to DCS of the vport, 2nd to convert from DCS to WCS
        (setq msCoords (mapcar '(lambda (pt) (trans (trans pt 3 2) 2 0)) psCoords))
        (vla-put-mspace oDoc :vlax-false) ; change back to pspace
        ;if telltale is true draw a line in mspace using the gathered msCoords
        (if telltale
            (progn
                (setq mspace (vla-get-modelspace oDoc))
                (vla-addline mspace (vlax-3d-point (car msCoords))(vlax-3d-point (cadr msCoords)))
            )
        )
    msCoords
    )

    (defun C:Vport-Coords ( / ent)
        (setq ent (car (entsel "\nSelect a vport: ")))
        (if (and ent  (= (vle-entget 0 ent) "VIEWPORT"))
            (ms-dims ent T)
            (princ "\nNo VIEWPORT selected ")
        )
    (prin1)
    )[/code]

    Different approach to do pretty much the same

    Regards,
    Jason Bourhill

This discussion has been closed.