.NET

Reply
Valued Contributor
kcimos
Posts: 82
Registered: ‎02-18-2010
Message 1 of 7 (268 Views)

iterating viewports

268 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.

*Expert Elite*
_gile
Posts: 2,078
Registered: ‎04-29-2006
Message 2 of 7 (252 Views)

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
Valued Contributor
kcimos
Posts: 82
Registered: ‎02-18-2010
Message 3 of 7 (223 Views)

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++

Valued Contributor
kcimos
Posts: 82
Registered: ‎02-18-2010
Message 4 of 7 (220 Views)

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

Valued Contributor
kcimos
Posts: 82
Registered: ‎02-18-2010
Message 5 of 7 (207 Views)

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.

 

Valued Contributor
kcimos
Posts: 82
Registered: ‎02-18-2010
Message 6 of 7 (206 Views)

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.

*Expert Elite*
_gile
Posts: 2,078
Registered: ‎04-29-2006
Message 7 of 7 (193 Views)

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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community