Re-Enable Screen Updating after Error

Re-Enable Screen Updating after Error

Matthew_Policelli
Advocate Advocate
455 Views
3 Replies
Message 1 of 4

Re-Enable Screen Updating after Error

Matthew_Policelli
Advocate
Advocate

Okay, so I know proper practice is to have an error handler that turns back on screen updating, but in this case I was still testing my code and screen updating never got turned back on.

 

Is there a way to re-enable screen updating without being able to interact with the application instance? Perhaps an iLogic that can be run from a separate instance that enables screen updating on all instances? Or some way through Task Manager or Command Prompt?

 

Or is the only solution to kill the instance in Task manager?

0 Likes
Accepted solutions (1)
456 Views
3 Replies
Replies (3)
Message 2 of 4

SevInventor
Advocate
Advocate
0 Likes
Message 3 of 4

Matthew_Policelli
Advocate
Advocate
Accepted solution

I was looking for a way to reactivate screen updating (i.e. from the command prompt or by running an iLogic in another Inventor instance) for those times that I accidentally commented out the section that turns screen updating back on. It doesn't happen very often, but it has before. And today, I somehow stopped the iLogic from completing without an error message, and screen updating stayed off and I had unsaved work 😞

 

However, I was able to figure out how to do it. I've only had one opportunity to test it, but it worked. Here's the code for anyone else who is interested:

 

For Each inventorInstance In Process.GetProcessesByName("Inventor")
	'Summary: For each Inventor process open, try to get the Inventor.Application
'object and enable screen updating and user interaction
'This should reactivate instances that were pushed into the background if screen updating was not turned back on Try Dim invApp As Inventor.Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") invApp.ScreenUpdating = True invApp.UserInterfaceManager.UserInteractionDisabled = False Catch ex As Exception MsgBox(ex.Message) End Try Next

 

0 Likes
Message 4 of 4

g.georgiades
Advocate
Advocate
Marshal.GetActiveObject("Inventor.Application") only ever returns the earliest started inventor instance. There is no (easy) way to COM hook into later instances. Your code would fail if the instance that froze was started after an instance is already open.

I also recommend using try/finally to help ensure the screen updating is turned back on, error or not.

For more info on the instance issue
https://stackoverflow.com/questions/6082580/any-way-to-get-object-from-rot-when-registered-name-is-n...
0 Likes