« Intersection Between Elements | Main | YouTube ADN Partner Channel »

June 25, 2010

Comments

After much searching I found the WPF window.owner property. I was unable to set the Revit window as the owner property because it requires a Window and not a IntPtr. Then I recently found the WindowInteropHelper class and was able to set the Owner property of the WPF window with The IntPtr similar to the above post. Two lines of code to implement prior to showing the window.

public void Run()
{
MyModelessWindow = new MyModelessWindow();

System.Windows.Interop.WindowInteropHelper x = new System.Windows.Interop.WindowInteropHelper(MyModelessWindow);
x.Owner = Process.GetCurrentProcess().MainWindowHandle;

MyModelessWindow.Show();
}

I'm quite happy about this discovery so I thought I'd share it.

Dear Mr West,

I'm quite happy for you too, and more than happy that you decided to share it :-)

Thank you!

Cheers, Jeremy.

Other way to get Revit main window handle (I think its easier):

1) Add reference to the AdWindows assembly (located at the same place where RevitAPI assembly) and set Copy Local property to false
2) Get Revit main window handle using static property ApplicationWindow of ComponentManager class in Autodesk.Windows namespace.

Now, you can use only one Property (ComponentManager.ApplicationWindow) instead two methods (get current process and main window handle)

Best regards, Victor.

Dear Victor,

This is absolutely beautiful, much nicer indeed!

I think we should promote this information to a main blog post right away.

Thank you!

Cheers, Jeremy.

Hello, Jeremy.
I've found many interesting classes and methods in AdWindows and UIFramework assemblies. Unfortunately it doesn't documented.

Now I use in me projects next:
1) ComponentManager.ApplicationWindow
2) UIFramework.RevitRibbonControl.RibonControl to determine if RebbonTab exists
3) Autodesk.Windows.TaskDialog - more flexible TaskDialog than Autodesk.Revit.UI.TaskDialog.

Best regards, Victor

Dear Victor,

Thank you, that sounds interesting indeed.

I did publish your previous hint about the parent window:

http://thebuildingcoder.typepad.com/blog/2012/03/melbourne-day-two.html#5

I think the other possibilities you mention sound exciting as well.

Please let us know if you implement anything that you think might be useful and worthwhile sharing, I'll be more than glad to publish them.

Thank you!

Cheers, Jeremy.

Hello Jeremy,

In Revit 2014 I'm having trouble showing a modeless form and calling a transaction whilst inside the form. It is giving me the error.

"starting a transation from an external application running outside of api context is not allowed"

I am using your method to send IWin32Window to show the form.

Any Ideas?

Kind Regards
David

Dear David,

Thank you for your query, both via ADN and this comment.

It looks as if you are calling the Revit API directly from your modeless dialog that is running in another thread.

As you should know, actually, that was never supported.

Now, in Revit 2014, an exception is raised when you make such an attempt.

You are lucky that it worked so far without corrupting anything.

The solution is described in depth on The Building Coder: simply google for "modeless site:thebuildingcoder.typepad.com".

In short, make use of the Idling event, or implement an external event, which is a simplified wrapper around that, and base you application on the ModelessForm_ExternalEvent and ModelessForm_IdlingEvent SDK samples.

I hope this helps.

Cheers, Jeremy.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Your Information

(Name and email address are required. Email address will not be displayed with the comment.)

Jeremy Tammik

AboutTopicsIndexSource