.NET

Reply
Member
mcoffman
Posts: 4
Registered: ‎08-16-2007
Message 1 of 2 (167 Views)

Trouble Creating Viewport in VB.NET

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

Hi,

 

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, "")
        myDB.CloseInput(True)

        '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
                .SetDatabaseDefaults()
                .CenterPoint = ptCenter
                .Height = dblHeight
                .Width = dblWidth
                .CustomScale = (1.0 / 96)
            End With
            btrPs.AppendEntity(myVP)
            trx.AddNewlyCreatedDBObject(myVP, True)

            'myVP.On = True

            trx.Commit()

            'Clean up file handles.
            btrPs.Dispose()
            blockBt.Dispose()

        End Using

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

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

    End Sub

 

Mentor
SENL1362
Posts: 150
Registered: ‎07-20-2011
Message 2 of 2 (110 Views)

Re: Trouble Creating Viewport in VB.NET

01-24-2014 09:29 AM in reply to: mcoffman
QuickReply:
- 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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community