static void SaveAsImage(SolidEdgeDraft.SheetWindow sheetWidow) { string[] extensions = { ".jpg", ".bmp", ".tif" }; Guid guid = Guid.NewGuid(); string folder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); double resolution = 1; // DPI - Larger values have better quality but also lead to larger file. int colorDepth = 24; int width = sheetWidow.UsableWidth; int height = sheetWidow.UsableHeight; // Save each extension. foreach (string extension in extensions) { // File saved to desktop. string filename = Path.ChangeExtension(guid.ToString(), extension); filename = Path.Combine(folder, filename); // You can specify .bmp (Windows Bitmap), .tif (TIFF), or .jpg (JPEG). sheetWidow.SaveAsImage( FileName: filename, Width: width, Height: height, Resolution: resolution, ColorDepth: colorDepth, ImageQuality: SolidEdgeFramework.SeImageQualityType.seImageQualityHigh, Invert: false); Console.WriteLine("Saved '{0}'.", filename); } }
static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.White; Console.Title = "Get info - SE"; Console.WriteLine("Returns the line information of the 2D model opened in SolidEdge"); Console.WriteLine("Andrea Veglia"); Console.WriteLine("Caution may affect the work done in Solid Edge \n"); Console.WriteLine("Press any key to launch the application. "); Console.ReadKey(); Console.Clear(); //SET THE LOG FILE NAME string NOME_FILE_LOG = Path.Combine("LOGS", "LOG_" + DateTime.UtcNow.ToString("MM'-'dd'-'yyyy'.'HH'-'mm'-'ss") + ".txt"); //CREATE THE LOG FILE CREATE_FILE_LOG(NOME_FILE_LOG); bool?se_close = null; try { SolidEdgeFramework.Application seApp = null; //I LOOK FOR THE SOLID EDGE PROCESS Type type = Type.GetTypeFromProgID("SolidEdge.Application"); Process[] remoteAll = Process.GetProcessesByName("Edge"); if (remoteAll.Count() > 0) { //SOLID EDGE IS ALREADY OPEN seApp = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); se_close = false; } else { Console.WriteLine("Solid edge is not open."); se_close = true; } if (se_close == false) { //SET THE ACTIVE WINDOW SolidEdgeDraft.SheetWindow win = (SolidEdgeDraft.SheetWindow)seApp.ActiveWindow; win.Fit(); var HEIGHT = win.ActiveSheet.SheetSetup.SheetHeight.ToString(); var WIDTH = win.ActiveSheet.SheetSetup.SheetWidth.ToString(); var DIMENSIONS = win.ActiveSheet.Dimensions.ToString(); WRITE_FILE_LOG("HEIGHT: " + HEIGHT, NOME_FILE_LOG, false); WRITE_FILE_LOG("WIDTH: " + WIDTH, NOME_FILE_LOG, false); WRITE_FILE_LOG("DIMENSIONI: " + DIMENSIONS, NOME_FILE_LOG, false); var line = win.ActiveSheet.Lines2d; var FOUND_LINES = line.Count; WRITE_FILE_LOG("FOUND LINES: " + FOUND_LINES.ToString(), NOME_FILE_LOG, false); for (int i = 1; i <= FOUND_LINES; i++) { var line_color = win.ActiveSheet.Lines2d.Item(i).Style.LinearColor; var line_name = win.ActiveSheet.Lines2d.Item(i).Name; var index = win.ActiveSheet.Lines2d.Item(i).Index; var layer = win.ActiveSheet.Lines2d.Item(i).Layer.Trim().ToLower(); var angle = win.ActiveSheet.Lines2d.Item(i).Angle.ToString(); WRITE_FILE_LOG("LINE NAME: " + line_name + " - INDEX: " + index + " - LINE COLORE: " + line_color + " - LAYER: " + layer + " - ANGLE: " + angle, NOME_FILE_LOG, false); } } else { Console.WriteLine("The SolidEdge process is closed"); } } catch (Exception ex) { WRITE_FILE_LOG("ERROR: " + ex.ToString(), NOME_FILE_LOG, true); } }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.Documents documents = null; SolidEdgeFramework.SolidEdgeDocument document = null; SolidEdgeFramework.Window window = null; SolidEdgeDraft.SheetWindow sheetWindow = null; try { Console.WriteLine("Registering OleMessageFilter."); // Register with OLE to handle concurrency issues on the current thread. OleMessageFilter.Register(); Console.WriteLine("Connecting to Solid Edge."); // Connect to or start Solid Edge. application = SolidEdgeUtils.Connect(true); // Make sure user can see the GUI. application.Visible = true; // Bring Solid Edge to the foreground. application.Activate(); // Get a reference to the Documents collection. documents = application.Documents; // This check is necessary because application.ActiveDocument will throw an // exception if no documents are open... if (documents.Count > 0) { // Attempt to connect to ActiveDocument. document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; } // Make sure we have a document. if (document == null) { throw new System.Exception("No active document."); } // 3D windows are of type SolidEdgeFramework.Window. window = application.ActiveWindow as SolidEdgeFramework.Window; // 2D windows are of type SolidEdgeDraft.SheetWindow. sheetWindow = application.ActiveWindow as SolidEdgeDraft.SheetWindow; if (window != null) { SaveAsImage(window); } else if (sheetWindow != null) { SaveAsImage(sheetWindow); } } catch (System.Exception ex) { #if DEBUG System.Diagnostics.Debugger.Break(); #endif Console.WriteLine(ex.Message); } }