TheSwamp

Code Red => .NET => Topic started by: CrockettScience on April 15, 2019, 05:57:26 PM

Title: Editor.Command() in a Viewport inside a paperspace layout
Post by: CrockettScience on April 15, 2019, 05:57:26 PM
Our goal is to basically do the equivalent of clicking into a viewport and executing Zoom => Extents to capture everything that's in model space, but in a C# command. The problem is that just executing editor.command() executes the command in for the layout, not the viewport. Is there a way to emulate "clicking" into a view first before executing?
Title: Re: Editor.Command() in a Viewport inside a paperspace layout
Post by: MP on April 15, 2019, 06:30:15 PM
In LISP the equivalent would be:
- set the sysvar tilemode to 0 (if not already)
- set the document's mspace property to true (if not already)
- set the sysvar cvport to the target viewport's id (if not already)

No command calls required. Should be easy to replicate in C#. Cheers.
Title: Re: Editor.Command() in a Viewport inside a paperspace layout
Post by: Bryco on April 15, 2019, 07:51:19 PM
acadApp.SetSystemVariable("Tilemode", 0);   0 and 1 toggles
ed.SwitchToModelSpace  Makes a vp active                   
 ed.SwitchToPaperSpace();   makes paperspace active
Title: Re: Editor.Command() in a Viewport inside a paperspace layout
Post by: CrockettScience on April 16, 2019, 02:18:15 PM
Quote
ed.SwitchToModelSpace  Makes a vp active

So in the event you have multiple Vp's, how do you know which one will become active, and how can you specify that in .NET?
Title: Re: Editor.Command() in a Viewport inside a paperspace layout
Post by: kdub_nz on April 16, 2019, 03:50:32 PM
See if this helps

https://help.autodesk.com/view/OARX/2019/ENU/?guid=GUID-5FA86EF3-DEFD-4256-BB1C-56DAC32BD868
Code - C#: [Select]
  1.  
  2.             acLayoutMgr.CurrentLayout = acLayout.LayoutName;
  3.  
Title: Re: Editor.Command() in a Viewport inside a paperspace layout
Post by: Bryco on April 16, 2019, 06:47:34 PM
Here's a little code. The first viewport is always the paperspace viewport.
You could cycle through the viewports by size or scale etc to choose a particular one

Code: [Select]
LayoutManager lm = LayoutManager.Current;
                Layout layout = tr.GetObject(lm.GetLayoutId(lm.CurrentLayout), OpenMode.ForRead) as Layout;
                ObjectIdCollection vpIds = layout.GetViewports();

                if (vpIds.Count < 2)
                {
                    MessageBox.Show("There are no viewports in this layout, exiting:");
                    return;
                }

                if (db.PaperSpaceVportId == ed.CurrentViewportObjectId)// in paperspace viewport
                {
                    if (vpIds.Count == 2)
                    {
                        vp = tr.GetObject(vpIds[1], OpenMode.ForWrite) as Viewport;
                        vp.Locked = false;
                        ed.SwitchToModelSpace();
                    }
                    else
Title: Re: Editor.Command() in a Viewport inside a paperspace layout
Post by: CrockettScience on April 17, 2019, 02:52:58 PM
I see, now I get it. Thanks.