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

switching layout

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
341 Views, 3 Replies

switching layout

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
3 REPLIES 3
Message 2 of 4
cadMeUp
in reply to: Anonymous

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}
Message 3 of 4
Anonymous
in reply to: Anonymous


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}
Message 4 of 4
cadMeUp
in reply to: Anonymous

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}

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