[Solved] Cannot cast to SolidEdge.Framework.Interop.Window

Pioneer
Pioneer

Hey everyone,

 

The following code throws a System.InvalidCastException, although I'm pretty sure I'm doing it the right way:

 

SolidEdge.Framework.Interop.Window win = null;
win = (SolidEdge.Framework.Interop.Window)Application.ActiveWindow;

 

whereas "Application" is a property of the type SolidEdge.Framework.Interop.Application.

 

I also tried to access the Window through:

 

SolidEdge.Draft.Interop.DraftDocument.Windows.Item(i), but the cast also fails there.

 

What am I missing?

 

3 REPLIES

Re: Cannot cast to SolidEdge.Framework.Interop.Window

Pioneer
Pioneer

Problem solved:

 

Since I was in the 2D environment, I had to cast to SolidEdge.Draft.Interop.SheetWindow. The normal Window only works for 3D appearantly.

Re: Cannot cast to SolidEdge.Framework.Interop.Window

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

This is where Spy for Solid Edge can save you a lot of time and headaches. It takes the guesswork out of what the runtime type is of an object by telling you directly in the UI.

 

Capture.png

Jason Newell
Applications Architect
www.jasonnewell.net

Re: Cannot cast to SolidEdge.Framework.Interop.Window

Pioneer
Pioneer

Wow thanks, thats absolutely awesome! I could have needed that a lot during my last project. Without this tool, its a lot of guessing and trial and error. I finished my project now, but I will use it in the future for sure!