Author Topic: Detect zoom in locked viewport  (Read 1775 times)

0 Members and 1 Guest are viewing this topic.

latour_g

  • Newt
  • Posts: 184
Detect zoom in locked viewport
« on: June 02, 2014, 01:43:05 PM »
I want to detect when a user is zooming in a locked viewport.

I have try this :

Code: [Select]
public static void SystemVariableChanged(object o, Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventArgs e)
{
        if (e.Name.Equals("CVPORT") && (Int16)AcadApp.GetSystemVariable("TILEMODE") == 0 && ((Int16)AcadApp.GetSystemVariable("CVPORT") == 1))
        {
        ...
        }
}

but it's not good because if the user click outside the viewport, it will also go in this statement and I don't want that.

Then I have try this code to distinguish if the user is in a viewport or not :

Code: [Select]
public static void SystemVariableChanged(object o, Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventArgs e)
{
        if (e.Name.Equals("CVPORT") && (Int16)AcadApp.GetSystemVariable("TILEMODE") == 0 && ((Int16)AcadApp.GetSystemVariable("CVPORT") == 1))
        {
               try
              {     
                       Document doc = AcadApp.DocumentManager.MdiActiveDocument;
                       Database db = doc.Database;
                       Editor ed = doc.Editor;
                       Viewport vp = (Viewport)ed.ActiveViewportId.GetObject(OpenMode.ForWrite);
                       MessageBox.Show("Someone is zooming in a locked viewport");
              }

               catch
              {
                       MessageBox.Show("No viewport was selected.");
               }
        }
}

but it's not working since there is no active viewport when the zoom is done in a locked viewport.


WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Detect zoom in locked viewport
« Reply #1 on: June 03, 2014, 01:28:59 AM »
but it's not working since there is no active viewport when the zoom is done in a locked viewport.
What makes you think there is no active viewport?
is it the catch statement saying 'no viewport selected'?

Just thinking that if you are not allowed to open for write then you may be misunderstanding the reason for the exception.

latour_g

  • Newt
  • Posts: 184
Re: Detect zoom in locked viewport
« Reply #2 on: June 03, 2014, 09:57:21 AM »
Sorry, there is an active viewport indeed.  The error is eLockViolation so I can only read it.

I would have use vp.Locked but it's useless since it doesn't give me the propertie of the viewport I was zooming in.

I found a workaround at my problem.  I use the property ''isQuiescent'' of AcadApp.DocumentManager.MdiActiveDocument.Editor.

When I zoom in a lock viewport, isQuiscent = true.  When I'm in a viewport and I click out of it, isQuiescent = false.

It's the only way I found to distinguish those two actions.