I am trying (desperately) to build a collection of viewports from a layout...
Why do I get a "FileNotFoundException was unhandled" alert when I try to execute this code?
I put "Public Shared Function doitsub" and "Public Shared Sub doit" into my form as a function and public sub respectively...and get the previously described File Not Found Error.
This problem is plaguing me, I think I may be at a breakthrough point in my programming if I can get this problem figured out.
First, thanks for all the help. It is really helpful.
This is what I have now, and it works, as far as it goes.
Public Shared Function doitsub() As IEnumerable(Of Autodesk.AutoCAD.DatabaseServices.Viewport)
Dim Editor As Autodesk.AutoCAD.EditorInput.Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim head As New List(Of Autodesk.AutoCAD.DatabaseServices.Viewport)()
Dim db As Database = HostApplicationServices.WorkingDatabase
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim vpids As ObjectIdCollection = db.GetViewports(False)
For Each vpid As ObjectId In vpids
head.Add(DirectCast(tr.GetObject(vpid, OpenMode.ForRead, False), Autodesk.AutoCAD.DatabaseServices.Viewport))
Next
tr.Commit()
End Using
Return head
End Function
<CommandMethod("doit")> _
Public Shared Sub doit()
Dim Editor As Autodesk.AutoCAD.EditorInput.Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Try
For Each vp As Autodesk.AutoCAD.DatabaseServices.Viewport In doitsub()
Editor.WriteMessage("" & Chr(10) & "" + vp.AnnotationScale.Scale.ToString())
Next
Catch ex As SystemException
Editor.WriteMessage("" & Chr(10) & "" + ex.Message)
Editor.WriteMessage("" & Chr(10) & "" + ex.StackTrace)
End Try
End Sub
Now a couple of questions. I know that to open an object for read I must wrap the read in a transaction. So, I see that we've done that in DoitSub, but then when we get to Doit, I don't have to wrap that (the code that gets the viewport properties) in a transaction? I mean, I can see that I don't - it works, but I would have expected a transaction here:-/
If I now want to modify the annotation scale for the viewport, it looks to me like I must:
- Start another transaction
- cycle through the viewports in Head
- re-opening each for write
- make the modification
- and commit the transaction
Again, thanks for all the examples. I'm seeing "slight of code" here that I didn't imagine possible.
Testing continues...