Posts: 4
Registered: ‎08-16-2007
Message 1 of 2 (200 Views)

Trouble Creating Viewport in VB.NET

200 Views, 1 Replies
01-10-2014 11:49 AM



I have a routine that custom builds sheet sets for the users in my company. As a part of that routine, I'm trying to write a sub that takes a filepath input and creates a viewport on the layout of the dwg file. The routine works, insomuch as a viewport is created, however none of the parameters (CenterPoint, Height, Width, Scale) are set. I can modify the parameters and re-run the routine and the output is the same. Any suggestions? The code for the sub is below. Thanks!


    Public Sub CreateViewPort(ToFile As String)
        Dim hostPath As String = ToFile
        Dim myDB As Database = New Database(False, True)
        Dim oldDB As Database = HostApplicationServices.WorkingDatabase
        myDB.ReadDwgFile(hostPath, FileShare.ReadWrite, False, "")

        'Set active layer
        SSLayerCommands.ActiveLayer(myDB, "G-ANNO-VPRT")
        HostApplicationServices.WorkingDatabase = myDB
        Using trx As Transaction = myDB.TransactionManager.StartTransaction()
            Dim blockBt As BlockTable = trx.GetObject(myDB.BlockTableId, OpenMode.ForRead)
            Dim btrPs As BlockTableRecord = trx.GetObject(blockBt(BlockTableRecord.PaperSpace), OpenMode.ForWrite)
            Dim ptCenter As Point3d
            Dim dblHeight As Double
            Dim dblWidth As Double
            Select Case DwgSize
                Case "30 x 42 - Arch E1 Size"
                    ptCenter = New Point3d(17.5, 17.0, 0.0)
                    dblHeight = 10
                    dblWidth = 10
                Case Else
                    ptCenter = New Point3d(17.5, 17.0, 0.0)
                    dblHeight = 10
                    dblWidth = 10
            End Select

            Dim myVP As Viewport = New Viewport
            With myVP
                .CenterPoint = ptCenter
                .Height = dblHeight
                .Width = dblWidth
                .CustomScale = (1.0 / 96)
            End With
            trx.AddNewlyCreatedDBObject(myVP, True)

            'myVP.On = True


            'Clean up file handles.

        End Using

        SSLayerCommands.ActiveLayer(myDB, "F-ANNO-TEXT")

        myDB.SaveAs(hostPath, DwgVersion.Current)
        HostApplicationServices.WorkingDatabase = oldDB

    End Sub


Posts: 231
Registered: ‎07-20-2011
Message 2 of 2 (143 Views)

Re: Trouble Creating Viewport in VB.NET

01-24-2014 09:29 AM in reply to: mcoffman
- I doubt you can do much with layouts and Viewports without the screen, i.e. the db connected to a Document.
- you didn't activate a layout in you're code.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.