Author Topic: Select all paperspace pviewports - NOT paperspace itself  (Read 13359 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: Select all paperspace pviewports - NOT paperspace itself
« Reply #15 on: May 30, 2008, 12:21:13 PM »
Mike, any chance we can get you to convert to C#?   :-D

I spent some time with C and C++ years ago (turbo C 3, I think) and was, shall we say, overwhelmed.  I generated a couple of simple console apps, but didn't ever really get proficient.  Because of this, and the time I have with VB/VBA I assumed that I would come up to speed more quickly with VB.net than I would with C#.

Are there things I could do with C# that I won't be able to do with VB?

It’s just my personal attempt to convert .NETers over to a C style language, because I can’t read VB.

Glenn R

  • Guest
Re: Select all paperspace pviewports - NOT paperspace itself
« Reply #16 on: May 30, 2008, 12:25:15 PM »
Ditto that.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Select all paperspace pviewports - NOT paperspace itself
« Reply #17 on: May 30, 2008, 07:24:50 PM »

nice example Daniel.


[< .. >
It’s just my personal attempt to convert .NETers over to a C style language, because I can’t read VB.


 :-D

I can read it, but my therapist has advised me not to.   :angel:
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

pellacad

  • Guest
Re: Select all paperspace pviewports - NOT paperspace itself
« Reply #18 on: August 13, 2009, 10:13:05 AM »
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.

Code: [Select]
  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...

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: Select all paperspace pviewports - NOT paperspace itself
« Reply #19 on: August 13, 2009, 10:36:37 AM »
I can't see anything in that code that would cause that error
maybe you can post your solution so we can take a look?

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: Select all paperspace pviewports - NOT paperspace itself
« Reply #20 on: August 13, 2009, 11:43:32 AM »
Hows my VB  :lol:

Code: [Select]
<CommandMethod("doit")> _
Public Shared Sub doit()
    Dim editor As Editor = Application.DocumentManager.MdiActiveDocument.Editor
    Dim db As Database = HostApplicationServices.WorkingDatabase
    Try
        Using tr As Transaction = db.TransactionManager.StartTransaction
            Dim ldid As ObjectId = db.LayoutDictionaryId
            Dim ld As DBDictionary = TryCast(tr.GetObject(ldid, OpenMode.ForRead, False),DBDictionary)
            Dim de As DBDictionaryEntry
            For Each de In ld
                Dim layout As Layout = TryCast(tr.GetObject(de.Value, OpenMode.ForRead, False),Layout)
                Dim ids As ObjectIdCollection = layout.GetViewports
                If (ids.Count > 0) Then
                    Dim i As Integer
                    For i = 1 To ids.Count - 1
                        Dim vp As Viewport = TryCast(tr.GetObject(ids.Item(i), OpenMode.ForRead, False),Viewport)
                        If (Not vp Is Nothing) Then
                            editor.WriteMessage(ChrW(10) & "Layout {0} , VP#{1} Width = {2}",
                                                         New Object() { layout.LayoutName, i, vp.Width })
                        End If
                    Next i
                End If
            Next
            tr.Commit
        End Using
    Catch ex As Exception
        editor.WriteMessage(ex.StackTrace)
    End Try
End Sub

Glenn R

  • Guest
Re: Select all paperspace pviewports - NOT paperspace itself
« Reply #21 on: August 17, 2009, 09:13:56 AM »
I agree with Dan - the FileNotFoundException is being thrown from somewhere else in your code.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Select all paperspace pviewports - NOT paperspace itself
« Reply #22 on: August 24, 2009, 01:52:34 AM »
Hows my VB  :lol:

Code: [Select]
<CommandMethod("doit")> _
Public Shared Sub doit()
    Dim editor As Editor = Application.DocumentManager.MdiActiveDocument.Editor
    Dim db As Database = HostApplicationServices.WorkingDatabase
// ..>>
<<..//
 End Sub

Dim humour ??
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: Select all paperspace pviewports - NOT paperspace itself
« Reply #23 on: August 24, 2009, 02:25:14 AM »
I've been known to dim on occasion