Create Layout

Create Layout

Civil3DReminders
Collaborator Collaborator
1,469 Views
5 Replies
Message 1 of 6

Create Layout

Civil3DReminders
Collaborator
Collaborator
I'm able to kind of create a new Layout and a viewport, the layout shows up but doesn't appear to be correctly created. If I try to zoom within layout I get an error message of "eBadPaperspaceView". Within Autocad I have to toggle back and forth between the layouts to have it work as expected w/in Autocad. Not quite sure what step I'm missing. Zoom is from the .NET developer's guide, but I don't think that code is my problem.

Thanks

{code}

Private Shared Function CreateNewLayout(ByVal i As Integer) As ObjectId

Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim doclock As DocumentLock = doc.LockDocument()
Dim db As Database = doc.Database
Dim trm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = db.TransactionManager
Try
Using tr As Transaction = trm.StartTransaction()

Dim oLayoutManager As LayoutManager = Autodesk.AutoCAD.DatabaseServices.LayoutManager.Current
Try
Dim oLayoutObjId As ObjectId
oLayoutObjId = oLayoutManager.CreateLayout("StructureReport" & i)
Dim oLayout As Layout = tr.GetObject(oLayoutObjId, OpenMode.ForWrite)
oLayout.Initialize()
' initialize the layout
ed.Regen()
CreateNewLayout = oLayoutObjId
Catch
Exit Function
End Try

tr.Commit()

End Using
doclock.Dispose()
Catch

End Try

End Function

Private Shared Function CreateNewViewport(ByVal sLayoutName As String, ByVal oCntrPt As Point3d) As Boolean

'' Get the current document and database, and start a transaction
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = acDoc.Editor
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)

Dim objId As ObjectId
For Each objId In acBlkTbl
Dim oBlockTableRec As BlockTableRecord = DirectCast(acTrans.GetObject(objId, OpenMode.ForWrite), BlockTableRecord)
If oBlockTableRec.IsLayout Then

Dim oLayout As Layout
oLayout = DirectCast(acTrans.GetObject(oBlockTableRec.LayoutId, OpenMode.ForWrite), Layout)

If oLayout.LayoutName = sLayoutName Then

Dim oBlkTableRec As BlockTableRecord = acTrans.GetObject(oLayout.BlockTableRecordId, OpenMode.ForWrite)

'' Create a Viewport
Dim acVport As Viewport = New Viewport()
acVport.SetDatabaseDefaults()
acVport.CenterPoint = New Point3d(4.25, 5.5, 0)
acVport.Width = 8.5
acVport.Height = 11.0

'' Add the new object to the block table record and the transaction
oBlkTableRec.AppendEntity(acVport)
acTrans.AddNewlyCreatedDBObject(acVport, True)

'' Change the view direction
acVport.ViewDirection = New Vector3d(0, 0, 1)

Dim oLayoutManager As LayoutManager = LayoutManager.Current
oLayoutManager.CurrentLayout = sLayoutName

'' Enable the viewport
acVport.On = True
acVport.CustomScale = 1

'' Set the new viewport current via an imported ObjectARX function
acedSetCurrentVPort(acVport.UnmanagedObject)

Zoom(New Point3d(), New Point3d(), oCntrPt, 1)

CreateNewViewport = True
Exit For
End If
End If
Next

acTrans.Commit()
End Using
End Function

{code}
0 Likes
1,470 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
AFAIK, you have to activate a new layout before you
can do anything with it, because AutoCAD doesn't
create the paper space viewport until the first time a
layout is activated.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6388272@discussion.autodesk.com...
I'm able to kind of create a new Layout and a viewport, the layout shows up but
doesn't appear to be correctly created. If I try to zoom within layout I get an
error message of "eBadPaperspaceView". Within Autocad I have to toggle back and
forth between the layouts to have it work as expected w/in Autocad. Not quite
sure what step I'm missing. Zoom is from the .NET developer's guide, but I don't
think that code is my problem.

Thanks

{code}

Private Shared Function CreateNewLayout(ByVal i As Integer) As ObjectId

Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim doclock As DocumentLock = doc.LockDocument()
Dim db As Database = doc.Database
Dim trm As Autodesk.AutoCAD.DatabaseServices.TransactionManager =
db.TransactionManager
Try
Using tr As Transaction = trm.StartTransaction()

Dim oLayoutManager As LayoutManager =
Autodesk.AutoCAD.DatabaseServices.LayoutManager.Current
Try
Dim oLayoutObjId As ObjectId
oLayoutObjId = oLayoutManager.CreateLayout("StructureReport"
& i)
Dim oLayout As Layout = tr.GetObject(oLayoutObjId,
OpenMode.ForWrite)
oLayout.Initialize()
' initialize the layout
ed.Regen()
CreateNewLayout = oLayoutObjId
Catch
Exit Function
End Try

tr.Commit()

End Using
doclock.Dispose()
Catch

End Try

End Function

Private Shared Function CreateNewViewport(ByVal sLayoutName As String, ByVal
oCntrPt As Point3d) As Boolean

'' Get the current document and database, and start a transaction
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = acDoc.Editor
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)

Dim objId As ObjectId
For Each objId In acBlkTbl
Dim oBlockTableRec As BlockTableRecord =
DirectCast(acTrans.GetObject(objId, OpenMode.ForWrite), BlockTableRecord)
If oBlockTableRec.IsLayout Then

Dim oLayout As Layout
oLayout =
DirectCast(acTrans.GetObject(oBlockTableRec.LayoutId, OpenMode.ForWrite),
Layout)

If oLayout.LayoutName = sLayoutName Then

Dim oBlkTableRec As BlockTableRecord =
acTrans.GetObject(oLayout.BlockTableRecordId, OpenMode.ForWrite)

'' Create a Viewport
Dim acVport As Viewport = New Viewport()
acVport.SetDatabaseDefaults()
acVport.CenterPoint = New Point3d(4.25, 5.5, 0)
acVport.Width = 8.5
acVport.Height = 11.0

'' Add the new object to the block table record and the
transaction
oBlkTableRec.AppendEntity(acVport)
acTrans.AddNewlyCreatedDBObject(acVport, True)

'' Change the view direction
acVport.ViewDirection = New Vector3d(0, 0, 1)

Dim oLayoutManager As LayoutManager =
LayoutManager.Current
oLayoutManager.CurrentLayout = sLayoutName

'' Enable the viewport
acVport.On = True
acVport.CustomScale = 1

'' Set the new viewport current via an imported
ObjectARX function
acedSetCurrentVPort(acVport.UnmanagedObject)

Zoom(New Point3d(), New Point3d(), oCntrPt, 1)

CreateNewViewport = True
Exit For
End If
End If
Next

acTrans.Commit()
End Using
End Function

{code}
0 Likes
Message 3 of 6

Anonymous
Not applicable
Actually, ever since Acad 2008 you can use the Initialize method to do that
without making the layout active.

"Tony Tanzillo" wrote in message
news:6388998@discussion.autodesk.com...
AFAIK, you have to activate a new layout before you
can do anything with it, because AutoCAD doesn't
create the paper space viewport until the first time a
layout is activated.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6388272@discussion.autodesk.com...
I'm able to kind of create a new Layout and a viewport, the layout shows up
but
doesn't appear to be correctly created. If I try to zoom within layout I get
an
error message of "eBadPaperspaceView". Within Autocad I have to toggle back
and
forth between the layouts to have it work as expected w/in Autocad. Not
quite
sure what step I'm missing. Zoom is from the .NET developer's guide, but I
don't
think that code is my problem.

Thanks

{code}

Private Shared Function CreateNewLayout(ByVal i As Integer) As ObjectId

Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim doclock As DocumentLock = doc.LockDocument()
Dim db As Database = doc.Database
Dim trm As Autodesk.AutoCAD.DatabaseServices.TransactionManager =
db.TransactionManager
Try
Using tr As Transaction = trm.StartTransaction()

Dim oLayoutManager As LayoutManager =
Autodesk.AutoCAD.DatabaseServices.LayoutManager.Current
Try
Dim oLayoutObjId As ObjectId
oLayoutObjId =
oLayoutManager.CreateLayout("StructureReport"
& i)
Dim oLayout As Layout = tr.GetObject(oLayoutObjId,
OpenMode.ForWrite)
oLayout.Initialize()
' initialize the layout
ed.Regen()
CreateNewLayout = oLayoutObjId
Catch
Exit Function
End Try

tr.Commit()

End Using
doclock.Dispose()
Catch

End Try

End Function

Private Shared Function CreateNewViewport(ByVal sLayoutName As String,
ByVal
oCntrPt As Point3d) As Boolean

'' Get the current document and database, and start a transaction
Dim acDoc As Document =
Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = acDoc.Editor
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)

Dim objId As ObjectId
For Each objId In acBlkTbl
Dim oBlockTableRec As BlockTableRecord =
DirectCast(acTrans.GetObject(objId, OpenMode.ForWrite), BlockTableRecord)
If oBlockTableRec.IsLayout Then

Dim oLayout As Layout
oLayout =
DirectCast(acTrans.GetObject(oBlockTableRec.LayoutId, OpenMode.ForWrite),
Layout)

If oLayout.LayoutName = sLayoutName Then

Dim oBlkTableRec As BlockTableRecord =
acTrans.GetObject(oLayout.BlockTableRecordId, OpenMode.ForWrite)

'' Create a Viewport
Dim acVport As Viewport = New Viewport()
acVport.SetDatabaseDefaults()
acVport.CenterPoint = New Point3d(4.25, 5.5, 0)
acVport.Width = 8.5
acVport.Height = 11.0

'' Add the new object to the block table record and
the
transaction
oBlkTableRec.AppendEntity(acVport)
acTrans.AddNewlyCreatedDBObject(acVport, True)

'' Change the view direction
acVport.ViewDirection = New Vector3d(0, 0, 1)

Dim oLayoutManager As LayoutManager =
LayoutManager.Current
oLayoutManager.CurrentLayout = sLayoutName

'' Enable the viewport
acVport.On = True
acVport.CustomScale = 1

'' Set the new viewport current via an imported
ObjectARX function
acedSetCurrentVPort(acVport.UnmanagedObject)

Zoom(New Point3d(), New Point3d(), oCntrPt, 1)

CreateNewViewport = True
Exit For
End If
End If
Next

acTrans.Commit()
End Using
End Function

{code}
0 Likes
Message 4 of 6

Civil3DReminders
Collaborator
Collaborator
Looks like going into Model space after creating the layout and initializing the viewport gets it to work better. Something still is not correct since I can't delete the initialized viewport or modify it.

{code}
' initialize the layout
oLayout.Initialize()

oLayoutManager.CurrentLayout = "StructureReport" & i

Application.SetSystemVariable("TILEMODE", 1)
{code}
0 Likes
Message 5 of 6

Anonymous
Not applicable
Thanks for pointing that out.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

"Art Cooney" wrote in message
news:6389003@discussion.autodesk.com...
Actually, ever since Acad 2008 you can use the Initialize method to do that
without making the layout active.

"Tony Tanzillo" wrote in message
news:6388998@discussion.autodesk.com...
AFAIK, you have to activate a new layout before you
can do anything with it, because AutoCAD doesn't
create the paper space viewport until the first time a
layout is activated.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6388272@discussion.autodesk.com...
I'm able to kind of create a new Layout and a viewport, the layout shows up
but
doesn't appear to be correctly created. If I try to zoom within layout I get
an
error message of "eBadPaperspaceView". Within Autocad I have to toggle back
and
forth between the layouts to have it work as expected w/in Autocad. Not
quite
sure what step I'm missing. Zoom is from the .NET developer's guide, but I
don't
think that code is my problem.

Thanks

{code}

Private Shared Function CreateNewLayout(ByVal i As Integer) As ObjectId

Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim doclock As DocumentLock = doc.LockDocument()
Dim db As Database = doc.Database
Dim trm As Autodesk.AutoCAD.DatabaseServices.TransactionManager =
db.TransactionManager
Try
Using tr As Transaction = trm.StartTransaction()

Dim oLayoutManager As LayoutManager =
Autodesk.AutoCAD.DatabaseServices.LayoutManager.Current
Try
Dim oLayoutObjId As ObjectId
oLayoutObjId =
oLayoutManager.CreateLayout("StructureReport"
& i)
Dim oLayout As Layout = tr.GetObject(oLayoutObjId,
OpenMode.ForWrite)
oLayout.Initialize()
' initialize the layout
ed.Regen()
CreateNewLayout = oLayoutObjId
Catch
Exit Function
End Try

tr.Commit()

End Using
doclock.Dispose()
Catch

End Try

End Function

Private Shared Function CreateNewViewport(ByVal sLayoutName As String,
ByVal
oCntrPt As Point3d) As Boolean

'' Get the current document and database, and start a transaction
Dim acDoc As Document =
Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = acDoc.Editor
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)

Dim objId As ObjectId
For Each objId In acBlkTbl
Dim oBlockTableRec As BlockTableRecord =
DirectCast(acTrans.GetObject(objId, OpenMode.ForWrite), BlockTableRecord)
If oBlockTableRec.IsLayout Then

Dim oLayout As Layout
oLayout =
DirectCast(acTrans.GetObject(oBlockTableRec.LayoutId, OpenMode.ForWrite),
Layout)

If oLayout.LayoutName = sLayoutName Then

Dim oBlkTableRec As BlockTableRecord =
acTrans.GetObject(oLayout.BlockTableRecordId, OpenMode.ForWrite)

'' Create a Viewport
Dim acVport As Viewport = New Viewport()
acVport.SetDatabaseDefaults()
acVport.CenterPoint = New Point3d(4.25, 5.5, 0)
acVport.Width = 8.5
acVport.Height = 11.0

'' Add the new object to the block table record and
the
transaction
oBlkTableRec.AppendEntity(acVport)
acTrans.AddNewlyCreatedDBObject(acVport, True)

'' Change the view direction
acVport.ViewDirection = New Vector3d(0, 0, 1)

Dim oLayoutManager As LayoutManager =
LayoutManager.Current
oLayoutManager.CurrentLayout = sLayoutName

'' Enable the viewport
acVport.On = True
acVport.CustomScale = 1

'' Set the new viewport current via an imported
ObjectARX function
acedSetCurrentVPort(acVport.UnmanagedObject)

Zoom(New Point3d(), New Point3d(), oCntrPt, 1)

CreateNewViewport = True
Exit For
End If
End If
Next

acTrans.Commit()
End Using
End Function

{code}
0 Likes
Message 6 of 6

Civil3DReminders
Collaborator
Collaborator
My issue was solved by getting the 1 viewport in the Layout instead of the 0 viewport.

Christopher
0 Likes