switching layout

switching layout

Anonymous
Not applicable
459 Views
3 Replies
Message 1 of 4

switching layout

Anonymous
Not applicable
This dont work when it meet a not used paperspace layout.
Can you help me?

Thanks

Public Sub MyZoom (MyDocument)

Dim Db As Database = MyDocument.Database
Dim Tr As Transaction = Db.TransactionManager.StartTransaction
Dim MyLayoutManager As Autodesk.AutoCAD.DatabaseServices.LayoutManager =
LayoutManager.Current
Try
Dim LayoutDict As DBDictionary = Tr.GetObject(Db.LayoutDictionaryId,
OpenMode.ForRead)
For Each id As DictionaryEntry In LayoutDict
Dim MyLayout As Layout = DirectCast(Tr.GetObject(DirectCast(id.Value,
ObjectId), OpenMode.ForRead), Layout)
MyLayoutManager.CurrentLayout = MyLayout.LayoutName
MyDocument.SendStringToExecute("_zoom" & vbCr & "_e" & vbCr, False, False,
False)
Next
Tr.Commit()
Finally
Tr.Dispose()
End Try

End Sub
0 Likes
460 Views
3 Replies
Replies (3)
Message 2 of 4

cadMeUp
Collaborator
Collaborator
You can try this, it uses AutoCAD interop so make sure you reference those assemblies. I replaced/removed lines from your code, you can see the differences here:
{code}
Dim Db As Database = MyDocument.Database
Dim Tr As Transaction = Db.TransactionManager.StartTransaction
Dim MyLayoutManager As Autodesk.AutoCAD.DatabaseServices.LayoutManager = LayoutManager.Current()
Dim acadApp As AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication

Try
Dim LayoutDict As DBDictionary = Tr.GetObject(Db.LayoutDictionaryId, OpenMode.ForRead)
For Each id As DictionaryEntry In LayoutDict
Dim MyLayout As Layout = CType(Tr.GetObject(id.Value, OpenMode.ForRead), Layout)
MyLayoutManager.CurrentLayout = MyLayout.LayoutName
acadApp.ZoomExtents()
Next
Finally
Tr.Commit()
End Try
{code}
0 Likes
Message 3 of 4

Anonymous
Not applicable

Thanks, but my problem is in the line
"MyLayoutManager.CurrentLayout = MyLayout.LayoutName":
i dont know because but it dont work.

It make "Error handler re-entered"
error.

 

You can try this, it uses
AutoCAD interop so make sure you reference those assemblies. I replaced/removed
lines from your code, you can see the differences here:
{code}
Dim Db As
Database = MyDocument.Database
Dim Tr As Transaction =
Db.TransactionManager.StartTransaction
Dim MyLayoutManager As
Autodesk.AutoCAD.DatabaseServices.LayoutManager = LayoutManager.Current()
Dim
acadApp As AcadApplication =
Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication

Try
Dim
LayoutDict As DBDictionary = Tr.GetObject(Db.LayoutDictionaryId,
OpenMode.ForRead)
For Each id As DictionaryEntry In LayoutDict
Dim
MyLayout As Layout = CType(Tr.GetObject(id.Value, OpenMode.ForRead),
Layout)
MyLayoutManager.CurrentLayout =
MyLayout.LayoutName

acadApp.ZoomExtents()
Next
Finally
Tr.Commit()
End
Try
{code}
0 Likes
Message 4 of 4

cadMeUp
Collaborator
Collaborator
It might help to see the rest of your code, specifically where the sub is being called.
I get an error and crash when calling your MyZoom sub in a command sub defined with the "CommandFlags.Session" flag:
{code}
<CommandMethod("LAYOUTZM", CommandFlags.Session)> _
Public Sub LAYOUTZM()
MyZoom(AcApp.DocumentManager.MdiActiveDocument)
End Sub
{code}
0 Likes