Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to avoid canceling export when user use scroll wheel

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
Act-3D
7052 Views, 9 Replies

How to avoid canceling export when user use scroll wheel

I have simple custom exporter based on IExportContext.

 

When during exporting I use scroll wheel then exporting is canceled in the middle of proccess (in random place).

 

IsCanceled() method always return false.
No exception is throw.

 

Question:

How to avoid canceling export when user use scroll wheel?

9 REPLIES 9
Message 2 of 10
Act-3D
in reply to: Act-3D

Any news about this issue?

Message 3 of 10
jeremytammik
in reply to: Act-3D

Dear Artur,

 

Sorry for the late response.

 

Hmm. I have no news so far. I wonder how this can be communicated to the development team. I don't know how to reproduce this. Do I need any special equipment? I don't have a scroll wheel to test with. I have never heard anyone else reporting anything similar. Can you provide a reproducible case?

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

Thank you!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 4 of 10
Act-3D
in reply to: jeremytammik

Hi Jeremy,

 

Thank you for answer.

 

Steps to reproduce:

 

1. Take any custom exporter

(for example: http://thebuildingcoder.typepad.com/blog/2013/07/graphics-pipeline-custom-exporter.html#5)

2. Load any Revit project 

3. Go to {3D} view

4. Start export

5. During export use mouse wheel

 

Message 5 of 10
Act-3D
in reply to: Act-3D

Hi Jeremy,

 

Did you manage to reproduce the problem?

 

/Artur

Message 6 of 10
jeremytammik
in reply to: Act-3D

Dear Artur,

 

Thank you for your update and renewed prompting.

 

Yes, I have reproduced the issue.

 

To do so, I migrated the sample you pointed out to Revit 2017 and posted it on GitHub:

 

https://github.com/jeremytammik/CustomExporterCollada

 

When I run the command and activate the mouse scroll wheel, an exception of type ExternalApplicationException is thrown from within the call to `exporter.Export(view3D)`, saying

 

  Object reference not set to an instance of an object.

 

I remember seeing the same exception being thrown once before.

 

It was reported in several comments by Helen Huang on

 

http://thebuildingcoder.typepad.com/blog/2013/07/adn-mesh-data-custom-exporter-to-json.html

 

I reported it to the development team in the database issue REVIT-94525 [API CustomExporter throws ExternalApplicationException after call to Finish].

 

This issue has been verified by the development team and classified as Code Fix Needed, submitting a new issue REVIT-100187 [API CustomExporter throws ExternalApplicationException after call to Finish].

 

That issue is still open.

 

I added a note of your report to it.

 

The case faced by Helen was easy to work around: simply add an exception handler around the call to `Finish`:

 

 

  try
  {
    exporter.Export( view );
  }
  catch( Autodesk.Revit.Exceptions.ExternalApplicationException ex )
  {
    Debug.Print( "ExternalApplicationException " + ex.Message );
  }

 

Here is the code for that case on GitHub:

 

https://github.com/jeremytammik/CustomExporterAdnMeshJson

 

Here is the fix I applied:

 

https://github.com/jeremytammik/CustomExporterAdnMeshJson/blob/master/CustomExporterAdnMeshJson/Comm...

 

I created a new GitHub repository for the sample you pointed to:

 

https://github.com/jeremytammik/CustomExporterCollada

 

It contains the code you point to in a solution for Revit 2017.

 

I added the same workaround to your code as well:

 

https://github.com/jeremytammik/CustomExporterCollada/commit/f734407aca033c42295e8748544d630ee51075c...

 

That seems to resolve the problem.

 

The fixed version is marked as release 2017.0.0.1:

 

https://github.com/jeremytammik/CustomExporterCollada/releases/tag/2017.0.0.1

 

I hope this helps.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 7 of 10
Act-3D
in reply to: jeremytammik

Thank you Jeremy,

 

The another workaround I found is to disable of scroll wheel for the time of export.

Message 8 of 10
jeremytammik
in reply to: Act-3D

How do you disable the use of the scroll wheel for the time of export, please?

 

Thank you!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 9 of 10
Act-3D
in reply to: jeremytammik

I used EnableWindow() function on view window.

The name of view window ("AfxFrameOrView140u") I found via Spy++.

 

Here is class I made. Tested on Revit 2017 so far.

 

 

 class RevitWindowUtility
    {
        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool EnableWindow(IntPtr hWnd, bool bEnable);

        static IntPtr viewWindowHwnd = IntPtr.Zero;

        public static IntPtr FindChildWindow(IntPtr hwndParent, string lpszClass, string lpszTitle)
        {
            return FindChildWindow(hwndParent, IntPtr.Zero, lpszClass, lpszTitle);
        }

        public static IntPtr FindChildWindow(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszTitle)
        {
            IntPtr hwnd = FindWindowEx(hwndParent, IntPtr.Zero, lpszClass, lpszTitle);
            if (hwnd == IntPtr.Zero)
            {
                IntPtr hwndChild = FindWindowEx(hwndParent, IntPtr.Zero, null, null);
                while (hwndChild != IntPtr.Zero && hwnd == IntPtr.Zero)
                {
                    hwnd = FindChildWindow(hwndChild, IntPtr.Zero, lpszClass, lpszTitle);
                    if (hwnd == IntPtr.Zero)
                    {
                        hwndChild = FindWindowEx(hwndParent, hwndChild, null, null);
                    }
                }
            }
            return hwnd;
        }

        public static IntPtr GetRevitMainWindowHwnd()
        {
            Process process = Process.GetCurrentProcess();
            return process.MainWindowHandle;
        }

        public static void FindViewWindowHwnd()
        {
            IntPtr mainWindowHwnd = GetRevitMainWindowHwnd();
            viewWindowHwnd = FindChildWindow(mainWindowHwnd, IntPtr.Zero, "AfxFrameOrView140u", null);
        }

        public static void EnableViewWindow(bool enable)
        {
            if (viewWindowHwnd == IntPtr.Zero)
            {
                FindViewWindowHwnd();
            }

            if (viewWindowHwnd != IntPtr.Zero)
                EnableWindow(viewWindowHwnd, enable);
        }
Message 10 of 10
jeremytammik
in reply to: Act-3D

Dear Artur,

Thank you for your super cool sample code snippet.

 

I hope others can find lots of interesting uses for this direct access to the view window.

 

Long live Spy++!

Cheers,

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community