<DllImport("acad.exe", CallingConvention:=CallingConvention.Cdecl, _
EntryPoint:="?acedSetCurrentVPort@@YA?AW4ErrorStatus@Acad@@PBVAcDbViewport@@@Z")> _
Public Shared Function acedSetCurrentVPort(ByVal AcDbVport As IntPtr) As IntPtr
End Function
<CommandMethod("CreateFloatingViewport")> _
Public Sub CreateFloatingViewport()
'' 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()
'' Open the Block table for read
Dim acBlkTbl As BlockTable
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, _
OpenMode.ForRead)
'' Open the Block table record Paper space for write
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.PaperSpace), _
OpenMode.ForWrite)
'' Switch to the previous Paper space layout
Application.SetSystemVariable("TILEMODE", 0)
acDoc.Editor.SwitchToPaperSpace()
'' Create a Viewport
Using acVport As Viewport = New Viewport()
acVport.CenterPoint = New Point3d(3.25, 3, 0)
acVport.Width = 6
acVport.Height = 5
'' Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acVport)
acTrans.AddNewlyCreatedDBObject(acVport, True)
'' Change the view direction
acVport.ViewDirection = New Vector3d(1, 1, 1)
'' Enable the viewport
acVport.On = True
'' Activate model space in the viewport
acDoc.Editor.SwitchToModelSpace()
'' Set the new viewport current via an imported ObjectARX function
acedSetCurrentVPort(acVport.UnmanagedObject)
End Using
'' Save the new objects to the database
acTrans.Commit()
End Using
End Sub