Monday 15 December 2014

Making of Solid Edge Screen Capture Part 2

...continued from part 1

Declare two variables at the module level one each for Solid Edge and the View as below:


The Marshal class comes from System.Runtime.Interopservices namespace and its GetActiveObject method helps the macro to connect to the running instance of Solid Edge specified as a string "SolidEdge.Application".

This string is the ProgID or Program ID of Solid Edge which is stored in the Registry and can be searched, upon which you will also find lying nearby the installed path of (Edge.exe) i.e. Solid Edge from where it is accessed or invoked.

oView is the variable for the model window which we are interested in capturing to the clipboard.

The next two lines define the width and height of the captured image of the model view.


The Screen object comes from the System.Windows.Forms namespace which we added in spite this being a console app.

This sets the size of the image to the current size of the screen, though you can set it to any desired value or proportion beyond the current resolution of the screen.

Using the approach in this tutorial the model view cannot be stored to clipboard without first storing it to a temporary disk image file.

So create a temporary disk image file name to store the captured image:


The Path class in above line comes from System.IO namespace imported at the top of the code window.

The GetTempPath method returns a string for the system's temporary folder path. On my machine it is:

C:\Documents and Settings\XYZ\Local Settings\Temp\

12 Note: The temp path string comes with a \ added at the end, so no need to append one when concatenating to the JPEG file name.

Next, using Solid Edge API's SaveAsImage method of the View object to save the model window to the JPEG image file with the width and height calculated from the screen size earlier.


This line creates an image file in the temp folder, so of you go out and check your temp folder, the file should be lying there.

12 Tip: An easy way to open your system's Temp folder would be typing %temp% in the Explorer's address bar.

Continued to part 3...

Index of all Solid Edge Tips, Tutorials and Videos...

No comments:

Post a Comment