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
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register