Modelspace to the center of Paperspace

Discussion in 'AutoCAD' started by zeha, Jun 23, 2004.

  1. zeha

    zeha Guest

    Hi all,

    When i added a new viewport with the posted function below
    then Mspace limmin displays to the center of the viewport.

    How to handle to solve this problem.


    A2k4 and Win2k

    ;-------------------------------------------------------------------
    ;example (addviewport "W06001" 210.0 297.0 100.0)
    (defun addviewport (name width height vpscale / doc layouts center layout obj vpscale)
    (setq doc (vla-get-activedocument(vlax-get-acad-object))
    layouts (vla-get-Layouts doc)
    center (mapcar '(lambda(x)(* 0.5 x))(list width height 0.0))
    )
    (if (member name (layoutList))
    (progn
    (vlax-for lay layouts
    (if (and (eq (vla-get-name lay) name)(eq :vlax-false (vla-get-modeltype lay)))
    (vlax-for ent (vla-get-block lay) ; for each ent in layout
    (if (= (vla-get-objectname ent) "AcDbViewport")
    (vla-delete ent)
    )
    )
    )
    )
    )
    (setq layout (vla-add layouts name))
    )
    (setq obj (vla-addpviewport (vla-get-PaperSpace doc)
    (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 2)) center)
    width height)
    )
    (if (equal vpscale 1)(vla-put-StandardScale obj vpscale)(vla-put-CustomScale obj (/ 1.0 vpscale)))
    (vla-put-viewporton obj :vlax-true)
    (vla-display obj :vlax-true)
    (vla-update obj)
    (vla-put-displaylocked obj :vlax-true)
    (vlax-release-object obj)
    )

    Help appreciated
     
    zeha, Jun 23, 2004
    #1
  2. Here is one approach. Notice that I cleaned up other things too, such as the
    needless layout iteration and the bogus check for ModelType (you, the
    programmer, better know better than to pass "Model" as an argument!).

    (defun addviewport (name width height vpscale / app doc layouts center
    layout obj vpscale)
    (vl-load-com)
    (setq app (vlax-get-Acad-Object)
    doc (vla-get-ActiveDocument app)
    layouts (vla-get-Layouts doc)
    center (mapcar '(lambda (x) (* 0.5 x)) (list width height 0.0)))
    (if (member name (layoutlist))
    (vlax-for ent (vla-get-Block (setq layout (vla-Item layouts name)))
    (if (= (vla-get-ObjectName ent) "AcDbViewport")
    (vla-delete ent)))
    (setq layout (vla-add layouts name)))
    (vla-put-ActiveLayout doc layout)
    (setq obj (vla-AddPViewport
    (vla-get-PaperSpace doc)
    (vlax-3D-Point center)
    width
    height))
    (vla-put-ViewportOn obj :vlax-true)
    (vla-Display obj :vlax-true)
    (vla-put-MSpace doc :vlax-True)
    (vla-ZoomExtents app)
    (vla-put-MSpace doc :vlax-False)
    (if (equal vpscale 1)
    (vla-put-StandardScale obj acVp1_1)
    (vla-put-CustomScale obj (/ 1.0 vpscale)))
    (vla-Update obj)
    (vla-put-DisplayLocked obj :vlax-true)
    (vlax-Release-Object obj))


    --
    R. Robert Bell


    Hi all,

    When i added a new viewport with the posted function below
    then Mspace limmin displays to the center of the viewport.

    How to handle to solve this problem.


    A2k4 and Win2k

    ;-------------------------------------------------------------------
    ;example (addviewport "W06001" 210.0 297.0 100.0)
    (defun addviewport (name width height vpscale / doc layouts center layout
    obj vpscale)
    (setq doc (vla-get-activedocument(vlax-get-acad-object))
    layouts (vla-get-Layouts doc)
    center (mapcar '(lambda(x)(* 0.5 x))(list width height 0.0))
    )
    (if (member name (layoutList))
    (progn
    (vlax-for lay layouts
    (if (and (eq (vla-get-name lay) name)(eq :vlax-false
    (vla-get-modeltype lay)))
    (vlax-for ent (vla-get-block lay) ; for each ent in layout
    (if (= (vla-get-objectname ent) "AcDbViewport")
    (vla-delete ent)
    )
    )
    )
    )
    )
    (setq layout (vla-add layouts name))
    )
    (setq obj (vla-addpviewport (vla-get-PaperSpace doc)
    (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 2))
    center)
    width height)
    )
    (if (equal vpscale 1)(vla-put-StandardScale obj
    vpscale)(vla-put-CustomScale obj (/ 1.0 vpscale)))
    (vla-put-viewporton obj :vlax-true)
    (vla-display obj :vlax-true)
    (vla-update obj)
    (vla-put-displaylocked obj :vlax-true)
    (vlax-release-object obj)
    )

    Help appreciated
     
    R. Robert Bell, Jun 23, 2004
    #2
  3. zeha

    zeha Guest

    Robert,

    Thanks, that will work

    I tougth to do it without switching to the new added layout.

    I suppose that's not possible?

    Harrie
     
    zeha, Jun 24, 2004
    #3
  4. If you calculated the center of MS' extents, I think you could use that to
    set the viewport's center.

    --
    R. Robert Bell


    Robert,

    Thanks, that will work

    I tougth to do it without switching to the new added layout.

    I suppose that's not possible?

    Harrie
     
    R. Robert Bell, Jun 24, 2004
    #4
  5. zeha

    zeha Guest

    Robert,

    I use the getvar limmin and limmax from the Model tab
    This is also set to the scale and expected papersize

    (vla-ZoomWindow app (vlax-3d-point (getvar "limmin")) (vlax-3d-point (getvar "limmax")))

    This works for me but it switch to the added layout

    Can it be done without switching and if so, how?

    Thanks,

    Harrie
     
    zeha, Jun 24, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.