Products

How to Use the SEDraftX Control in a WPF Application

Prolog


  


Designers who use custom programs for automating their routine design tasks that also need to interact with Solid Edge are constantly exploring newer platforms like the .Net based Windows Forms or ASP.Net and lately the new Windows Presentation Foundation or simply WPF.


 


Whereas hosting a Solid Edge ActiveX control like the SEPartX and SEDraftX are easily accomplished in a Windows Forms Application by drag-dropping from the Toolbox, the last installment by @ksbhadekar  showed how to use these controls in a ASP.Net web application.


 


This article further shows how to use the Solid Edge SEDraftX control in a WPF application.

In this article:


  



  • Prolog

  • Obtaining the ActiveX Control Wrapper: The Easy Way

  • Creating the ActiveX Control Wrapper: Under the Hood

  • Hosting the ActiveX Control in a WPF Window

  • Interacting with the ActiveX Control in WPF

  • Tip-Tricks

  • Epilog

Unlike a Windows Forms Application, the SEDraftX ActiveX control cannot be drag-dropped from the toolbox on to a WPF window. A wrapper is required to host a ActiveX control in WPF and there are two ways to obtain this wrapper.

Obtaining the ActiveX Control Wrapper: The Easy Way

The name is AxInterop.SEDRAFTXLib.dll and is readily available in the C:Program FilesSolid Edge STxProgram folder.

Note: [bulb .PNG] If you are interested in knowing how you can generate this wrapper to expand your knowledge base, continue reading, else skip to the section – Hosting the ActiveX Control on a WPF Page.

Creating the ActiveX Control Wrapper: Under the Hood

The procedure for generating the wrapper for any ActiveX control is amply detailed in this Microsoft knowledge article and in a nutshell, here’s the process for the Solid Edge SEDraftX control:


  1. Create a new Windows Forms Application.

  2. Add the SEDraftX control to the toolbox. To do this go to the General tab or any empty tab in the toolbox and right-click in the empty space in the tab. Then select Choose Items… from the context menu that appears.

 wpf01.png


  1. In the dialog that appears next, take the COM Components tab and scroll down to select the SEDraftX Control. Click OK.

wpf02.png


  1. Drop the Solid Edge SEDraftX control on the Form:

 wpf03.png


  1. Build the project and open the output folder; note the AxInterop.SEDraftXLib.dll which is the wrapper generated for use in WPF:


 wpf04.png

Recollect from previous section, this is the same wrapper that comes readily with Solid Edge.

Hosting the ActiveX Control in a WPF Window


  1. Start a WPF Application and add a reference to SEDraftX.dll that was either built using the steps in previous section or the one directly in the Solid Edge Program folder.


  1. Add the namespace as shown below to the XAML part of the WPF project:


 wpf05.png


  1. Drop the special WindowsFormsHost from the Toolbox on to the WPF’s XAML Window and add the SEActiveX line as below:


 wpf06.png

Interacting with the ActiveX Control in WPF

The name MySEDraftX from XAML can be used in the code-behind using VB.Net or CSharp to access the properties of the SEDrfatX control as below:

 wpf07.png

Tip-Tricks

When the WPF window is resized, the Draft file graphics may not update with it.

 wpf08.png

To overcome this problem, use the Resize event of the WPF window as below:

wpf09.png

Epilog

Windows Presentation Foundation or simply WPF is the latest development platform from Microsoft which is specifically released for a rich and polished user interface.

This in-depth and meticulously written article shows the various techniques to display Solid Edge Part, Draft and Assembly files with all its glitter and glory in the WPF UI.

The contents and code samples provided can be freely used as a knowledge base for all future developments projects that use WPF with Solid Edge.

~Tushar Suradkar


fb.pngSolid Edge Users Facebook Group – Let’s Sync

Tushar Suradkar

Solid Edge blogger, Programmer

More from this author

Leave a Reply

This article first appeared on the Siemens Digital Industries Software blog at https://blogs.stage.sw.siemens.com/solidedge/how-to-use-the-sedraftx-control-in-a-wpf-application/