vb.net - change to viewport (mspace) and zoom window

vb.net - change to viewport (mspace) and zoom window

jan_tappenbeck
Collaborator Collaborator
1,848 Views
6 Replies
Message 1 of 7

vb.net - change to viewport (mspace) and zoom window

jan_tappenbeck
Collaborator
Collaborator

hi!

 

i have special job to do. current i have a layout with ONE viewport. my job is to change to modelspace, take a zoom window (left-buttom and right-top i know) and then go back to paperspace.

 

i have no idea!!!

could you help me?

 

regard Jan

0 Likes
1,849 Views
6 Replies
Replies (6)
Message 2 of 7

ambrosl
Autodesk
Autodesk

There are several things that you need to be concerned with, such as being on the Model tab or a named layout along with which viewport is active when on a named layout.  Those things assigned, the following help topics should get you moving in the right direction:

 

Zoom subroutine is documented here
https://help.autodesk.com/view/OARX/2020/ENU/?guid=GUID-FAC1A5EB-2D9E-497B-8FD9-E11D2FF87B93

 

Zoom to a specific area with the Zoom subroutine
https://help.autodesk.com/view/OARX/2020/ENU/?guid=GUID-AA770AAA-A008-47A9-9C2B-3ECD040A18ED

 

Demonstrates the use of the SwitchToPaperSpace and SwitchToModelSpace functions
https://help.autodesk.com/view/OARX/2020/ENU/?guid=GUID-61C22902-F63B-4204-86EC-FA37312D1B6E



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
0 Likes
Message 3 of 7

jan_tappenbeck
Collaborator
Collaborator

Hi!

 

Thank you, i knew that - but to understand it better overall, I described the whole task.

 

I'll look at it and then report it again if necessary.

 

regards Jan

0 Likes
Message 4 of 7

jan_tappenbeck
Collaborator
Collaborator

Hi!

 

i look to the examples. zoom-function will not be the problem.

 

the viewport-examples show how to create - but my template did have a viewport and so i search the way to collect the one viewport in current layout and switch to modell.

 

reagards Jan

0 Likes
Message 5 of 7

jan_tappenbeck
Collaborator
Collaborator

hi !

 

i testet the function FourFloatingViewports in a empty layout - the Viewport element will create, but there is an error by switch to modelspace.

 

2020-03-24_19h00_04.png

0 Likes
Message 6 of 7

ambrosl
Autodesk
Autodesk

If your layout only has one viewport, you should be able to simply just toggle Model and Paper space using the SwitchToPaperSpace and SwitchToModelSpace functions.

https://help.autodesk.com/view/OARX/2020/ENU/?guid=GUID-F0906774-90AD-4AD2-9894-E37ACEF8035A

 

If you want to get the viewports on the current layout, you can get the Block Table Record associated with the layout and then iterate its objects looking for the viewports.  Once you find the viewport, then you can set it current, switch to model space, zoom, and then switch back to paper space.

   ' Step through current layout
    <CommandMethod("StepLayout")>
    Public Shared Sub StepLayout()
        ' Get the current document and database, and start a transaction
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database

        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
            ' Reference the Layout Manager
            Dim acLayoutMgr As LayoutManager = LayoutManager.Current

            ' Get the current layout and output its name in the Command Line window
            Dim acLayout As Layout =
            acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout),
                              OpenMode.ForRead)

            ' Open the Block table for read
            Dim acBlkTbl As BlockTable
            acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)

            ' Open the Block table record for the current layout
            Dim acBlkTblRec As BlockTableRecord
            acBlkTblRec = acTrans.GetObject(acLayout.BlockTableRecordId,
                                        OpenMode.ForRead)

            ' Step through the Block table record
            For Each acObjId As ObjectId In acBlkTblRec
                acDoc.Editor.WriteMessage(vbLf & "DXF name: " & acObjId.ObjectClass().DxfName)
                acDoc.Editor.WriteMessage(vbLf & "ObjectID: " & acObjId.ToString())
                acDoc.Editor.WriteMessage(vbLf & "Handle: " & acObjId.Handle.ToString())
                acDoc.Editor.WriteMessage(vbLf)
            Next

            ' Dispose of the transaction
        End Using
    End Sub

 



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
0 Likes
Message 7 of 7

ambrosl
Autodesk
Autodesk

I'm not able to reproduct your error. Based on the Managed .NET libraries you are referencing, you might need to revise the following statements:

 

Current: Dim acVportLast As Viewport = Nothing

To: Dim acVportLast As DatabaseServices.Viewport = Nothing

 

Current: Using acVport As Viewport = New Viewport()

To: Using acVport As DatabaseServices.Viewport = New DatabaseServices.Viewport()

 

If that doesn't work and you are able to post a version of the drawing in which the error comes up, please post the drawing and I can take a look at it.



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
0 Likes