/// <summary>
        /// Adds an overlay to the specified window.
        /// </summary>
        public TOverlay Add <TOverlay>(SolidEdgeFramework.Window window) where TOverlay : ViewOverlay
        {
            TOverlay overlay = Activator.CreateInstance <TOverlay>();

            Add(window, overlay);
            return(overlay);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application = null;
            SolidEdgeFramework.Window      window      = null;

            try
            {
                // Register with OLE to handle concurrency issues on the current thread.
                SolidEdgeCommunity.OleMessageFilter.Register();

                // Connect to Solid Edge.
                application = SolidEdgeCommunity.SolidEdgeUtils.Start();

                // 3D windows are of type SolidEdgeFramework.Window.
                window = application.ActiveWindow as SolidEdgeFramework.Window;

                if (window != null)
                {
                    WindowHelper.SaveAsImageUsingBitBlt(window);
                }
                else
                {
                    throw new System.Exception("No active 3D window.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
 /// <summary>
 /// Adds an overlay to the specified window.
 /// </summary>
 public void Add(SolidEdgeFramework.Window window, ViewOverlay overlay)
 {
     if (window == null)
     {
         throw new ArgumentNullException("window");
     }
     Add(window.View, overlay);
 }
 /// <summary>
 /// Determines if the specified window has an overlay.
 /// </summary>
 public bool HasOverlay(SolidEdgeFramework.Window window)
 {
     if (window == null)
     {
         throw new ArgumentNullException("window");
     }
     return(HasOverlay(window.View));
 }
        /// <summary>
        /// Removes all overlays for the specified window.
        /// </summary>
        public void RemoveAll(SolidEdgeFramework.Window window)
        {
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            RemoveAll(window.View);
        }
Ejemplo n.º 6
0
        public static void SaveAsImageUsingBitBlt(SolidEdgeFramework.Window window)
        {
            System.Windows.Forms.SaveFileDialog dialog = new System.Windows.Forms.SaveFileDialog();
            dialog.FileName    = System.IO.Path.ChangeExtension(window.Caption, ".bmp");
            dialog.Filter      = "BMP (.bmp)|*.bmp|GIF (.gif)|*.gif|JPEG (.jpeg)|*.jpeg|PNG (.png)|*.png|TIFF (.tiff)|*.tiff|WMF Image (.wmf)|*.wmf";
            dialog.FilterIndex = 1;

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                IntPtr handle = new IntPtr(window.DrawHwnd);

                // Capture the window to an Image object.
                using (System.Drawing.Image image = Capture(handle))
                {
                    ImageFormat imageFormat = default(ImageFormat);

                    // Determine the selected image format.
                    // The index is 1-based.
                    switch (dialog.FilterIndex)
                    {
                    case 1:
                        imageFormat = ImageFormat.Bmp;
                        break;

                    case 2:
                        imageFormat = ImageFormat.Gif;
                        break;

                    case 3:
                        imageFormat = ImageFormat.Jpeg;
                        break;

                    case 4:
                        imageFormat = ImageFormat.Png;
                        break;

                    case 5:
                        imageFormat = ImageFormat.Tiff;
                        break;

                    case 6:
                        imageFormat = ImageFormat.Wmf;
                        break;
                    }

                    Console.WriteLine("Saving {0}.", dialog.FileName);

                    image.Save(dialog.FileName, imageFormat);
                }
            }
        }
Ejemplo n.º 7
0
    public static void SaveAsImage(SolidEdgeFramework.Window window)
    {
        string[] extensions = { ".jpg", ".bmp", ".tif" };

        SolidEdgeFramework.View view = null;
        Guid   guid   = Guid.NewGuid();
        string folder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

        if (window == null)
        {
            throw new ArgumentNullException("window");
        }

        // Get a reference to the 3D view.
        view = window.View;

        // Save each extension.
        foreach (string extension in extensions)
        {
            // File saved to desktop.
            string filename = Path.ChangeExtension(guid.ToString(), extension);
            filename = Path.Combine(folder, filename);

            double resolution = 1.0;  // DPI - Larger values have better quality but also lead to larger file.
            int    colorDepth = 24;
            int    width      = window.UsableWidth;
            int    height     = window.UsableHeight;

            // You can specify .bmp (Windows Bitmap), .tif (TIFF), or .jpg (JPEG).
            view.SaveAsImage(
                Filename: filename,
                Width: width,
                Height: height,
                AltViewStyle: null,
                Resolution: resolution,
                ColorDepth: colorDepth,
                ImageQuality: SolidEdgeFramework.SeImageQualityType.seImageQualityHigh,
                Invert: false);

            Console.WriteLine("Saved '{0}'.", filename);
        }
    }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application = null;
            SolidEdgeFramework.Window      window      = null;

            try
            {
                // Register with OLE to handle concurrency issues on the current thread.
                SolidEdgeCommunity.OleMessageFilter.Register();

                // Connect to Solid Edge.
                application = SolidEdgeCommunity.SolidEdgeUtils.Start();

                // 3D windows are of type SolidEdgeFramework.Window.
                window = application.ActiveWindow as SolidEdgeFramework.Window;

                if (window != null)
                {
                    string[] extensions = { ".jpg", ".bmp", ".tif" };

                    SolidEdgeFramework.View view = null;
                    Guid   guid   = Guid.NewGuid();
                    string folder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

                    if (window == null)
                    {
                        throw new ArgumentNullException("window");
                    }

                    // Get a reference to the 3D view.
                    view = window.View;

                    // Save each extension.
                    foreach (string extension in extensions)
                    {
                        // File saved to desktop.
                        string filename = System.IO.Path.ChangeExtension(guid.ToString(), extension);
                        filename = System.IO.Path.Combine(folder, filename);

                        double resolution = 1.0;  // DPI - Larger values have better quality but also lead to larger file.
                        int    colorDepth = 24;
                        int    width      = window.UsableWidth;
                        int    height     = window.UsableHeight;

                        // You can specify .bmp (Windows Bitmap), .tif (TIFF), or .jpg (JPEG).
                        view.SaveAsImage(
                            Filename: filename,
                            Width: width,
                            Height: height,
                            AltViewStyle: null,
                            Resolution: resolution,
                            ColorDepth: colorDepth,
                            ImageQuality: SolidEdgeFramework.SeImageQualityType.seImageQualityHigh,
                            Invert: false);

                        Console.WriteLine("Saved '{0}'.", filename);
                    }
                }
                else
                {
                    throw new System.Exception("No active 3D window.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
 /// <summary>
 /// Returns an IntPtr representing the window handle.
 /// </summary>
 public static IntPtr GetHandle(this SolidEdgeFramework.Window window)
 {
     return(new IntPtr(window.hWnd));
 }
Ejemplo n.º 10
0
        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);
            }
        }