.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trouble Creating Viewport in VB.NET

1 REPLY 1
Reply
Message 1 of 2
michael.coffman
574 Views, 1 Reply

Trouble Creating Viewport in VB.NET

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

 

1 REPLY 1
Message 2 of 2
SENL1362
in reply to: michael.coffman

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost