Author Topic: Editor.Command() in a Viewport inside a paperspace layout  (Read 2768 times)

0 Members and 1 Guest are viewing this topic.

CrockettScience

  • Mosquito
  • Posts: 14
Editor.Command() in a Viewport inside a paperspace layout
« 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?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Editor.Command() in a Viewport inside a paperspace layout
« Reply #1 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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Bryco

  • Water Moccasin
  • Posts: 1882
Re: Editor.Command() in a Viewport inside a paperspace layout
« Reply #2 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

CrockettScience

  • Mosquito
  • Posts: 14
Re: Editor.Command() in a Viewport inside a paperspace layout
« Reply #3 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?

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2120
  • class keyThumper<T>:ILazy<T>
Re: Editor.Command() in a Viewport inside a paperspace layout
« Reply #4 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.  
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Bryco

  • Water Moccasin
  • Posts: 1882
Re: Editor.Command() in a Viewport inside a paperspace layout
« Reply #5 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

CrockettScience

  • Mosquito
  • Posts: 14
Re: Editor.Command() in a Viewport inside a paperspace layout
« Reply #6 on: April 17, 2019, 02:52:58 PM »
I see, now I get it. Thanks.