Ejemplo n.º 1
0
 public void Dispose()
 {
     OleMessageFilter.Unregister();
     if (_application != null)
     {
         Marshal.ReleaseComObject(_application);
     }
 }
Ejemplo n.º 2
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         OleMessageFilter.Unregister();
     }
     catch
     {
         GlobalExceptionHandler.HandleException();
     }
 }
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Loads the Solid Edge Instance
 /// </summary>
 /// <param name="OpenNewAppInstance"></param>
 internal void LoadSolidEdgeApplication(bool OpenNewAppInstance)
 {
     try
     {
         CustomEvents.OnProgressChanged("Launching Solid Edge");
         OleMessageFilter.Register();
         _application = SolidEdgeUtils.Connect(OpenNewAppInstance, true);
     }
     catch
     {
     }
 }
        private void frmCacheManager_Load(object sender, EventArgs e)
        {
            this.comboBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckKeyPress);
            this.KeyPress           += new System.Windows.Forms.KeyPressEventHandler(CheckKeyPress);

            try
            {
                OleMessageFilter.Register();
                app = SolidEdgeUtils.Connect(false, true);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }

            bool tcMode = false;

            if (app != null)
            {
                app.SolidEdgeTCE.GetTeamCenterMode(out tcMode);

                if (tcMode == false)
                {
                    return;
                }

                string keyname = app.RegistryPath + @"\General";
                key = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.CurrentUser, RegistryView.Registry64);
                key = key.OpenSubKey(keyname, true);
                string seecPath  = key.GetValue(@"SEEC cache").ToString();
                string currentWS = key.GetValue(@"SEEC_Active_Project").ToString();
                prefixWorkspaces = currentWS.Substring(0, currentWS.Length - (currentWS.Split('\\').Last().Length + 1)) + @"\";

                workspaceFolder = Directory.GetParent(seecPath + @"\" + currentWS).FullName;

                string[] workspaces = Directory.GetDirectories(workspaceFolder)
                                      .OrderByDescending(Directory.GetLastWriteTime)
                                      .Select(Path.GetFileName)
                                      .ToArray();

                comboBox1.Items.AddRange(workspaces);
                comboBox1.Text = currentWS.Split('\\').Last();
            }
        }
Ejemplo n.º 6
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            try
            {
                // Register with OLE to handle concurrency issues on the current thread.
                OleMessageFilter.Register();

                PreloadTypeLibraries();

                ComTypeManager.Instance.ComTypeLibrarySelected += Instance_ComTypeLibrarySelected;
                ComTypeManager.Instance.ComTypeInfoSelected    += Instance_ComTypeInfoSelected;
            }
            catch
            {
                GlobalExceptionHandler.HandleException();
            }

            SetupToolStripManager();
        }
Ejemplo n.º 7
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     OleMessageFilter.Unregister();
 }
Ejemplo n.º 8
0
 private void MainForm_Load(object sender, EventArgs e)
 {
     OleMessageFilter.Register();
 }
Ejemplo n.º 9
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();
            }
        }
 private void frmCacheManager_FormClosing(object sender, FormClosingEventArgs e)
 {
     OleMessageFilter.Unregister();
     app = null;
 }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            string            folder         = ConfigurationManager.AppSettings.Get("saveFolder");
            Application       application    = null;
            SolidEdgeDocument activeDocument = null;

            try
            {
                // See "Handling 'Application is Busy' and 'Call was Rejected By Callee' errors" topic.
                OleMessageFilter.Register();

                // Attempt to connect to a running instance of Solid Edge.
                application = (Application)Marshal.GetActiveObject("SolidEdge.Application");
                //get active document
                activeDocument = (SolidEdgeDocument)application.ActiveDocument;

                //execute different behaviour for different documet type
                switch (GetDocumentType(application.ActiveDocument)) //grab document type form active document
                {
                case DocumentTypeConstants.igDraftDocument:
                    Console.WriteLine("Grabbed draft document");
                    SaveAsExtension(activeDocument, folder, "dxf");                        //save the active document on the specified folder as dxf
                    SaveAsExtension(activeDocument, folder, "pdf");                        //save the active document on the specified folder as pdf
                    DraftDocument activeDraft = (DraftDocument)application.ActiveDocument; //cast the active document as a draftDocument to access the model link

                    foreach (ModelLink modelLink in activeDraft.ModelLinks)                //loop for all model links found in the model link
                    {
                        if (GetDocumentType((SolidEdgeDocument)modelLink.ModelDocument) == DocumentTypeConstants.igPartDocument)
                        {
                            SaveAsExtension((SolidEdgeDocument)modelLink.ModelDocument, folder, "stp");     // cast the individual modelLlink.ModelDocument as a model document and save it
                            break;
                        }

                        if (GetDocumentType((SolidEdgeDocument)modelLink.ModelDocument) == DocumentTypeConstants.igAssemblyDocument)
                        {
                            SolidEdgeDocument asmDocument = (SolidEdgeDocument)modelLink.ModelDocument; // cast the individual modelLlink.ModelDocument as a model document

                            if (asmDocument.Name.Contains("MPF"))                                       // quick string check if contains the letters MPF
                            {
                                Console.WriteLine("Found MPF named document: " + asmDocument.Name);
                                SaveAsExtension((SolidEdgeDocument)modelLink.ModelDocument, folder, "stp");     //save the model link document on the specified folder as stp
                                break;
                            }
                            else
                            {
                                Console.WriteLine("Found an non MPF asembly document: " + asmDocument.Name);     // found nothing here
                            }
                        }
                    }
                    break;

                case DocumentTypeConstants.igPartDocument:
                    Console.WriteLine("Grabbed part document");
                    SaveAsExtension(activeDocument, folder, "stp");     // save the part document in the specified folder as stp
                    break;

                default:
                    Console.WriteLine("No valid document");     // found nothing here
                    break;
                }
                Console.WriteLine("Todo ha salido a pedir de Milhouse");
                Console.ReadKey();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
            finally
            {
                OleMessageFilter.Unregister(); // unlink application after completion
            }
        }
        static void Main(string[] args)
        {
            //string fileToOpen = @"C:\Users\wttcpchang\Downloads\3D CAD\03-22811_A~A.ASM";
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent      = true;
            settings.IndentChars = "    ";
            settings.Encoding    = Encoding.UTF8;
            XmlWriter writerXml = XmlWriter.Create("PhyProperty.xml", settings);

            SolidEdgeFramework.Application     application        = null;
            SolidEdgeFramework.Documents       seDocuments        = null;
            SolidEdgeAssembly.AssemblyDocument seAssemblyDocument = null;
            SolidEdgePart.PartDocument         sePartDocument     = null;

            SolidEdgePart.Models models = null; // collection of Methods
            SolidEdgePart.Model  model  = null; // 3d model

            //The variables for use
            int    status;
            double volume, area, mass, density, accuracy, relativeAccuracyAchieved;

            // The matrix data
            Array centerOfGravity           = Array.CreateInstance(typeof(double), 3);
            Array centerOfVolume            = Array.CreateInstance(typeof(double), 3);
            Array globalMomentsOfInteria    = Array.CreateInstance(typeof(double), 6); //Ixx, Iyy, Izz, Ixy, Iyz, Ixz
            Array principalMomentsOfInteria = Array.CreateInstance(typeof(double), 3); //Ixx, Iyy, Izz
            Array principalAxes             = Array.CreateInstance(typeof(double), 9);
            Array radiiOfGyration           = Array.CreateInstance(typeof(double), 9);

            FileStream   ostrm;
            StreamWriter writer;
            TextWriter   oldOut = Console.Out;

            try
            {
                ostrm  = new FileStream("./SEinfo.txt", FileMode.Create, FileAccess.Write);
                writer = new StreamWriter(ostrm);
                Console.SetOut(writer);
                //OleMessageFilter.Register();
                //application = SolidEdgeUtils.Connect();
                //var assemblyDocument = application.GetActiveDocument<SolidEdgeAssembly.AssemblyDocument>(false);
                Console.WriteLine(args[0]);
                //Write the root element
                writerXml.WriteStartElement("RootAssemblyFile");
                writerXml.WriteAttributeString("File", args[0]);

                ///////// open Solid Edge file in SE
                application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true);
                seDocuments = application.Documents;
                //seAssemblyDocument = (AssemblyDocument)seDocuments.Open(fileToOpen);
                seAssemblyDocument = (AssemblyDocument)seDocuments.Open(args[0].ToString());

                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)
                    {
                        String file = documentItem.FileName.ToString();

                        if (file.Substring(file.Length - 3) == "PAR" || file.Substring(file.Length - 3) == "par" || file.Substring(file.Length - 3) == "Par")
                        {
                            sePartDocument = (PartDocument)seDocuments.Open(documentItem.FileName.ToString());            // SE open the tree PAR
                            var seActivePartDocument = application.GetActiveDocument <SolidEdgePart.PartDocument>(false); // connect to the active PAR
                        }
                        Console.WriteLine("==============================================================");
                        Console.WriteLine("connect to active file (within Document tree):");
                        //Console.WriteLine(seActivePartDocument.FullName);
                        Console.WriteLine(documentItem.FileName);

                        //if (application.ActiveDocumentType == DocumentTypeConstants.igPartDocument)
                        if (file.Substring(file.Length - 3) == "PAR" || file.Substring(file.Length - 3) == "par" || file.Substring(file.Length - 3) == "Par")
                        {
                            writerXml.WriteStartElement("DocumentTree_Part");
                            writerXml.WriteAttributeString("File", documentItem.FileName);

                            Console.WriteLine("-------- ## Physical Properties: ## --------");
                            // get the collection of models
                            models = sePartDocument.Models;

                            // get the model
                            model = models.Item(1);

                            // get the Volume, Area, Mass,....
                            model.GetPhysicalProperties(
                                Status: out status,
                                Density: out density,
                                Accuracy: out accuracy,
                                Volume: out volume,
                                Area: out area,
                                Mass: out mass,
                                CenterOfGravity: ref centerOfGravity,
                                CenterOfVolume: ref centerOfVolume,
                                GlobalMomentsOfInteria: ref globalMomentsOfInteria,
                                PrincipalMomentsOfInteria: ref principalMomentsOfInteria,
                                PrincipalAxes: ref radiiOfGyration,
                                RadiiOfGyration: ref radiiOfGyration,
                                RelativeAccuracyAchieved: out relativeAccuracyAchieved
                                );


                            // do anything what you want....
                            Console.WriteLine("\tVolume, \"" + volume + "\"");
                            Console.WriteLine("\tArea, \"" + area + "\"");
                            Console.WriteLine("\tMass, \"" + mass + "\"");
                            //Console.ReadKey();
                            //writerXml.WriteStartElement("Volume");
                            writerXml.WriteElementString("Volume", volume.ToString());
                            writerXml.WriteElementString("Area", area.ToString());
                            writerXml.WriteElementString("Mass", mass.ToString());
                            // Write results to screen.

                            Console.WriteLine("\tDensity, \"{0}\"", density);
                            Console.WriteLine("\tAccuracy, \"{0}\"", accuracy);

                            writerXml.WriteElementString("Density", density.ToString());
                            writerXml.WriteElementString("Accuracy", accuracy.ToString());


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

                            Console.WriteLine("CenterOfGravity:");
                            Console.WriteLine("\tCenterOfGravity_x, \"{0}\"", m[0]);
                            Console.WriteLine("\tCenterOfGravity_y, \"{0}\"", m[1]);
                            Console.WriteLine("\tCenterOfGravity_z, \"{0}\"", m[2]);
                            writerXml.WriteElementString("CenterOfGravity_x", m[0].ToString());
                            writerXml.WriteElementString("CenterOfGravity_y", m[1].ToString());
                            writerXml.WriteElementString("CenterOfGravity_z", m[2].ToString());

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

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

                            Console.WriteLine("CenterOfVolume:");
                            Console.WriteLine("\tCenterOfVolume_x, \"{0}\"", m[0]);
                            Console.WriteLine("\tCenterOfVolume_y, \"{0}\"", m[1]);
                            Console.WriteLine("\tCenterOfVolume_z, \"{0}\"", m[2]);
                            writerXml.WriteElementString("CenterOfVolume_x", m[0].ToString());
                            writerXml.WriteElementString("CenterOfVolume_y", m[1].ToString());
                            writerXml.WriteElementString("CenterOfVolume_z", m[2].ToString());
                            //Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]);

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

                            Console.WriteLine("GlobalMomentsOfInteria:");
                            Console.WriteLine("\tGlobalMomentsOfInteria_xx, \"{0}\"", m[0]);
                            Console.WriteLine("\tGlobalMomentsOfInteria_yy, \"{0}\"", m[1]);
                            Console.WriteLine("\tGlobalMomentsOfInteria_zz, \"{0}\"", m[2]);
                            Console.WriteLine("\tGlobalMomentsOfInteria_xy, \"{0}\"", m[3]);
                            Console.WriteLine("\tGlobalMomentsOfInteria_xz, \"{0}\"", m[4]);
                            Console.WriteLine("\tGlobalMomentsOfInteria_yz, \"{0}\"", m[5]);
                            writerXml.WriteElementString("GlobalMomentsOfInteria_xx", m[0].ToString());
                            writerXml.WriteElementString("GlobalMomentsOfInteria_yy", m[1].ToString());
                            writerXml.WriteElementString("GlobalMomentsOfInteria_zz", m[2].ToString());
                            writerXml.WriteElementString("GlobalMomentsOfInteria_xy", m[3].ToString());
                            writerXml.WriteElementString("GlobalMomentsOfInteria_xz", m[4].ToString());
                            writerXml.WriteElementString("GlobalMomentsOfInteria_yz", m[5].ToString());
                            //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("\tPrincipalMomentsOfInteria_xx, \"{0}\"", m[0]);
                            Console.WriteLine("\tPrincipalMomentsOfInteria_yy, \"{0}\"", m[1]);
                            Console.WriteLine("\tPrincipalMomentsOfInteria_zz, \"{0}\"", m[2]);
                            writerXml.WriteElementString("PrincipalMomentsOfInteria_xx", m[0].ToString());
                            writerXml.WriteElementString("PrincipalMomentsOfInteria_yy", m[1].ToString());
                            writerXml.WriteElementString("PrincipalMomentsOfInteria_zz", m[2].ToString());
                            //Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]);

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

                            Console.WriteLine("PrincipalAxes:");
                            Console.WriteLine("\tPrincipalAxes_xx, \"{0}\"", m[0]);
                            Console.WriteLine("\tPrincipalAxes_xy, \"{0}\"", m[1]);
                            Console.WriteLine("\tPrincipalAxes_xz, \"{0}\"", m[2]);

                            Console.WriteLine("\tPrincipalAxes_yx, \"{0}\"", m[3]);
                            Console.WriteLine("\tPrincipalAxes_yy, \"{0}\"", m[4]);
                            Console.WriteLine("\tPrincipalAxes_yz, \"{0}\"", m[5]);

                            Console.WriteLine("\tPrincipalAxes_zx, \"{0}\"", m[6]);
                            Console.WriteLine("\tPrincipalAxes_zy, \"{0}\"", m[7]);
                            Console.WriteLine("\tPrincipalAxes_zz, \"{0}\"", m[8]);

                            writerXml.WriteElementString("PrincipalAxes_xx", m[0].ToString());
                            writerXml.WriteElementString("PrincipalAxes_xy", m[1].ToString());
                            writerXml.WriteElementString("PrincipalAxes_xz", m[2].ToString());
                            writerXml.WriteElementString("PrincipalAxes_yx", m[3].ToString());
                            writerXml.WriteElementString("PrincipalAxes_yy", m[4].ToString());
                            writerXml.WriteElementString("PrincipalAxes_yz", m[5].ToString());
                            writerXml.WriteElementString("PrincipalAxes_zx", m[6].ToString());
                            writerXml.WriteElementString("PrincipalAxes_zy", m[7].ToString());
                            writerXml.WriteElementString("PrincipalAxes_zz", m[8].ToString());
                            //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("\tRadiiOfGyration_xx, \"{0}\"", m[0]);
                            Console.WriteLine("\tRadiiOfGyration_xy, \"{0}\"", m[1]);
                            Console.WriteLine("\tRadiiOfGyration_xz, \"{0}\"", m[2]);

                            Console.WriteLine("\tRadiiOfGyration_yx, \"{0}\"", m[3]);
                            Console.WriteLine("\tRadiiOfGyration_yy, \"{0}\"", m[4]);
                            Console.WriteLine("\tRadiiOfGyration_yz, \"{0}\"", m[5]);

                            Console.WriteLine("\tRadiiOfGyration_zx, \"{0}\"", m[6]);
                            Console.WriteLine("\tRadiiOfGyration_zy, \"{0}\"", m[7]);
                            Console.WriteLine("\tRadiiOfGyration_zz, \"{0}\"", m[8]);
                            writerXml.WriteElementString("RadiiOfGyration_xx", m[0].ToString());
                            writerXml.WriteElementString("RadiiOfGyration_xy", m[1].ToString());
                            writerXml.WriteElementString("RadiiOfGyration_xz", m[2].ToString());
                            writerXml.WriteElementString("RadiiOfGyration_yx", m[3].ToString());
                            writerXml.WriteElementString("RadiiOfGyration_yy", m[4].ToString());
                            writerXml.WriteElementString("RadiiOfGyration_yz", m[5].ToString());
                            writerXml.WriteElementString("RadiiOfGyration_zx", m[6].ToString());
                            writerXml.WriteElementString("RadiiOfGyration_zy", m[7].ToString());
                            writerXml.WriteElementString("RadiiOfGyration_zz", m[8].ToString());
                            //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();
                            Console.WriteLine("\tRelativeAccuracyAchieved, \"{0}\"", relativeAccuracyAchieved);
                            writerXml.WriteElementString("RelativeAccuracyAchieved", relativeAccuracyAchieved.ToString());
                            Console.WriteLine("\tStatus, \"{0}\"", status);
                            writerXml.WriteElementString("Status", status.ToString());
                            Console.WriteLine();
                            writerXml.WriteEndElement();
                        }
                        //Console.ReadKey();
                    }
                    writerXml.WriteFullEndElement();
                    writerXml.Close();
                    Console.SetOut(oldOut);
                    writer.Close();
                    ostrm.Close();

                    // 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);
                Console.ReadKey();
            }
            finally
            {
                if (application != null)
                {
                    application.DelayCompute   = false;
                    application.DisplayAlerts  = true;
                    application.Interactive    = true;
                    application.ScreenUpdating = true;
                }

                OleMessageFilter.Unregister();
            }
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            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;

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

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

                    // 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);
                }
            }
            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();
            }
        }