Beispiel #1
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application   application        = null;
            SolidEdgePart.SheetMetalDocument sheetMetalDocument = 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 sheetmetal document.
                sheetMetalDocument = application.GetActiveDocument <SolidEdgePart.SheetMetalDocument>();

                if (sheetMetalDocument != null)
                {
                    sheetMetalDocument.Recompute();
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Beispiel #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();
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application   application = null;
            SolidEdgePart.SheetMetalDocument document    = 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 document.
                document = application.GetActiveDocument <SolidEdgePart.SheetMetalDocument>(false);

                // Make sure we have a document.
                if (document != null)
                {
                    VariablesHelper.ReportVariables(document);
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application     application      = null;
            SolidEdgeAssembly.AssemblyDocument assemblyDocument = null;
            SolidEdgeAssembly.Occurrences      occurrences      = 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 the active document.
                assemblyDocument = application.GetActiveDocument <SolidEdgeAssembly.AssemblyDocument>(false);

                if (assemblyDocument != null)
                {
                    // Get a reference to the Occurrences collection.
                    occurrences = assemblyDocument.Occurrences;

                    foreach (var occurrence in occurrences.OfType <SolidEdgeAssembly.Occurrence>())
                    {
                        Array MinRangePoint = Array.CreateInstance(typeof(double), 0);
                        Array MaxRangePoint = Array.CreateInstance(typeof(double), 0);
                        occurrence.GetRangeBox(ref MinRangePoint, ref MaxRangePoint);

                        // Convert from System.Array to double[].  double[] is easier to work with.
                        double[] a1 = MinRangePoint.OfType <double>().ToArray();
                        double[] a2 = MaxRangePoint.OfType <double>().ToArray();

                        // Report the occurrence matrix.
                        Console.WriteLine("{0} range box:", occurrence.Name);
                        Console.WriteLine("|MinRangePoint: {0}, {1}, {2}|",
                                          a1[0],
                                          a1[1],
                                          a1[2]);
                        Console.WriteLine("|MaxRangePoint: {0}, {1}, {2}|",
                                          a2[0],
                                          a2[1],
                                          a2[2]);
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application = null;

            try
            {
                OleMessageFilter.Register();
                application = SolidEdgeUtils.Connect();
                var assemblyDocument = application.GetActiveDocument <SolidEdgeAssembly.AssemblyDocument>(false);

                // Optional settings you may tweak for performance improvements. Results may vary.
                application.DelayCompute   = true;
                application.DisplayAlerts  = false;
                application.Interactive    = false;
                application.ScreenUpdating = false;

                if (assemblyDocument != null)
                {
                    var rootItem = new DocumentItem();
                    rootItem.FileName = assemblyDocument.FullName;

                    // Begin the recurisve extraction process.
                    PopulateDocumentItems(assemblyDocument.Occurrences, rootItem);

                    // Write each DocumentItem to console.
                    foreach (var documentItem in rootItem.AllDocumentItems)
                    {
                        Console.WriteLine(documentItem.FileName);
                    }

                    // Demonstration of how to save the BOM to various formats.

                    // Convert the document items to JSON.
                    string json = Newtonsoft.Json.JsonConvert.SerializeObject(rootItem, Newtonsoft.Json.Formatting.Indented);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (application != null)
                {
                    application.DelayCompute   = false;
                    application.DisplayAlerts  = true;
                    application.Interactive    = true;
                    application.ScreenUpdating = true;
                }

                OleMessageFilter.Unregister();
            }
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application  = null;
            SolidEdgePart.PartDocument     partDocument = null;
            SolidEdgePart.Models           models       = null;
            SolidEdgePart.Model            model        = null;
            SolidEdgeGeometry.Body         body         = 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);

                // Bring Solid Edge to the foreground.
                application.Activate();

                // Get a reference to the active part document.
                partDocument = application.GetActiveDocument <SolidEdgePart.PartDocument>(false);

                if (partDocument != null)
                {
                    models = partDocument.Models;

                    if (models.Count == 0)
                    {
                        throw new System.Exception("No geometry defined.");
                    }

                    model = models.Item(1);
                    body  = (SolidEdgeGeometry.Body)model.Body;

                    Array MinRangePoint = Array.CreateInstance(typeof(double), 0);
                    Array MaxRangePoint = Array.CreateInstance(typeof(double), 0);

                    body.GetRange(ref MinRangePoint, ref MaxRangePoint);
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application     application    = null;
            SolidEdgeAssembly.AssemblyDocument document       = null;
            SolidEdgeAssembly.Configurations   configurations = null;
            SolidEdgeAssembly.Configuration    configuration  = 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 assembly document.
                document = application.GetActiveDocument <SolidEdgeAssembly.AssemblyDocument>(false);

                if (document != null)
                {
                    // Get a reference to the Configurations collection.
                    configurations = document.Configurations;

                    // Configuration name has to be unique so for demonstration
                    // purposes, use a random number.
                    Random random     = new Random();
                    string configName = String.Format("Configuration {0}", random.Next());

                    configuration = configurations.Item(1);

                    object configList = new string[] { configuration.Name };

                    object missing = Missing.Value;

                    // NOTE: Not sure why but this is causing Solid Edge ST6 to crash.
                    // Add the new configuration.
                    configuration = configurations.AddDerivedConfig(1, 0, 0, ref configList, ref missing, ref missing, configName);
                }
                else
                {
                    throw new System.Exception("No active document");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application   application        = 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(true, true);

                // Bring Solid Edge to the foreground.
                application.Activate();

                // Get a reference to the active sheetmetal document.
                sheetMetalDocument = application.GetActiveDocument <SolidEdgePart.SheetMetalDocument>(false);

                if (sheetMetalDocument != null)
                {
                    // Get a reference to the DesignEdgebarFeatures collection.
                    edgebarFeatures = sheetMetalDocument.DesignEdgebarFeatures;

                    // Interate through the features.
                    for (int i = 1; i <= edgebarFeatures.Count; i++)
                    {
                        // Get the EdgebarFeature at current index.
                        var edgebarFeature = edgebarFeatures.Item(i);

                        // Get the managed type.
                        var type = SolidEdgeCommunity.Runtime.InteropServices.ComObject.GetType(edgebarFeature);

                        Console.WriteLine("Item({0}) is of type '{1}'", i, type);
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Beispiel #9
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();
            }
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application   = null;
            SolidEdgeDraft.DraftDocument   draftDocument = null;
            SolidEdgeDraft.PartsLists      partsLists    = null;
            SolidEdgeDraft.PartsList       partsList     = 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 PartsLists collection.
                    partsLists = draftDocument.PartsLists;

                    if (partsLists.Count > 0)
                    {
                        // Get a reference to the 1st parts list.
                        partsList = partsLists.Item(1);

                        // Copy parts list to clipboard.
                        partsList.CopyToClipboard();
                    }
                    else
                    {
                        throw new System.Exception("No parts lists.");
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application     application      = null;
            SolidEdgeAssembly.AssemblyDocument assemblyDocument = null;
            SolidEdgeAssembly.Configurations   configurations   = null;
            SolidEdgeAssembly.Configuration    configuration    = 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 refrence to the active assembly document.
                assemblyDocument = application.GetActiveDocument <SolidEdgeAssembly.AssemblyDocument>(false);

                if (assemblyDocument != null)
                {
                    // Get a reference tot he Configurations collection.
                    configurations = assemblyDocument.Configurations;

                    // Configuration name has to be unique so for demonstration
                    // purposes, use a random number.
                    Random random     = new Random();
                    string configName = String.Format("Configuration {0}", random.Next());

                    // Add the new configuration.
                    configuration = configurations.Add(configName);

                    // Make the new configuration the active configuration.
                    configuration.Apply();
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application   application        = null;
            SolidEdgePart.SheetMetalDocument sheetMetalDocument = 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);

                // Bring Solid Edge to the foreground.
                application.Activate();

                // Get a reference to the active sheetmetal document.
                sheetMetalDocument = application.GetActiveDocument <SolidEdgePart.SheetMetalDocument>(false);

                if (sheetMetalDocument != null)
                {
                    switch (sheetMetalDocument.ModelingMode)
                    {
                    case SolidEdgePart.ModelingModeConstants.seModelingModeOrdered:
                        sheetMetalDocument.ModelingMode = SolidEdgePart.ModelingModeConstants.seModelingModeSynchronous;
                        Console.WriteLine("Modeling mode changed to synchronous.");
                        break;

                    case SolidEdgePart.ModelingModeConstants.seModelingModeSynchronous:
                        sheetMetalDocument.ModelingMode = SolidEdgePart.ModelingModeConstants.seModelingModeOrdered;
                        Console.WriteLine("Modeling mode changed to ordered (traditional).");
                        break;
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application = 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 assembly document.
                var document = application.GetActiveDocument <SolidEdgeAssembly.AssemblyDocument>(false);

                if (document != null)
                {
                    // Get a reference to the occurrences collection.
                    var occurrences = document.Occurrences;

                    foreach (var occurrence in occurrences.OfType <SolidEdgeAssembly.Occurrence>())
                    {
                        Console.WriteLine("Processing occurrence {0}.", occurrence.Name);

                        var relations3d       = (SolidEdgeAssembly.Relations3d)occurrence.Relations3d;
                        var groundRelations3d = relations3d.OfType <SolidEdgeAssembly.GroundRelation3d>();

                        foreach (var groundRelation3d in groundRelations3d)
                        {
                            Console.WriteLine("Found and deleted ground relationship at index {0}.", groundRelation3d.Index);
                            groundRelation3d.Delete();
                        }
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application   = null;
            SolidEdgeDraft.DraftDocument   draftDocument = null;
            SolidEdgeDraft.Sheets          sheets        = 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 document.
                draftDocument = application.GetActiveDocument <SolidEdgeDraft.DraftDocument>(false);

                // Make sure we have a document.
                if (draftDocument != null)
                {
                    // Get a reference to the sheets collection.
                    sheets = draftDocument.Sheets;

                    foreach (var sheet in sheets.OfType <SolidEdgeDraft.Sheet>())
                    {
                        Console.WriteLine("Name: {0}", sheet.Name);
                        Console.WriteLine("Index: {0}", sheet.Index);
                        Console.WriteLine("Number: {0}", sheet.Number);
                        Console.WriteLine("SectionType: {0}", sheet.SectionType);
                        Console.WriteLine();
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application   application        = null;
            SolidEdgePart.SheetMetalDocument sheetMetalDocument = null;
            SolidEdgePart.Models             models             = null;
            SolidEdgePart.Model model = 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);

                // Bring Solid Edge to the foreground.
                application.Activate();

                // Get a reference to the active document.
                sheetMetalDocument = application.GetActiveDocument <SolidEdgePart.SheetMetalDocument>(false);

                if (sheetMetalDocument != null)
                {
                    models = sheetMetalDocument.Models;

                    for (int i = 1; i <= models.Count; i++)
                    {
                        model = models.Item(i);
                        model.HealAndOptimizeBody(true, true);
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Beispiel #16
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();
            }
        }
Beispiel #17
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application  = null;
            SolidEdgePart.PartDocument     partDocument = null;
            SolidEdgePart.Models           models       = 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);

                // Bring Solid Edge to the foreground.
                application.Activate();

                // Get a reference to the active part document.
                partDocument = application.GetActiveDocument <SolidEdgePart.PartDocument>(false);

                if (partDocument != null)
                {
                    models = partDocument.Models;

                    foreach (var model in models.OfType <SolidEdgePart.Model>())
                    {
                        model.Recompute();
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Beispiel #18
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application     application      = null;
            SolidEdgeAssembly.AssemblyDocument assemblyDocument = null;
            SolidEdgeAssembly.Configurations   configurations   = 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 active assembly document.
                assemblyDocument = application.GetActiveDocument <SolidEdgeAssembly.AssemblyDocument>(false);

                if (assemblyDocument != null)
                {
                    // Get a reference tot he Configurations collection.
                    configurations = assemblyDocument.Configurations;

                    // Iterate through all of the configurations.
                    foreach (SolidEdgeAssembly.Configuration configuration in configurations.OfType <SolidEdgeAssembly.Configuration>())
                    {
                        Console.WriteLine("Configuration Name: '{0}' | Configuration Type: {1}.", configuration.Name, configuration.ConfigurationType);
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Beispiel #19
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application   = null;
            SolidEdgeDraft.DraftDocument   draftDocument = null;
            SolidEdgeDraft.Sections        sections      = 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>(false);

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

                    // Convert property text on all sheets in background section.
                    ConvertSection(sections.BackgroundSection);

                    // Convert property text on all sheets in working section.
                    ConvertSection(sections.WorkingSection);
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Beispiel #20
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application = 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 assembly document.
                var document = application.GetActiveDocument();

                if (document != null)
                {
                    var propertySets = (SolidEdgeFramework.PropertySets)document.Properties;

                    AddCustomProperties(propertySets);
                    ReportCustomProperties(propertySets);
                    DeleteCustomProperties(propertySets);
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
            Console.Read();
        }
Beispiel #21
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application     application = null;
            SolidEdgeAssembly.AssemblyDocument document    = 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 document.
                document = application.GetActiveDocument <SolidEdgeAssembly.AssemblyDocument>(false);

                // Make sure we have a document.
                if (document != null)
                {
                    SolidEdgeFramework.Variables        variables    = null;
                    SolidEdgeFramework.VariableList     variableList = null;
                    SolidEdgeFramework.variable         variable     = null;
                    SolidEdgeFrameworkSupport.Dimension dimension    = null;

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

                    // Get a reference to the Variables collection.
                    variables = (SolidEdgeFramework.Variables)document.Variables;

                    // Get a reference to the variablelist.
                    variableList = (SolidEdgeFramework.VariableList)variables.Query(
                        pFindCriterium: "*",
                        NamedBy: SolidEdgeConstants.VariableNameBy.seVariableNameByBoth,
                        VarType: SolidEdgeConstants.VariableVarType.SeVariableVarTypeBoth);

                    // Process variables.
                    foreach (var variableListItem in variableList.OfType <object>())
                    {
                        // Not used in this sample but a good example of how to get the runtime type.
                        var variableListItemType = SolidEdgeCommunity.Runtime.InteropServices.ComObject.GetType(variableListItem);

                        // Use helper class to get the object type.
                        var objectType = SolidEdgeCommunity.Runtime.InteropServices.ComObject.GetPropertyValue <SolidEdgeFramework.ObjectType>(variableListItem, "Type", (SolidEdgeFramework.ObjectType) 0);

                        // Process the specific variable item type.
                        switch (objectType)
                        {
                        case SolidEdgeFramework.ObjectType.igDimension:
                            // Get a reference to the dimension.
                            dimension = (SolidEdgeFrameworkSupport.Dimension)variableListItem;
                            Console.WriteLine("Dimension: '{0}' = '{1}' ({2})", dimension.DisplayName, dimension.Value, objectType);
                            break;

                        case SolidEdgeFramework.ObjectType.igVariable:
                            variable = (SolidEdgeFramework.variable)variableListItem;
                            Console.WriteLine("Variable: '{0}' = '{1}' ({2})", variable.DisplayName, variable.Value, objectType);
                            break;

                        default:
                            // Other SolidEdgeConstants.ObjectType's may exist.
                            break;
                        }
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
 /// <summary>
 /// Returns the currently active document.
 /// </summary>
 /// <typeparam name="T">The type to return.</typeparam>
 /// /// <remarks>An exception will be thrown if there is no active document or if the cast fails.</remarks>
 public static T GetActiveDocument <T>(this SolidEdgeFramework.Application application) where T : class
 {
     return(application.GetActiveDocument <T>(true));
 }
 /// <summary>
 /// Returns the currently active document.
 /// </summary>
 /// <remarks>An exception will be thrown if there is no active document.</remarks>
 public static SolidEdgeFramework.SolidEdgeDocument GetActiveDocument(this SolidEdgeFramework.Application application)
 {
     return(application.GetActiveDocument(true));
 }
Beispiel #24
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application   application        = null;
            SolidEdgePart.SheetMetalDocument sheetMetalDocument = null;
            SolidEdgePart.Models             models             = null;
            SolidEdgePart.Model model = null;
            double density            = 0;
            double accuracy           = 0;
            double volume             = 0;
            double area                      = 0;
            double mass                      = 0;
            Array  cetnerOfGravity           = Array.CreateInstance(typeof(double), 3);
            Array  centerOfVolumne           = Array.CreateInstance(typeof(double), 3);
            Array  globalMomentsOfInteria    = Array.CreateInstance(typeof(double), 6); // Ixx, Iyy, Izz, Ixy, Ixz and Iyz
            Array  principalMomentsOfInteria = Array.CreateInstance(typeof(double), 3); // Ixx, Iyy and Izz
            Array  principalAxes             = Array.CreateInstance(typeof(double), 9); // 3 axes x 3 coords
            Array  radiiOfGyration           = Array.CreateInstance(typeof(double), 9); // 3 axes x 3 coords
            double relativeAccuracyAchieved  = 0;
            int    status                    = 0;

            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 document.
                sheetMetalDocument = application.GetActiveDocument <SolidEdgePart.SheetMetalDocument>(false);

                if (sheetMetalDocument != null)
                {
                    density  = 1;
                    accuracy = 0.05;

                    // Get a reference to the Models collection.
                    models = sheetMetalDocument.Models;

                    // Get a reference to the Model.
                    model = models.Item(1);

                    // Compute the physical properties.
                    model.ComputePhysicalProperties(
                        Density: density,
                        Accuracy: accuracy,
                        Volume: out volume,
                        Area: out area,
                        Mass: out mass,
                        CenterOfGravity: ref cetnerOfGravity,
                        CenterOfVolume: ref centerOfVolumne,
                        GlobalMomentsOfInteria: ref globalMomentsOfInteria,
                        PrincipalMomentsOfInteria: ref principalMomentsOfInteria,
                        PrincipalAxes: ref principalAxes,
                        RadiiOfGyration: ref radiiOfGyration,
                        RelativeAccuracyAchieved: out relativeAccuracyAchieved,
                        Status: out status);

                    Console.WriteLine("ComputePhysicalProperties() results:");

                    // Write results to screen.

                    Console.WriteLine("Density: {0}", density);
                    Console.WriteLine("Accuracy: {0}", accuracy);
                    Console.WriteLine("Volume: {0}", volume);
                    Console.WriteLine("Area: {0}", area);
                    Console.WriteLine("Mass: {0}", mass);

                    // Convert from System.Array to double[].  double[] is easier to work with.
                    double[] m = cetnerOfGravity.OfType <double>().ToArray();

                    Console.WriteLine("CenterOfGravity:");
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]);

                    m = centerOfVolumne.OfType <double>().ToArray();

                    Console.WriteLine("CenterOfVolume:");
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]);

                    m = globalMomentsOfInteria.OfType <double>().ToArray();

                    Console.WriteLine("GlobalMomentsOfInteria:");
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]);
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[3], m[4], m[5]);

                    m = principalMomentsOfInteria.OfType <double>().ToArray();

                    Console.WriteLine("PrincipalMomentsOfInteria:");
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]);

                    m = principalAxes.OfType <double>().ToArray();

                    Console.WriteLine("PrincipalAxes:");
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]);
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[3], m[4], m[5]);
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[6], m[7], m[8]);

                    m = radiiOfGyration.OfType <double>().ToArray();

                    Console.WriteLine("RadiiOfGyration:");
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]);
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[3], m[4], m[5]);
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[6], m[7], m[8]);

                    Console.WriteLine("RelativeAccuracyAchieved: {0}", relativeAccuracyAchieved);
                    Console.WriteLine("Status: {0}", status);
                    Console.WriteLine();

                    // Show physical properties window.
                    application.StartCommand(SolidEdgeConstants.SheetMetalCommandConstants.SheetMetalToolsPhysicalProperties);
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Beispiel #25
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application = 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 assembly document.
                var document = application.GetActiveDocument <SolidEdgeAssembly.AssemblyDocument>(false);

                if (document != null)
                {
                    var propertySets = (SolidEdgeFramework.PropertySets)document.Properties;

                    foreach (var properties in propertySets.OfType <SolidEdgeFramework.Properties>())
                    {
                        Console.WriteLine("PropertSet '{0}'.", properties.Name);

                        foreach (var property in properties.OfType <SolidEdgeFramework.Property>())
                        {
                            System.Runtime.InteropServices.VarEnum nativePropertyType = System.Runtime.InteropServices.VarEnum.VT_EMPTY;
                            Type runtimePropertyType = null;

                            object value = null;

                            nativePropertyType = (System.Runtime.InteropServices.VarEnum)property.Type;

                            // Accessing Value property may throw an exception...
                            try
                            {
                                value = property.get_Value();
                            }
                            catch (System.Exception ex)
                            {
                                value = ex.Message;
                            }

                            if (value != null)
                            {
                                runtimePropertyType = value.GetType();
                            }

                            Console.WriteLine("\t{0} = '{1}' ({2} | {3}).", property.Name, value, nativePropertyType, runtimePropertyType);
                        }

                        Console.WriteLine();
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Beispiel #26
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application                     application      = null;
            SolidEdgeAssembly.AssemblyDocument                 assemblyDocument = null;
            SolidEdgeAssembly.Occurrences                      occurrences      = null;
            SolidEdgeAssembly.InterferenceStatusConstants      interferenceStatus;
            SolidEdgeConstants.InterferenceComparisonConstants compare    = SolidEdgeConstants.InterferenceComparisonConstants.seInterferenceComparisonSet1vsAllOther;
            SolidEdgeConstants.InterferenceReportConstants     reportType = SolidEdgeConstants.InterferenceReportConstants.seInterferenceReportPartNames;

            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 assembly document.
                assemblyDocument = application.GetActiveDocument <SolidEdgeAssembly.AssemblyDocument>(false);

                if (assemblyDocument != null)
                {
                    // Get a reference to the Occurrences collection.
                    occurrences = assemblyDocument.Occurrences;

                    foreach (var occurrence in occurrences.OfType <SolidEdgeAssembly.Occurrence>())
                    {
                        Array  set1                   = Array.CreateInstance(occurrence.GetType(), 1);
                        object numInterferences       = 0;
                        object retSet1                = Array.CreateInstance(typeof(SolidEdgeAssembly.Occurrence), 0);
                        object retSet2                = Array.CreateInstance(typeof(SolidEdgeAssembly.Occurrence), 0);
                        object confirmedInterference  = null;
                        object interferenceOccurrence = null;

                        set1.SetValue(occurrence, 0);

                        // Check interference.
                        assemblyDocument.CheckInterference(
                            NumElementsSet1: set1.Length,
                            Set1: ref set1,
                            Status: out interferenceStatus,
                            ComparisonMethod: compare,
                            NumElementsSet2: 0,
                            Set2: Missing.Value,
                            AddInterferenceAsOccurrence: false,
                            ReportFilename: Missing.Value,
                            ReportType: reportType,
                            NumInterferences: out numInterferences,
                            InterferingPartsSet1: ref retSet1,
                            InterferingPartsOtherSet: ref retSet2,
                            ConfirmedInterference: ref confirmedInterference,
                            InterferenceOccurrence: out interferenceOccurrence,
                            IgnoreThreadInterferences: Missing.Value
                            );

                        // Process status.
                        switch (interferenceStatus)
                        {
                        case SolidEdgeAssembly.InterferenceStatusConstants.seInterferenceStatusNoInterference:
                            break;

                        case SolidEdgeAssembly.InterferenceStatusConstants.seInterferenceStatusConfirmedAndProbableInterference:
                        case SolidEdgeAssembly.InterferenceStatusConstants.seInterferenceStatusConfirmedInterference:
                        case SolidEdgeAssembly.InterferenceStatusConstants.seInterferenceStatusIncompleteAnalysis:
                        case SolidEdgeAssembly.InterferenceStatusConstants.seInterferenceStatusProbableInterference:
                            if (retSet2 != null)
                            {
                                for (int j = 0; j < (int)numInterferences; j++)
                                {
                                    object obj1 = ((Array)retSet1).GetValue(j);
                                    object obj2 = ((Array)retSet2).GetValue(j);

                                    // Use helper class to get the object type.
                                    var objectType1 = SolidEdgeCommunity.Runtime.InteropServices.ComObject.GetPropertyValue <SolidEdgeFramework.ObjectType>(obj1, "Type", (SolidEdgeFramework.ObjectType) 0);
                                    var objectType2 = SolidEdgeCommunity.Runtime.InteropServices.ComObject.GetPropertyValue <SolidEdgeFramework.ObjectType>(obj2, "Type", (SolidEdgeFramework.ObjectType) 0);

                                    SolidEdgeFramework.Reference reference1  = null;
                                    SolidEdgeFramework.Reference reference2  = null;
                                    SolidEdgeAssembly.Occurrence occurrence1 = null;
                                    SolidEdgeAssembly.Occurrence occurrence2 = null;

                                    switch (objectType1)
                                    {
                                    case SolidEdgeFramework.ObjectType.igReference:
                                        reference1 = (SolidEdgeFramework.Reference)obj1;
                                        break;

                                    case SolidEdgeFramework.ObjectType.igPart:
                                    case SolidEdgeFramework.ObjectType.igOccurrence:
                                        occurrence1 = (SolidEdgeAssembly.Occurrence)obj1;
                                        break;
                                    }

                                    switch (objectType2)
                                    {
                                    case SolidEdgeFramework.ObjectType.igReference:
                                        reference2 = (SolidEdgeFramework.Reference)obj2;
                                        break;

                                    case SolidEdgeFramework.ObjectType.igPart:
                                    case SolidEdgeFramework.ObjectType.igOccurrence:
                                        occurrence2 = (SolidEdgeAssembly.Occurrence)obj2;
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Beispiel #27
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application   application        = null;
            SolidEdgePart.SheetMetalDocument sheetMetalDocument = null;
            SolidEdgePart.Models             models             = null;
            SolidEdgePart.Model    model    = null;
            SolidEdgePart.Features features = null;
            bool bIgnoreWarnings            = true;
            bool bExtendSelection           = true;

            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);

                // Bring Solid Edge to the foreground.
                application.Activate();

                // Get a reference to the active part document.
                sheetMetalDocument = application.GetActiveDocument <SolidEdgePart.SheetMetalDocument>(false);

                if (sheetMetalDocument != null)
                {
                    // Get a reference to the Models collection.
                    models = sheetMetalDocument.Models;

                    // Get a reference to the 1st model.
                    model = models.Item(1);

                    // Get a reference to the Features collection.
                    features = model.Features;

                    // Iterate through the features.
                    foreach (var feature in features.OfType <object>())
                    {
                        var featureEdgeBarName  = SolidEdgeCommunity.Runtime.InteropServices.ComObject.GetPropertyValue <string>(feature, "EdgeBarName", "Unknown");
                        var featureModelingMode = SolidEdgeCommunity.Runtime.InteropServices.ComObject.GetPropertyValue <SolidEdgePart.ModelingModeConstants>(feature, "ModelingModeType", (SolidEdgePart.ModelingModeConstants) 0);

                        // Check to see if the feature is ordered.
                        // NOTE: I've found that not all features have a ModelingModeType property. SolidEdgePart.FaceRotate is one of them.
                        // This is a bit of a problem because I see no way to know if the FaceRotate is Ordered or Synchronous...
                        if (featureModelingMode == SolidEdgePart.ModelingModeConstants.seModelingModeOrdered)
                        {
                            int   NumberOfFeaturesCausingError   = 0;
                            Array ErrorMessageArray              = Array.CreateInstance(typeof(string), 0);
                            int   NumberOfFeaturesCausingWarning = 0;
                            Array WarningMessageArray            = Array.CreateInstance(typeof(string), 0);

                            // Move the ordered feature to synchronous.
                            sheetMetalDocument.MoveToSynchronous(
                                pFeatureUnk: feature,
                                bIgnoreWarnings: bIgnoreWarnings,
                                bExtendSelection: bExtendSelection,
                                NumberOfFeaturesCausingError: out NumberOfFeaturesCausingError,
                                ErrorMessageArray: out ErrorMessageArray,
                                NumberOfFeaturesCausingWarning: out NumberOfFeaturesCausingWarning,
                                WarningMessageArray: out WarningMessageArray);

                            Console.WriteLine("Feature '{0}' results:", featureEdgeBarName);

                            // Process error messages.
                            for (int i = 0; i < ErrorMessageArray.Length; i++)
                            {
                                Console.WriteLine("Error: '{0}'.", ErrorMessageArray.GetValue(i));
                            }

                            // Process warning messages.
                            for (int i = 0; i < WarningMessageArray.Length; i++)
                            {
                                Console.WriteLine("Warning: '{0}'.", WarningMessageArray.GetValue(i));
                            }

                            // If you get any error or warning messages, it's probably a good idea to stop.
                            if ((ErrorMessageArray.Length > 0) || (WarningMessageArray.Length > 0))
                            {
                                break;
                            }
                            else
                            {
                                Console.WriteLine("Success");
                            }
                        }
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Beispiel #28
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application   = null;
            SolidEdgeDraft.DraftDocument   draftDocument = null;
            SolidEdgeDraft.Sections        sections      = null;
            SolidEdgeDraft.Section         section       = null;
            SolidEdgeDraft.SectionSheets   sectionSheets = null;
            SolidEdgeDraft.DrawingViews    drawingViews  = 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);

                draftDocument = application.GetActiveDocument <SolidEdgeDraft.DraftDocument>(false);

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

                    // Get a reference to the WorkingSection.
                    section = sections.WorkingSection;

                    // Get a reference to the Sheets collection.
                    sectionSheets = section.Sheets;

                    foreach (var sheet in sectionSheets.OfType <SolidEdgeDraft.Sheet>())
                    {
                        Console.WriteLine("Processing sheet '{0}'.", sheet.Name);

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

                        foreach (var drawingView in drawingViews.OfType <SolidEdgeDraft.DrawingView>())
                        {
                            // Updates an out-of-date drawing view.
                            drawingView.Update();

                            // Note: You can use ForceUpdate() even if it is not out-of-date.

                            Console.WriteLine("Updated drawing view '{0}'.", drawingView.Name);
                        }
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Beispiel #29
0
        static void Main()
        {
            SolidEdgeFramework.Application application = null;


            try
            {
                OleMessageFilter.Register();

                // Connect to a running instance of Solid Edge.
                application = SolidEdgeUtils.Connect();

                // Connect to the active assembly document.
                var assemblyDocument = application.GetActiveDocument <SolidEdgeAssembly.AssemblyDocument>(false);

                // Optional settings you may tweak for performance improvements. Results may vary.
                application.DelayCompute   = true;
                application.DisplayAlerts  = false;
                application.Interactive    = false;
                application.ScreenUpdating = false;

                Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();

                if (xlApp == null)
                {
                    Console.WriteLine("EXCEL could not be started. Check that your office installation and project references are correct.");
                    return;
                }
                xlApp.Visible = true;

                // Open workbook
                Workbook wb = xlApp.Workbooks.Open("Y:\\Common\\Engineering\\001_Vraagbaak\\gijs\\BOM.xlsx");

                // Open worksheet
                Worksheet ws = (Worksheet)wb.Worksheets[2];

                if (ws == null)
                {
                    Console.WriteLine("Worksheet could not be created. Check that your office installation and project references are correct.");
                }

                int      i          = 2;
                string   sRow       = "";
                object[] oBomValues = new Object[1];

                sRow = i.ToString();

                oBomValues[0] = "Keywords";
                Range aRange = ws.get_Range("C" + sRow);
                aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, oBomValues);

                oBomValues[0] = "Document Number";
                aRange        = ws.get_Range("D" + sRow);
                aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, oBomValues);

                oBomValues[0] = "Title";
                aRange        = ws.get_Range("E" + sRow);
                aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, oBomValues);

                oBomValues[0] = "Quantity";
                aRange        = ws.get_Range("F" + sRow);
                aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, oBomValues);

                i++;

                if (assemblyDocument != null)
                {
                    var rootBomItem = new BomItem();
                    rootBomItem.FileName = assemblyDocument.FullName;

                    // Write Name of rootBomItem to excel
                    oBomValues[0] = assemblyDocument.DisplayName;
                    aRange        = ws.get_Range("A1");
                    aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, oBomValues);

                    // Begin the recurisve extraction process.
                    PopulateBom(0, assemblyDocument, rootBomItem);

                    // Write each BomItem to console.
                    foreach (var bomItem in rootBomItem.AllChildren)
                    {
                        Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", bomItem.Level, bomItem.DocumentNumber, bomItem.Revision, bomItem.Title, bomItem.Quantity);
                        sRow = i.ToString();

                        oBomValues[0] = bomItem.Level;
                        aRange        = ws.get_Range("C" + sRow);
                        aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, oBomValues);

                        oBomValues[0] = bomItem.DocumentNumber;
                        aRange        = ws.get_Range("D" + sRow);
                        aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, oBomValues);

                        oBomValues[0] = bomItem.Title;
                        aRange        = ws.get_Range("E" + sRow);
                        aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, oBomValues);

                        oBomValues[0] = bomItem.Quantity;
                        aRange        = ws.get_Range("F" + sRow);
                        aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, oBomValues);

                        i++;
                    }

                    // Demonstration of how to save the BOM to various formats.

                    // Define the Json serializer settings.
                    var jsonSettings = new JsonSerializerSettings
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    };

                    // Convert the BOM to JSON.
                    string json = Newtonsoft.Json.JsonConvert.SerializeObject(rootBomItem, Newtonsoft.Json.Formatting.Indented, jsonSettings);

                    wb.RefreshAll();
                    wb.SaveAs(assemblyDocument.Path + "\\_BOM.xlsx");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (application != null)
                {
                    application.DelayCompute   = false;
                    application.DisplayAlerts  = true;
                    application.Interactive    = true;
                    application.ScreenUpdating = true;
                }

                OleMessageFilter.Unregister();
            }
        }
Beispiel #30
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application     application = null;
            SolidEdgeAssembly.AssemblyDocument document    = null;

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

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

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

                if (document != null)
                {
                    // Note: Some of the parameters are obvious by their name but we need to work on getting better descriptions for some.
                    var NewName                         = String.Empty;
                    var Include_PreciseGeom             = 0;
                    var Prod_Structure_Option           = 1;
                    var Export_PMI                      = 0;
                    var Export_CoordinateSystem         = 0;
                    var Export_3DBodies                 = 0;
                    var NumberofLODs                    = 1;
                    var JTFileUnit                      = 0;
                    var Write_Which_Files               = 1;
                    var Use_Simplified_TopAsm           = 0;
                    var Use_Simplified_SubAsm           = 0;
                    var Use_Simplified_Part             = 0;
                    var EnableDefaultOutputPath         = 0;
                    var IncludeSEProperties             = 0;
                    var Export_VisiblePartsOnly         = 0;
                    var Export_VisibleConstructionsOnly = 0;
                    var RemoveUnsafeCharacters          = 0;
                    var ExportSEPartFileAsSingleJTFile  = 0;

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

                    switch (document.Type)
                    {
                    case SolidEdgeFramework.DocumentTypeConstants.igAssemblyDocument:
                    case SolidEdgeFramework.DocumentTypeConstants.igPartDocument:
                    case SolidEdgeFramework.DocumentTypeConstants.igSheetMetalDocument:
                    case SolidEdgeFramework.DocumentTypeConstants.igWeldmentAssemblyDocument:
                    case SolidEdgeFramework.DocumentTypeConstants.igWeldmentDocument:
                        NewName = System.IO.Path.ChangeExtension(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), document.Name), ".jt");
                        document.SaveAsJT(
                            NewName,
                            Include_PreciseGeom,
                            Prod_Structure_Option,
                            Export_PMI,
                            Export_CoordinateSystem,
                            Export_3DBodies,
                            NumberofLODs,
                            JTFileUnit,
                            Write_Which_Files,
                            Use_Simplified_TopAsm,
                            Use_Simplified_SubAsm,
                            Use_Simplified_Part,
                            EnableDefaultOutputPath,
                            IncludeSEProperties,
                            Export_VisiblePartsOnly,
                            Export_VisibleConstructionsOnly,
                            RemoveUnsafeCharacters,
                            ExportSEPartFileAsSingleJTFile);
                        break;

                    default:
                        throw new System.Exception(String.Format("'{0}' cannot be converted to JT.", document.Type));
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }