• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Valued Contributor
    Posts: 60
    Registered: ‎02-18-2010

    iterating viewports

    189 Views, 6 Replies
    04-16-2012 04:07 PM

    can someone provide a clear explaination (& maybe an example (or pseudocode)) of iterating all of the viewports (PS & MS) of all layout tabs in a (currently open) drawing & make them current & then lets  display a MSGBOX indicating something about that current VP.

    Additionally, lets pretend that in an example DWG, the current VP is one of three MS VPs that exist in a layout tab called "TESTlayout" & we would like to reset that to the current layout & VP when our routine is finished.

    Please use plain text.
    *Expert Elite*
    Posts: 1,647
    Registered: ‎04-29-2006

    Re : iterating viewports

    04-16-2012 11:13 PM in reply to: kcimos

    Hi,

     

    Here's a little example:

     

            [CommandMethod("Foo")]
            public void foo()
            {
                Editor ed = AcAp.DocumentManager.MdiActiveDocument.Editor;
                Database db = HostApplicationServices.WorkingDatabase;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    DBDictionary layouts = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
                    foreach (DBDictionaryEntry entry in layouts)
                    {
                        if (entry.Key != "Model")
                        {
                            Layout layout = (Layout)tr.GetObject(entry.Value, OpenMode.ForRead);
                            string name = layout.LayoutName;
                            LayoutManager.Current.CurrentLayout = name;
                            foreach (ObjectId id in layout.GetViewports())
                            {
                                Viewport vp = (Viewport)tr.GetObject(id, OpenMode.ForRead);
                                int vpNum = vp.Number;
                                if (vpNum == 1)
                                {
                                    ed.SwitchToPaperSpace();
                                }
                                else
                                {
                                    ed.SwitchToModelSpace();
                                    AcAp.SetSystemVariable("cvport", vpNum);
                                }
                                AcAp.ShowAlertDialog("Layout: " + name + "\nViewport number: " + vpNum.ToString());
                            }
                        }
                    }
                    tr.Commit();
                }
            }

     

    Gilles Chanteau
    Please use plain text.
    Valued Contributor
    Posts: 60
    Registered: ‎02-18-2010

    Re: iterating viewports

    04-17-2012 02:24 PM in reply to: kcimos

    Thanks, that helps a bit.

     

    I'm still not sure how to find the current viewport. I've seen stuff where people talk about finding the word "*ACTIVE" in the viewtable (?), but I'n not clear about this & how that relates to the current VP.

     

    I'm using VB, but I'm semi-literate in C++

    Please use plain text.
    Valued Contributor
    Posts: 60
    Registered: ‎02-18-2010

    Re: iterating viewports

    04-17-2012 03:19 PM in reply to: kcimos

    got it, very simple. I had found an example in the autodesk documentation which lead me astray, but I figured it out:

     

    Dim strCurrentLayout AsString

    Dim iCurrentTilemode AsInteger = Application.GetSystemVariable("TILEMODE")

    Dim vpCurrentVP AsViewport

           

    Using Tx AsTransaction = ACF.Db.TransactionManager.StartTransaction()

    

                strCurrentLayout =LayoutManager.Current.CurrentLayout

               

    If iCurrentTilemode = 1 Then'      = Model Layout

               

    Else                                'you're in a layout, so get current VP

                    vpCurrentVP = (Tx.GetObject(ACF.acDoc.Editor.CurrentViewportObjectId,OpenMode.ForRead))          

     

    EndIf

    Please use plain text.
    Valued Contributor
    Posts: 60
    Registered: ‎02-18-2010

    Re: iterating viewports

    04-19-2012 03:26 PM in reply to: kcimos

    OK, I've implemented proper procedures to iterate each layout & each viewport ( PS too) w/in each layout. I'm trying to use VPLAYER via sendcommand (or SendStringToExecute) to freeze a particular layer in the VP. It will not work. I get no errors, but it just soesn't work. Except it will freeze the layer in the VP that was origianlly current (which is also the last VP switched to) (even if it is not supposed to (becasue the user (me) didn't select that layout for inclusion in the list of layouts to have the layer frozen in that layout's VPs)).

     

     

    It almost seems as if the SENDCOMMAND calls aren't being executed until the whole routine is finished, therefore only affecting the one VP.

     

    I tried  a SendStringToExecute & that didn't work either.

     

    I'd attach some code, but the routine is prretty complicated with multiple forms in different classes.

     

    Please use plain text.
    Valued Contributor
    Posts: 60
    Registered: ‎02-18-2010

    Re: iterating viewports

    04-19-2012 03:28 PM in reply to: kcimos

    PS

    in other sections of my code, the same exact VPLAYER string is used in a SENDCOMMAND & it works just fine. This section does NOT involve changing layouts or VPs.

    Please use plain text.
    *Expert Elite*
    Posts: 1,647
    Registered: ‎04-29-2006

    Re: iterating viewports

    04-19-2012 10:28 PM in reply to: kcimos

    Hi

     

    Try to avoid using Sendcommand or SendStringToExecute as they do not run synchronously.

     

    The Viewport class has the method you need:

    FreezeLayersInViewport()

    ThawLayersInViewport()

    ThawAllLayersInViewport()

     

    Gilles Chanteau
    Please use plain text.