Esempio n. 1
0
        static void ConvertAllDrawingViewsTo2D(SolidEdgeDraft.Section section)
        {
            SolidEdgeDraft.SectionSheets sectionSheets = null;
            SolidEdgeDraft.Sheet         sheet         = null;
            SolidEdgeDraft.DrawingViews  drawingViews  = null;
            SolidEdgeDraft.DrawingView   drawingView   = null;

            sectionSheets = section.Sheets;

            for (int i = 1; i <= sectionSheets.Count; i++)
            {
                // Get a reference to the sheet.
                sheet = sectionSheets.Item(i);

                // Get a reference to the DrawingViews collection.
                drawingViews = sheet.DrawingViews;

                for (int j = 1; j < drawingViews.Count; j++)
                {
                    drawingView = drawingViews.Item(j);

                    Console.WriteLine("Dropping (convert to 2D) DrawingView '{0} - {1}'.  ", drawingView.Name, drawingView.Caption);

                    // DrawingView's of type igUserView cannot be converted.
                    if (drawingView.DrawingViewType != SolidEdgeDraft.DrawingViewTypeConstants.igUserView)
                    {
                        // Converts the current DrawingView to an igUserView type containing simple geometry
                        // and disassociates the drawing view from the source 3d Model.
                        drawingView.Drop();
                    }
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application           application    = null;
            SolidEdgeDraft.DraftDocument             draftDocument  = null;
            SolidEdgeDraft.Sheet                     sheet          = null;
            SolidEdgeFrameworkSupport.DrawingObjects drawingObjects = null;

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

                // Connect to or start Solid Edge.
                application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true);

                // Get a reference to the active draft document.
                draftDocument = application.GetActiveDocument <SolidEdgeDraft.DraftDocument>();

                // Get a reference to the active Sheet.
                sheet = draftDocument.ActiveSheet;

                // Get a reference to the drawing objects collection.
                drawingObjects = sheet.DrawingObjects;

                // Disable screen updating for performance.
                application.ScreenUpdating = false;

                // Loop until count is 0.
                while (drawingObjects.Count > 0)
                {
                    // Leverage dynamic keyword to allow invoking Delete() method.
                    dynamic drawingObject = drawingObjects.Item(1);

                    if (drawingObject is SolidEdgeDraft.TablePage)
                    {
                        // TablePage does not have a Delete() method but its parent does.
                        dynamic drawingObjectParent = drawingObject.Parent;
                        drawingObjectParent.Delete();
                    }
                    else
                    {
                        drawingObject.Delete();
                    }
                }

                // Turn screen updating back on.
                application.ScreenUpdating = true;

                // Fit the view.
                application.StartCommand(SolidEdgeConstants.DetailCommandConstants.DetailViewFit);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
        public static System.Drawing.Imaging.Metafile GetEnhancedMetafile(this SolidEdgeDraft.Sheet sheet)
        {
            try
            {
                // Copy the sheet as an EMF to the windows clipboard.
                sheet.CopyEMFToClipboard();

                if (OpenClipboard(IntPtr.Zero))
                {
                    if (IsClipboardFormatAvailable(CF_ENHMETAFILE))
                    {
                        // Get the handle to the EMF.
                        IntPtr henhmetafile = GetClipboardData(CF_ENHMETAFILE);

                        return(new System.Drawing.Imaging.Metafile(henhmetafile, true));
                    }
                    else
                    {
                        throw new System.Exception("CF_ENHMETAFILE is not available in clipboard.");
                    }
                }
                else
                {
                    throw new System.Exception("Error opening clipboard.");
                }
            }
            catch (System.Exception e)
            {
                throw e;
            }
            finally
            {
                CloseClipboard();
            }
        }
Esempio n. 4
0
        static void AddLineAndDimension(SolidEdgeDraft.DraftDocument draftDocument)
        {
            SolidEdgeDraft.Sheet sheet = null;
            SolidEdgeFrameworkSupport.Lines2d    lines2d    = null;
            SolidEdgeFrameworkSupport.Line2d     line2d     = null;
            SolidEdgeFrameworkSupport.Dimensions dimensions = null;
            SolidEdgeFrameworkSupport.Dimension  dimension  = null;
            SolidEdgeFrameworkSupport.DimStyle   dimStyle   = null;

            // Get a reference to the active sheet.
            sheet = draftDocument.ActiveSheet;

            // Get a reference to the Lines2d collection.
            lines2d = sheet.Lines2d;

            // Draw a new line.
            line2d = lines2d.AddBy2Points(
                x1: 0.2,
                y1: 0.2,
                x2: 0.3,
                y2: 0.2);

            // Get a reference to the Dimensions collection.
            dimensions = (SolidEdgeFrameworkSupport.Dimensions)sheet.Dimensions;

            // Add a dimension to the line.
            dimension = dimensions.AddLength(line2d);

            // Get a reference to the dimension style.
            // DimStyle has a ton of options...
            dimStyle = dimension.Style;
        }
Esempio n. 5
0
        static void AddAssemblyView(SolidEdgeDraft.DraftDocument draftDocument)
        {
            SolidEdgeDraft.Sheet        sheet        = null;
            SolidEdgeDraft.ModelLinks   modelLinks   = null;
            SolidEdgeDraft.ModelLink    modelLink    = null;
            SolidEdgeDraft.DrawingViews drawingViews = null;
            SolidEdgeDraft.DrawingView  drawingView  = null;
            DirectoryInfo trainingDirectory          = GetTrainingDirectory();
            string        fileName = Path.Combine(trainingDirectory.FullName, "Coffee Pot.asm");

            // Get a reference to the active sheet.
            sheet = draftDocument.ActiveSheet;

            // Get a reference to the ModelLinks collection.
            modelLinks = draftDocument.ModelLinks;
            //2holebar.par
            modelLink = modelLinks.Add(fileName);

            drawingViews = sheet.DrawingViews;

            drawingView = drawingViews.AddAssemblyView(
                From: modelLink,
                Orientation: SolidEdgeDraft.ViewOrientationConstants.igDimetricTopBackLeftView,
                Scale: 1.0,
                x: 0.4,
                y: 0.2,
                ViewType: SolidEdgeDraft.AssemblyDrawingViewTypeConstants.seAssemblyDesignedView);
        }
Esempio n. 6
0
        void DoOpenSave(SolidEdgeDraft.DraftDocument draftDocument, DraftSettings draftSettings)
        {
            SolidEdgeDraft.Sections      sections      = null;
            SolidEdgeDraft.Section       section       = null;
            SolidEdgeDraft.SectionSheets sectionSheets = null;
            SolidEdgeDraft.Sheet         sheet         = null;
            SolidEdgeDraft.DrawingViews  drawingViews  = null;
            SolidEdgeDraft.DrawingView   drawingView   = null;

            if (draftSettings.UpdateDrawingViews)
            {
                sections = draftDocument.Sections;
                section  = sections.WorkingSection;

                sectionSheets = section.Sheets;

                for (int i = 1; i <= sectionSheets.Count; i++)
                {
                    sheet        = sectionSheets.Item(i);
                    drawingViews = sheet.DrawingViews;

                    for (int j = 1; j <= drawingViews.Count; j++)
                    {
                        drawingView = drawingViews.Item(j);
                        drawingView.Update();
                    }
                }
            }
        }
Esempio n. 7
0
        static void UpdateAllViewsInWorkingSection(SolidEdgeDraft.Section section)
        {
            SolidEdgeDraft.SectionSheets sectionSheets = null;
            SolidEdgeDraft.Sheet         sheet         = null;
            SolidEdgeDraft.DrawingViews  drawingViews  = null;
            SolidEdgeDraft.DrawingView   drawingView   = null;

            sectionSheets = section.Sheets;

            for (int i = 1; i <= sectionSheets.Count; i++)
            {
                sheet = sectionSheets.Item(i);

                drawingViews = sheet.DrawingViews;

                for (int j = 1; j < drawingViews.Count; j++)
                {
                    drawingView = drawingViews.Item(j);

                    Console.WriteLine("Updating DrawingView '{0} - {1}'.", drawingView.Name, drawingView.Caption);

                    // Updates an out-of-date drawing view.
                    drawingView.Update();

                    // Updates the drawing view even if it is not out-of-date.
                    //drawingView.ForceUpdate();
                }
            }
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application    application   = null;
            SolidEdgeFramework.Documents      documents     = null;
            SolidEdgeDraft.DraftDocument      draftDocument = null;
            SolidEdgeDraft.Sheet              sheet         = null;
            SolidEdgeFrameworkSupport.Lines2d lines2d       = null;
            SolidEdgeFrameworkSupport.Line2d  line2d        = null;
            double lineLength = 3.0; // Inches

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

                // Connect to or start Solid Edge.
                application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true);

                // Get a reference to the documents collection.
                documents = application.Documents;

                // Create a new draft document.
                draftDocument = documents.AddDraftDocument();

                // Get a reference to the active sheet.
                sheet = draftDocument.ActiveSheet;

                // Get a reference to the Lines2d collection.
                lines2d = sheet.Lines2d;

                // Work with angle in degrees.
                for (int angle = 0; angle < 360; angle += 45)
                {
                    // {x1, y1, x2, y2}
                    double[] startPoint = { 0.2, 0.2 };
                    double[] endPoint   = { 0.3, 0.2 };

                    // Add the line.
                    line2d = lines2d.AddBy2Points(
                        x1: startPoint[0],
                        y1: startPoint[1],
                        x2: endPoint[0],
                        y2: endPoint[1]);

                    // Set the line length by converting inches to meters.
                    line2d.Length = lineLength * 0.0254;

                    // Set the angle by converting degrees to radians.
                    line2d.Angle = (Math.PI / 180) * angle;
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application       application   = null;
            SolidEdgeFramework.Documents         documents     = null;
            SolidEdgeDraft.DraftDocument         draftDocument = null;
            SolidEdgeDraft.Sheet                 sheet         = null;
            SolidEdgeFrameworkSupport.Circles2d  circles2d     = null;
            SolidEdgeFrameworkSupport.Circle2d   circle2d      = null;
            SolidEdgeFrameworkSupport.Dimensions dimensions    = null;

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

                // Connect to or start Solid Edge.
                application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true);

                // Get a reference to the documents collection.
                documents = application.Documents;

                // Create a new draft document.
                draftDocument = documents.AddDraftDocument();

                // Get a reference to the active sheet.
                sheet = draftDocument.ActiveSheet;

                // Get a reference to the Circles2d collection.
                circles2d = sheet.Circles2d;

                // Get a reference to the Dimensions collection.
                dimensions = (SolidEdgeFrameworkSupport.Dimensions)sheet.Dimensions;

                double x      = 0.1;
                double y      = 0.1;
                double radius = 0.01;

                for (int i = 0; i < 5; i++)
                {
                    // Add the circle.
                    circle2d = circles2d.AddByCenterRadius(x, y, radius);

                    // Dimension the circle.
                    dimensions.AddRadialDiameter(circle2d);

                    x      += 0.05;
                    y      += 0.05;
                    radius += 0.01;
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application   = null;
            SolidEdgeFramework.Documents   documents     = null;
            SolidEdgeDraft.DraftDocument   draftDocument = null;
            SolidEdgeDraft.ModelLinks      modelLinks    = null;
            SolidEdgeDraft.ModelLink       modelLink     = null;
            SolidEdgeDraft.Sheet           sheet         = null;
            SolidEdgeDraft.DrawingViews    drawingViews  = null;
            SolidEdgeDraft.DrawingView     drawingView   = null;
            string filename = null;

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

                // Connect to or start Solid Edge.
                application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true);

                // Get a reference to the documents collection.
                documents = application.Documents;

                // Create a new draft document.
                draftDocument = documents.AddDraftDocument();

                // Get a reference to the active sheet.
                sheet = draftDocument.ActiveSheet;

                // Build path to part file.
                filename = System.IO.Path.Combine(SolidEdgeCommunity.SolidEdgeUtils.GetTrainingFolderPath(), "Coffee Pot.asm");

                // Get a reference to the ModelLinks collection.
                modelLinks = draftDocument.ModelLinks;

                // Add a new model link.
                modelLink = modelLinks.Add(filename);

                // Get a reference to the DrawingViews collection.
                drawingViews = sheet.DrawingViews;

                // Add a new part drawing view.
                drawingView = drawingViews.AddAssemblyView(
                    From: modelLink,
                    Orientation: SolidEdgeDraft.ViewOrientationConstants.igDimetricTopBackLeftView,
                    Scale: 1.0,
                    x: 0.4,
                    y: 0.4,
                    ViewType: SolidEdgeDraft.AssemblyDrawingViewTypeConstants.seAssemblyDesignedView);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application       application   = null;
            SolidEdgeFramework.Documents         documents     = null;
            SolidEdgeDraft.DraftDocument         draftDocument = null;
            SolidEdgeDraft.Sheet                 sheet         = null;
            SolidEdgeFrameworkSupport.Lines2d    lines2d       = null;
            SolidEdgeFrameworkSupport.Line2d     line2d        = null;
            SolidEdgeFrameworkSupport.Dimensions dimensions    = null;
            SolidEdgeFrameworkSupport.Dimension  dimension     = null;
            SolidEdgeFrameworkSupport.DimStyle   dimStyle      = null;

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

                // Connect to or start Solid Edge.
                application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true);

                // Get a reference to the documents collection.
                documents = application.Documents;

                // Create a new draft document.
                draftDocument = documents.AddDraftDocument();

                // Get a reference to the active sheet.
                sheet = draftDocument.ActiveSheet;

                // Get a reference to the Lines2d collection.
                lines2d = sheet.Lines2d;

                // Draw a new line.
                line2d = lines2d.AddBy2Points(
                    x1: 0.2,
                    y1: 0.2,
                    x2: 0.3,
                    y2: 0.2);

                // Get a reference to the Dimensions collection.
                dimensions = (SolidEdgeFrameworkSupport.Dimensions)sheet.Dimensions;

                // Add a dimension to the line.
                dimension = dimensions.AddLength(line2d);

                // Get a reference to the dimension style.
                // DimStyle has a ton of options...
                dimStyle = dimension.Style;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Esempio n. 12
0
        static void AddPartViewAndDimension(SolidEdgeDraft.DraftDocument draftDocument)
        {
            SolidEdgeDraft.Sheet        sheet        = null;
            SolidEdgeDraft.ModelLinks   modelLinks   = null;
            SolidEdgeDraft.ModelLink    modelLink    = null;
            SolidEdgeDraft.DrawingViews drawingViews = null;
            SolidEdgeDraft.DrawingView  drawingView  = null;
            DirectoryInfo trainingDirectory          = GetTrainingDirectory();
            string        fileName = Path.Combine(trainingDirectory.FullName, "2holebar.par");

            SolidEdgeDraft.DVLines2d             dvLines2d  = null;
            SolidEdgeDraft.DVLine2d              dvLine2d   = null;
            SolidEdgeFrameworkSupport.Dimensions dimensions = null;
            SolidEdgeFrameworkSupport.Dimension  dimension  = null;
            SolidEdgeFrameworkSupport.DimStyle   dimStyle   = null;

            // Get a reference to the active sheet.
            sheet = draftDocument.ActiveSheet;

            // Get a reference to the ModelLinks collection.
            modelLinks = draftDocument.ModelLinks;

            // Add a new model link.
            modelLink = modelLinks.Add(fileName);

            // Get a reference to the DrawingViews collection.
            drawingViews = sheet.DrawingViews;

            // Add a new part drawing view.
            drawingView = drawingViews.AddPartView(
                From: modelLink,
                Orientation: SolidEdgeDraft.ViewOrientationConstants.igDimetricTopBackLeftView,
                Scale: 5.0,
                x: 0.4,
                y: 0.4,
                ViewType: SolidEdgeDraft.PartDrawingViewTypeConstants.sePartDesignedView);

            // Get a reference to the DVLines2d collection.
            dvLines2d = drawingView.DVLines2d;

            // Get the 1st drawing view 2D line.
            dvLine2d = dvLines2d.Item(1);

            // Get a reference to the Dimensions collection.
            dimensions = (SolidEdgeFrameworkSupport.Dimensions)sheet.Dimensions;

            // Add a dimension to the line.
            dimension = dimensions.AddLength(dvLine2d.Reference);

            // Few changes to make the dimensions look right.
            dimension.ProjectionLineDirection = true;
            dimension.TrackDistance           = 0.02;

            // Get a reference to the dimension style.
            // DimStyle has a ton of options...
            dimStyle = dimension.Style;
        }
Esempio n. 13
0
        static void AddItemsToSelectSet(SolidEdgeFramework.SolidEdgeDocument document)
        {
            SolidEdgeAssembly.AssemblyDocument assemblyDocument = null;
            SolidEdgeAssembly.AsmRefPlanes     asmRefPlanes     = null;
            SolidEdgeDraft.DraftDocument       draftDocument    = null;
            SolidEdgeDraft.Sheet             sheet              = null;
            SolidEdgeDraft.DrawingViews      drawingViews       = null;
            SolidEdgePart.PartDocument       partDocument       = null;
            SolidEdgePart.SheetMetalDocument sheetMetalDocument = null;
            SolidEdgePart.EdgebarFeatures    edgeBarFeatures    = null;

            switch (document.Type)
            {
            case SolidEdgeFramework.DocumentTypeConstants.igAssemblyDocument:
                assemblyDocument = (SolidEdgeAssembly.AssemblyDocument)document;
                asmRefPlanes     = assemblyDocument.AsmRefPlanes;

                for (int i = 1; i <= asmRefPlanes.Count; i++)
                {
                    assemblyDocument.SelectSet.Add(asmRefPlanes.Item(i));
                }
                break;

            case SolidEdgeFramework.DocumentTypeConstants.igDraftDocument:
                draftDocument = (SolidEdgeDraft.DraftDocument)document;
                sheet         = draftDocument.ActiveSheet;
                drawingViews  = sheet.DrawingViews;

                for (int i = 1; i <= drawingViews.Count; i++)
                {
                    draftDocument.SelectSet.Add(drawingViews.Item(i));
                }

                break;

            case SolidEdgeFramework.DocumentTypeConstants.igPartDocument:
                partDocument    = (SolidEdgePart.PartDocument)document;
                edgeBarFeatures = partDocument.DesignEdgebarFeatures;

                for (int i = 1; i <= edgeBarFeatures.Count; i++)
                {
                    partDocument.SelectSet.Add(edgeBarFeatures.Item(i));
                }

                break;

            case SolidEdgeFramework.DocumentTypeConstants.igSheetMetalDocument:
                sheetMetalDocument = (SolidEdgePart.SheetMetalDocument)document;
                edgeBarFeatures    = sheetMetalDocument.DesignEdgebarFeatures;

                for (int i = 1; i <= edgeBarFeatures.Count; i++)
                {
                    partDocument.SelectSet.Add(edgeBarFeatures.Item(i));
                }
                break;
            }
        }
Esempio n. 14
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application      application   = null;
            SolidEdgeFramework.Documents        documents     = null;
            SolidEdgeDraft.DraftDocument        draftDocument = null;
            SolidEdgeDraft.Sheet                sheet         = null;
            SolidEdgeFrameworkSupport.TextBoxes textBoxes     = null;
            SolidEdgeFrameworkSupport.TextBox   textBox       = null;
            SolidEdgeFrameworkSupport.Leaders   leaders       = null;
            SolidEdgeFrameworkSupport.Leader    leader        = null;
            SolidEdgeFrameworkSupport.DimStyle  dimStyle      = null;

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

                // Connect to or start Solid Edge.
                application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true);

                // Get a reference to the documents collection.
                documents = application.Documents;

                // Create a new draft document.
                draftDocument = documents.AddDraftDocument();

                // Get a reference to the active sheet.
                sheet = draftDocument.ActiveSheet;

                // Get a reference to the TextBoxes collection.
                textBoxes = (SolidEdgeFrameworkSupport.TextBoxes)sheet.TextBoxes;

                // Add a new text box.
                textBox                   = textBoxes.Add(0.25, 0.25, 0);
                textBox.TextScale         = 1;
                textBox.VerticalAlignment = SolidEdgeFrameworkSupport.TextVerticalAlignmentConstants.igTextHzAlignVCenter;
                textBox.Text              = "Leader";

                // Get a reference to the Leaders collection.
                leaders = (SolidEdgeFrameworkSupport.Leaders)sheet.Leaders;

                Console.WriteLine("Creating a new leader. ");

                // Add a new leader.
                leader   = leaders.Add(0.225, 0.225, 0, 0.25, 0.25, 0);
                dimStyle = leader.Style;
                dimStyle.FreeSpaceTerminatorType = SolidEdgeFrameworkSupport.DimTermTypeConstants.igDimStyleTermFilled;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Esempio n. 15
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application   = null;
            SolidEdgeDraft.DraftDocument   draftDocument = null;
            SolidEdgeDraft.Sheet           sheet         = null;

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

                // Connect to or start Solid Edge.
                application = SolidEdgeCommunity.SolidEdgeUtils.Connect(false);

                // Get a reference to the active draft document.
                draftDocument = application.GetActiveDocument <SolidEdgeDraft.DraftDocument>(false);

                if (draftDocument != null)
                {
                    // Get a reference to the active sheet.
                    sheet = draftDocument.ActiveSheet;

                    SaveFileDialog dialog = new SaveFileDialog();

                    // Set a default file name
                    dialog.FileName         = System.IO.Path.ChangeExtension(sheet.Name, ".emf");
                    dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                    dialog.Filter           = "Enhanced Metafile (*.emf)|*.emf";

                    if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        // Save the sheet as an EMF file.
                        sheet.SaveAsEnhancedMetafile(dialog.FileName);

                        Console.WriteLine("Created '{0}'", dialog.FileName);
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
        public static void SaveAsEnhancedMetafile(this SolidEdgeDraft.Sheet sheet, string filename)
        {
            try
            {
                // Copy the sheet as an EMF to the windows clipboard.
                sheet.CopyEMFToClipboard();

                if (OpenClipboard(IntPtr.Zero))
                {
                    if (IsClipboardFormatAvailable(CF_ENHMETAFILE))
                    {
                        // Get the handle to the EMF.
                        IntPtr hEMF = GetClipboardData(CF_ENHMETAFILE);

                        // Query the size of the EMF.
                        uint   len      = GetEnhMetaFileBits(hEMF, 0, null);
                        byte[] rawBytes = new byte[len];

                        // Get all of the bytes of the EMF.
                        GetEnhMetaFileBits(hEMF, len, rawBytes);

                        // Write all of the bytes to a file.
                        File.WriteAllBytes(filename, rawBytes);

                        // Delete the EMF handle.
                        DeleteEnhMetaFile(hEMF);
                    }
                    else
                    {
                        throw new System.Exception("CF_ENHMETAFILE is not available in clipboard.");
                    }
                }
                else
                {
                    throw new System.Exception("Error opening clipboard.");
                }
            }
            catch (System.Exception e)
            {
                throw e;
            }
            finally
            {
                CloseClipboard();
            }
        }
Esempio n. 17
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application            application     = null;
            SolidEdgeFramework.Documents              documents       = null;
            SolidEdgeDraft.DraftDocument              draftDocument   = null;
            SolidEdgeDraft.Sheet                      sheet           = null;
            SolidEdgeFrameworkSupport.Circles2d       circles2d       = null;
            SolidEdgeFrameworkSupport.Circle2d        circle2d        = null;
            SolidEdgeFrameworkSupport.GeometryStyle2d geometryStyle2d = null;

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

                // Connect to or start Solid Edge.
                application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true);

                // Get a reference to the Documents collection.
                documents = application.Documents;

                // Create a new draft document.
                draftDocument = documents.AddDraftDocument();

                // Get a reference to the active sheet.
                sheet = draftDocument.ActiveSheet;

                // Get a reference to the Circles2d collection.
                circles2d = sheet.Circles2d;

                // Add the circle.
                circle2d = circles2d.AddByCenterRadius(0.2, 0.2, 0.1);

                // Get a reference to the GeometryStyle2d to modify the style.
                geometryStyle2d = circle2d.Style;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Esempio n. 18
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application   = null;
            SolidEdgeDraft.DraftDocument   draftDocument = null;
            SolidEdgeDraft.Sheets          sheets        = null;
            SolidEdgeDraft.Sheet           sheet         = null;

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

                // Connect to or start Solid Edge.
                application = SolidEdgeCommunity.SolidEdgeUtils.Connect(false);

                // Get a reference to the active draft document.
                draftDocument = application.GetActiveDocument <SolidEdgeDraft.DraftDocument>(false);

                if (draftDocument != null)
                {
                    // Get a reference to the Sheets collection.
                    sheets = draftDocument.Sheets;

                    // Add a new sheet.
                    sheet = sheets.AddSheet();

                    // Make the new sheet the active sheet.
                    sheet.Activate();
                }
                else
                {
                    throw new System.Exception("No active documet.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Esempio n. 19
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application     application   = null;
            SolidEdgeFramework.Documents       documents     = null;
            SolidEdgeDraft.DraftDocument       draftDocument = null;
            SolidEdgeDraft.Sheet               sheet         = null;
            SolidEdgeFrameworkSupport.Balloons balloons      = null;
            SolidEdgeFrameworkSupport.Balloon  balloon       = null;
            SolidEdgeFrameworkSupport.DimStyle dimStype      = null;

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

                // Connect to or start Solid Edge.
                application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true);

                // Get a reference to the documents collection.
                documents = application.Documents;

                // Create a new draft document.
                draftDocument = documents.AddDraftDocument();

                // Get a reference to the active sheet.
                sheet = draftDocument.ActiveSheet;

                // Get a reference to the balloons collection.
                balloons = (SolidEdgeFrameworkSupport.Balloons)sheet.Balloons;

                balloon             = balloons.Add(0.05, 0.05, 0);
                balloon.TextScale   = 1.0;
                balloon.BalloonText = "B";
                balloon.Leader      = true;
                balloon.BreakLine   = true;
                balloon.BalloonSize = 3;
                balloon.SetTerminator(balloon, 0, 0, 0, false);
                balloon.BalloonType = SolidEdgeFrameworkSupport.DimBalloonTypeConstants.igDimBalloonCircle;

                dimStype = balloon.Style;
                dimStype.TerminatorType = SolidEdgeFrameworkSupport.DimTermTypeConstants.igDimStyleTermFilled;

                balloon             = balloons.Add(0.1, 0.1, 0);
                balloon.Callout     = 1;
                balloon.TextScale   = 1.0;
                balloon.BalloonText = "This is a callout";
                balloon.Leader      = true;
                balloon.BreakLine   = true;
                balloon.BalloonSize = 3;
                balloon.SetTerminator(balloon, 0, 0, 0, false);
                balloon.BalloonType = SolidEdgeFrameworkSupport.DimBalloonTypeConstants.igDimBalloonCircle;

                dimStype = balloon.Style;
                dimStype.TerminatorType = SolidEdgeFrameworkSupport.DimTermTypeConstants.igDimStyleTermFilled;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application      application   = null;
            SolidEdgeFramework.Documents        documents     = null;
            SolidEdgeDraft.DraftDocument        draftDocument = null;
            SolidEdgeDraft.Sheet                sheet         = null;
            SolidEdgeFrameworkSupport.TextBoxes textBoxes     = null;
            SolidEdgeFrameworkSupport.TextBox   textBox       = null;
            SolidEdgeFrameworkSupport.Leaders   leaders       = null;
            SolidEdgeFrameworkSupport.Leader    leader        = null;
            SolidEdgeFrameworkSupport.DimStyle  dimStyle      = 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;

                // Create a new draft document.
                draftDocument = (SolidEdgeDraft.DraftDocument)documents.Add("SolidEdge.DraftDocument");

                // Get a reference to the active sheet.
                sheet = draftDocument.ActiveSheet;

                // Get a reference to the TextBoxes collection.
                textBoxes = (SolidEdgeFrameworkSupport.TextBoxes)sheet.TextBoxes;

                Console.WriteLine("Creating a new textbox. ");

                // Add a new text box.
                textBox                   = textBoxes.Add(0.25, 0.25, 0);
                textBox.TextScale         = 1;
                textBox.VerticalAlignment = SolidEdgeFrameworkSupport.TextVerticalAlignmentConstants.igTextHzAlignVCenter;
                textBox.Text              = "Leader";

                // Get a reference to the Leaders collection.
                leaders = (SolidEdgeFrameworkSupport.Leaders)sheet.Leaders;

                Console.WriteLine("Creating a new leader. ");

                // Add a new leader.
                leader   = leaders.Add(0.225, 0.225, 0, 0.25, 0.25, 0);
                dimStyle = leader.Style;
                dimStyle.FreeSpaceTerminatorType = SolidEdgeFrameworkSupport.DimTermTypeConstants.igDimStyleTermFilled;
            }
            catch (System.Exception ex)
            {
#if DEBUG
                System.Diagnostics.Debugger.Break();
#endif
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 21
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application      application   = null;
            SolidEdgeFramework.Documents        documents     = null;
            SolidEdgeDraft.DraftDocument        draftDocument = null;
            SolidEdgeDraft.Sheet                sheet         = null;
            SolidEdgeFrameworkSupport.TextBoxes textBoxes     = null;
            SolidEdgeFrameworkSupport.TextBox   textBox       = null;

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

                // Connect to or start Solid Edge.
                application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true);

                // Get a reference to the documents collection.
                documents = application.Documents;

                // Create a new draft document.
                draftDocument = documents.AddDraftDocument();

                // Get a reference to the active sheet.
                sheet = draftDocument.ActiveSheet;

                // Get a reference to the TextBoxes collection.
                textBoxes = (SolidEdgeFrameworkSupport.TextBoxes)sheet.TextBoxes;

                // Disable screen updating for performance.
                application.ScreenUpdating = false;

                double x = 0;
                double y = 0;

                for (int i = 0; i < 10; i++)
                {
                    x += .05;
                    y  = 0;
                    for (int j = 0; j < 50; j++)
                    {
                        y += .01;
                        // Add a new text box.
                        textBox                   = textBoxes.Add(x, y, 0);
                        textBox.TextScale         = 1;
                        textBox.VerticalAlignment = SolidEdgeFrameworkSupport.TextVerticalAlignmentConstants.igTextHzAlignVCenter;
                        textBox.Text              = String.Format("[X: {0:0.###} Y: {1:0.###}]", x, y);
                    }
                }

                // Turn screen updating back on.
                application.ScreenUpdating = true;

                // Fit the view.
                application.StartCommand(SolidEdgeConstants.DetailCommandConstants.DetailViewFit);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Esempio n. 22
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application       application      = null;
            SolidEdgeFramework.SolidEdgeDocument document         = null;
            SolidEdgeFramework.SelectSet         selectSet        = null;
            SolidEdgeAssembly.AssemblyDocument   assemblyDocument = null;
            SolidEdgeAssembly.AsmRefPlanes       asmRefPlanes     = null;
            SolidEdgeDraft.DraftDocument         draftDocument    = null;
            SolidEdgeDraft.Sheet             sheet              = null;
            SolidEdgeDraft.DrawingViews      drawingViews       = null;
            SolidEdgePart.PartDocument       partDocument       = null;
            SolidEdgePart.SheetMetalDocument sheetMetalDocument = null;
            SolidEdgePart.EdgebarFeatures    edgeBarFeatures    = null;

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

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

                // Get a reference to the active selectset.
                selectSet = application.ActiveSelectSet;

                // Temporarily suspend selectset UI updates.
                selectSet.SuspendDisplay();

                // Clear the selectset.
                selectSet.RemoveAll();

                // Get a reference to the active document.
                document = application.GetActiveDocument <SolidEdgeFramework.SolidEdgeDocument>(false);

                if (document != null)
                {
                    // Determine document type.
                    switch (document.Type)
                    {
                    case SolidEdgeFramework.DocumentTypeConstants.igAssemblyDocument:
                        assemblyDocument = (SolidEdgeAssembly.AssemblyDocument)document;
                        asmRefPlanes     = assemblyDocument.AsmRefPlanes;

                        for (int i = 1; i <= asmRefPlanes.Count; i++)
                        {
                            selectSet.Add(asmRefPlanes.Item(i));
                        }

                        break;

                    case SolidEdgeFramework.DocumentTypeConstants.igDraftDocument:
                        draftDocument = (SolidEdgeDraft.DraftDocument)document;
                        sheet         = draftDocument.ActiveSheet;
                        drawingViews  = sheet.DrawingViews;

                        for (int i = 1; i <= drawingViews.Count; i++)
                        {
                            draftDocument.SelectSet.Add(drawingViews.Item(i));
                        }

                        break;

                    case SolidEdgeFramework.DocumentTypeConstants.igPartDocument:
                        partDocument    = (SolidEdgePart.PartDocument)document;
                        edgeBarFeatures = partDocument.DesignEdgebarFeatures;

                        for (int i = 1; i <= edgeBarFeatures.Count; i++)
                        {
                            partDocument.SelectSet.Add(edgeBarFeatures.Item(i));
                        }

                        break;

                    case SolidEdgeFramework.DocumentTypeConstants.igSheetMetalDocument:
                        sheetMetalDocument = (SolidEdgePart.SheetMetalDocument)document;
                        edgeBarFeatures    = sheetMetalDocument.DesignEdgebarFeatures;

                        for (int i = 1; i <= edgeBarFeatures.Count; i++)
                        {
                            partDocument.SelectSet.Add(edgeBarFeatures.Item(i));
                        }
                        break;
                    }
                }
                else
                {
                    throw new System.Exception("No active document");
                }

                // Re-enable selectset UI display.
                selectSet.ResumeDisplay();

                // Manually refresh the selectset UI display.
                selectSet.RefreshDisplay();
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Esempio n. 23
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application       application   = null;
            SolidEdgeFramework.Documents         documents     = null;
            SolidEdgeDraft.DraftDocument         draftDocument = null;
            SolidEdgeDraft.ModelLinks            modelLinks    = null;
            SolidEdgeDraft.ModelLink             modelLink     = null;
            SolidEdgeDraft.Sheet                 sheet         = null;
            SolidEdgeDraft.DrawingViews          drawingViews  = null;
            SolidEdgeDraft.DrawingView           drawingView   = null;
            SolidEdgeDraft.DVLines2d             dvLines2d     = null;
            SolidEdgeDraft.DVLine2d              dvLine2d      = null;
            SolidEdgeFrameworkSupport.Dimensions dimensions    = null;
            SolidEdgeFrameworkSupport.Dimension  dimension     = null;
            SolidEdgeFrameworkSupport.DimStyle   dimStyle      = null;
            string filename = null;

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

                // Connect to or start Solid Edge.
                application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true);

                // Get a reference to the documents collection.
                documents = application.Documents;

                // Create a new draft document.
                draftDocument = documents.AddDraftDocument();

                // Get a reference to the ModelLinks collection.
                modelLinks = draftDocument.ModelLinks;

                // Build path to part file.
                filename = System.IO.Path.Combine(SolidEdgeCommunity.SolidEdgeUtils.GetTrainingFolderPath(), "2holebar.par");

                // Add a new model link.
                modelLink = modelLinks.Add(filename);

                // Get a reference to the active sheet.
                sheet = draftDocument.ActiveSheet;

                // Get a reference to the DrawingViews collection.
                drawingViews = sheet.DrawingViews;

                // Add a new part drawing view.
                drawingView = drawingViews.AddPartView(
                    From: modelLink,
                    Orientation: SolidEdgeDraft.ViewOrientationConstants.igDimetricTopBackLeftView,
                    Scale: 5.0,
                    x: 0.4,
                    y: 0.4,
                    ViewType: SolidEdgeDraft.PartDrawingViewTypeConstants.sePartDesignedView);

                // Get a reference to the DVLines2d collection.
                dvLines2d = drawingView.DVLines2d;

                // Get the 1st drawing view 2D line.
                dvLine2d = dvLines2d.Item(1);

                // Get a reference to the Dimensions collection.
                dimensions = (SolidEdgeFrameworkSupport.Dimensions)sheet.Dimensions;

                // Add a dimension to the line.
                dimension = dimensions.AddLength(dvLine2d.Reference);

                // Few changes to make the dimensions look right.
                dimension.ProjectionLineDirection = true;
                dimension.TrackDistance           = 0.02;

                // Get a reference to the dimension style.
                // DimStyle has a ton of options...
                dimStyle = dimension.Style;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application     application   = null;
            SolidEdgeFramework.Documents       documents     = null;
            SolidEdgeDraft.DraftDocument       draftDocument = null;
            SolidEdgeDraft.Sheet               sheet         = null;
            SolidEdgeFrameworkSupport.Balloons balloons      = null;
            SolidEdgeFrameworkSupport.Balloon  balloon       = null;
            SolidEdgeFrameworkSupport.DimStyle dimStype      = 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;

                // Create a new draft document.
                draftDocument = (SolidEdgeDraft.DraftDocument)documents.Add("SolidEdge.DraftDocument");

                // Get a reference to the active sheet.
                sheet = draftDocument.ActiveSheet;

                // Get a reference to the balloons collection.
                balloons = (SolidEdgeFrameworkSupport.Balloons)sheet.Balloons;

                balloon             = balloons.Add(0.05, 0.05, 0);
                balloon.TextScale   = 1.0;
                balloon.BalloonText = "B";
                balloon.Leader      = true;
                balloon.BreakLine   = true;
                balloon.BalloonSize = 3;
                balloon.SetTerminator(balloon, 0, 0, 0, false);
                balloon.BalloonType = SolidEdgeFrameworkSupport.DimBalloonTypeConstants.igDimBalloonCircle;

                dimStype = balloon.Style;
                dimStype.TerminatorType = SolidEdgeFrameworkSupport.DimTermTypeConstants.igDimStyleTermFilled;

                balloon             = balloons.Add(0.1, 0.1, 0);
                balloon.Callout     = 1;
                balloon.TextScale   = 1.0;
                balloon.BalloonText = "This is a callout";
                balloon.Leader      = true;
                balloon.BreakLine   = true;
                balloon.BalloonSize = 3;
                balloon.SetTerminator(balloon, 0, 0, 0, false);
                balloon.BalloonType = SolidEdgeFrameworkSupport.DimBalloonTypeConstants.igDimBalloonCircle;

                dimStype = balloon.Style;
                dimStype.TerminatorType = SolidEdgeFrameworkSupport.DimTermTypeConstants.igDimStyleTermFilled;
            }
            catch (System.Exception ex)
            {
#if DEBUG
                System.Diagnostics.Debugger.Break();
#endif
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 25
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application        application   = null;
            SolidEdgeFramework.Documents          documents     = null;
            SolidEdgeDraft.DraftDocument          draftDocument = null;
            SolidEdgeDraft.Sheet                  sheet         = null;
            SolidEdgeFrameworkSupport.Lines2d     lines2d       = null;
            SolidEdgeFrameworkSupport.Relations2d relations2d   = null;
            SolidEdgeFramework.SelectSet          selectSet     = null;

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

                // Connect to or start Solid Edge.
                application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true);

                // Get a reference to the documents collection.
                documents = application.Documents;

                // Create a new part document.
                draftDocument = documents.AddDraftDocument();

                // Always a good idea to give SE a chance to breathe.
                application.DoIdle();

                // Get a reference to the active Sheet.
                sheet = draftDocument.ActiveSheet;

                // Get a reference to the Relations2d collection.
                relations2d = sheet.Relations2d;

                // Get a reference to the Lines2d collection.
                lines2d = sheet.Lines2d;

                int    sides = 8;
                double angle = 360 / sides;
                angle = (angle * Math.PI) / 180;

                double radius     = .05;
                double lineLength = 2 * radius * (Math.Tan(angle) / 2);

                // x1, y1, x2, y2
                double[] points = { 0.0, 0.0, 0.0, 0.0 };

                double x = 0.2;
                double y = 0.2;

                points[2] = -((Math.Cos(angle / 2) * radius) - x);
                points[3] = -((lineLength / 2) - y);

                // Draw each line.
                for (int i = 0; i < sides; i++)
                {
                    points[0] = points[2];
                    points[1] = points[3];
                    points[2] = points[0] + (Math.Sin(angle * i) * lineLength);
                    points[3] = points[1] + (Math.Cos(angle * i) * lineLength);

                    lines2d.AddBy2Points(points[0], points[1], points[2], points[3]);
                }

                // Create endpoint relationships.
                for (int i = 1; i <= lines2d.Count; i++)
                {
                    if (i == lines2d.Count)
                    {
                        relations2d.AddKeypoint(lines2d.Item(i), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(1), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart);
                    }
                    else
                    {
                        relations2d.AddKeypoint(lines2d.Item(i), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(i + 1), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart);
                        relations2d.AddEqual(lines2d.Item(i), lines2d.Item(i + 1));
                    }
                }

                // Get a reference to the ActiveSelectSet.
                selectSet = application.ActiveSelectSet;

                // Empty ActiveSelectSet.
                selectSet.RemoveAll();

                // Add all lines to ActiveSelectSet.
                foreach (var line2d in lines2d.OfType <SolidEdgeFrameworkSupport.Line2d>())
                {
                    selectSet.Add(line2d);
                }

                // Switch to ISO view.
                application.StartCommand(SolidEdgeConstants.PartCommandConstants.PartViewISOView);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }