Exemplo n.º 1
0
        private void buttonDeleteTheme_Click(object sender, EventArgs e)
        {
            var application     = SolidEdgeUtils.Connect(false);
            var customization   = application.Customization;
            var ribbonBarThemes = customization.RibbonBarThemes;

            SolidEdgeFramework.RibbonBarTheme ribbonBarTheme = null;

            // Look for our custom theme.
            foreach (SolidEdgeFramework.RibbonBarTheme theme in ribbonBarThemes)
            {
                if (theme.Name.Equals(_themeName, StringComparison.Ordinal))
                {
                    ribbonBarTheme = theme;
                }
            }

            // If found, delete it.
            if (ribbonBarTheme != null)
            {
                customization.BeginCustomization();
                ribbonBarThemes.Remove(ribbonBarTheme);
                ribbonBarThemes.Commit();
                customization.EndCustomization();
            }
        }
Exemplo n.º 2
0
 static void Main(string[] args)
 {
     var application      = SolidEdgeUtils.Connect();
     var documents        = application.Documents;
     var assemblyDocument = documents.AddAssemblyDocument();
     var draftDocument    = documents.AddDraftDocument();
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            // Connect to Solid Edge.
            var application = SolidEdgeUtils.Connect(true, true);

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

            // Get a folder that has Solid Edge files.
            var folder = new DirectoryInfo(SolidEdgeUtils.GetTrainingFolderPath());

            // Get the installed version of Solid Edge.
            var solidEdgeVesion = application.GetVersion();

            // Disable prompts.
            application.DisplayAlerts = false;

            // Process the files.
            foreach (var file in folder.EnumerateFiles("*.par", SearchOption.AllDirectories))
            {
                Console.WriteLine(file.FullName);

                // Open the document.
                var document = (SolidEdgeFramework.SolidEdgeDocument)documents.Open(file.FullName);

                // Give Solid Edge a chance to do processing.
                application.DoIdle();

                // Prior to ST8, we needed a reference to a document to close it.
                // That meant that SE can't fully close the document because we're holding a reference.
                if (solidEdgeVesion.Major < 108)
                {
                    // Close the document.
                    document.Close();

                    // Release our reference to the document.
                    Marshal.FinalReleaseComObject(document);
                    document = null;

                    // Give SE a chance to do post processing (finish closing the document).
                    application.DoIdle();
                }
                else
                {
                    // Release our reference to the document.
                    Marshal.FinalReleaseComObject(document);
                    document = null;

                    // Starting with ST8, the Documents collection has a CloseDocument() method.
                    documents.CloseDocument(file.FullName, false, Missing.Value, Missing.Value, true);
                }
            }

            application.DisplayAlerts = true;

            // Additional cleanup.
            Marshal.FinalReleaseComObject(documents);
            Marshal.FinalReleaseComObject(application);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Connects to a running instance of Solid Edge and extracts each sheet as an image.
        /// </summary>
        static void ExportFromOpenFile(Options options)
        {
            var application    = SolidEdgeUtils.Connect();
            var draftDocument  = application.GetActiveDocument <SolidEdgeDraft.DraftDocument>();
            var sections       = draftDocument.Sections;
            var workingSection = sections.WorkingSection;

            if (File.Exists(draftDocument.FullName))
            {
                // Get the path to the file.
                var exportPath = Path.GetDirectoryName(draftDocument.FullName);

                // Get the file name without the extension.
                var baseFileName = Path.GetFileNameWithoutExtension(draftDocument.FullName);

                // Build the base path to the new file.
                baseFileName = Path.Combine(exportPath, baseFileName);

                foreach (SolidEdgeDraft.Sheet sheet in workingSection.Sheets)
                {
                    // Build the base path & filename of the image.
                    var baseSheetFileName = String.Format("{0} ({1})", baseFileName, sheet.Index);

                    // Sheets native viewer format is EMF so they can be exported directly.
                    if (options.ExportEMF)
                    {
                        // Build full path to EMF.
                        var emfFileName = String.Format("{0}.emf", baseSheetFileName);

                        // Save EMF.
                        // Note: SaveAsEnhancedMetafile() is an extension method from SolidEdge.Community.dll.
                        sheet.SaveAsEnhancedMetafile(emfFileName);

                        Console.WriteLine("Extracted '{0}'.", emfFileName);
                    }

                    // Other formats must go through a vector to raster conversion process.
                    // This conversion process can be slow. The reason is that most drawings
                    // have large dimensions. You may consider resizing during the conversion.
                    if (options.IsRasterImageFormatSpecified)
                    {
                        // Get a new instance of Metafile from sheet.
                        using (var metafile = sheet.GetEnhancedMetafile())
                        {
                            ExportMetafile(metafile, baseSheetFileName, options);
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("Draft must be saved prior to exporting.");
            }
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 6
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
     {
     }
 }
Exemplo n.º 7
0
        private void Form1_Load(object sender, EventArgs e)
        {
            CustomEvents.ProgressChanged += CustomEvents_ProgressChanged;

            try
            {
                seVersionLabel.Text += SolidEdgeUtils.GetVersion();
            }
            catch
            {
                seVersionLabel.Text += "ERROR";
            }
        }
        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();
            }
        }
Exemplo n.º 9
0
        private void UpdateTreeView()
        {
            if (_application == null)
            {
                try
                {
                    _application = SolidEdgeUtils.Connect();
                }
                catch
                {
                    MessageBox.Show("Solid Edge is not running.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            if (_document == null)
            {
                try
                {
                    _document = (SolidEdgeFramework.SolidEdgeDocument)_application.ActiveDocument;
                }
                catch
                {
                }
            }

            if (_document != null)
            {
                try
                {
                    _documentEvents = (SolidEdgeFramework.ISEDocumentEvents_Event)_document.DocumentEvents;
                    _documentEvents.BeforeClose += _documentEvents_BeforeClose;
                    _documentEvents.SelectSetChanged += _documentEvents_SelectSetChanged;

                    UpdateTreeView(_application.ActiveSelectSet);
                }
                catch (System.Exception ex)
                {
                    _document = null;
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 打开文件夹中具体零件文件
        /// </summary>
        /// <param name="part"></param>
        private void opFile(Parts part)
        {
            string dirPath  = @fileFolderPath + "\\" + part.project;
            string filePath = dirPath + "\\" + part.name;
            // Connect to Solid Edge.
            var application = SolidEdgeUtils.Connect(true, true);
            // Get a reference to the Documents collection.
            var documents = application.Documents;
            // Get a folder that has Solid Edge files.
            var folder = new DirectoryInfo(dirPath);
            // Get the installed version of Solid Edge.
            var solidEdgeVesion = application.GetVersion();

            // Disable prompts.
            application.DisplayAlerts = false;

            if (Directory.Exists(dirPath))
            {
                List <string> extension = new List <string>(3);
                extension.Add(".par");
                extension.Add(".asm");
                //extension.Add(".cfg");
                if (File.Exists(filePath + extension[0]))
                {
                    //string partName = System.IO.Path.GetFileName();
                    string fullPath = System.IO.Path.GetFullPath(filePath + extension[0]);
                    // Open the document.
                    var document = (SolidEdgeFramework.SolidEdgeDocument)documents.Open(fullPath);
                    // Give Solid Edge a chance to do processing.
                    application.DoIdle();
                }
                else if (File.Exists(filePath + extension[1]))
                {
                    string fullPath = Path.GetFullPath(filePath + extension[1]);
                    // Open the document.
                    var document = (SolidEdgeFramework.SolidEdgeDocument)documents.Open(fullPath);
                    // Give Solid Edge a chance to do processing.
                    application.DoIdle();
                }
            }
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            // Dictionary variables to hold before and after settings.
            var snapshot1 = new Dictionary <SolidEdgeFramework.ApplicationGlobalConstants, object>();
            var snapshot2 = new Dictionary <SolidEdgeFramework.ApplicationGlobalConstants, object>();

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

            // Begin snapshot 1 of application global constants.
            CaptureApplicationGlobalConstants(application, snapshot1);

            // Force break-point. Change the Solid Edge setting in question.
            System.Diagnostics.Debugger.Break();

            // Begin snapshot 2 of application global constants.
            CaptureApplicationGlobalConstants(application, snapshot2);

            // Report the changes from snapshot 1 and snapshot 2.
            var enumerator = snapshot1.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var enumConstant = enumerator.Current.Key;
                var enumValue1   = enumerator.Current.Value;
                var enumValue2   = snapshot2[enumConstant];

                // Check to see if the snapshot 1 and snapshot 2 value is equal.
                if (Object.Equals(enumValue1, enumValue2) == false)
                {
                    Console.WriteLine("{0}: '{1}' '{2}'", enumConstant, enumValue1, enumValue2);
                }
            }

            // This will pause the console window.
            Console.WriteLine();
            Console.WriteLine("Press enter to contine.");
            Console.ReadLine();
        }
Exemplo n.º 12
0
        private void buttonCreateTheme_Click(object sender, EventArgs e)
        {
            var application     = SolidEdgeUtils.Connect(true);
            var customization   = application.Customization;
            var ribbonBarThemes = customization.RibbonBarThemes;

            SolidEdgeFramework.RibbonBarTheme ribbonBarTheme = null;

            // Look for our custom theme.
            foreach (SolidEdgeFramework.RibbonBarTheme theme in ribbonBarThemes)
            {
                if (theme.Name.Equals(_themeName, StringComparison.Ordinal))
                {
                    ribbonBarTheme = theme;
                }
            }

            customization.BeginCustomization();

            // If our theme is not found, create it.
            if (ribbonBarTheme == null)
            {
                ribbonBarTheme      = ribbonBarThemes.Create(null);
                ribbonBarTheme.Name = _themeName;
            }

            var ribbonBars = ribbonBarTheme.RibbonBars;

            foreach (SolidEdgeFramework.RibbonBar ribbonBar in ribbonBars)
            {
                // For this demo, only change the ribbon for the active environment.
                if (ribbonBar.Environment.Equals(application.ActiveEnvironment))
                {
                    var ribbonBarTabs = ribbonBar.RibbonBarTabs;

                    // Some environments likely dont' have RibbonBarTabs by default! i.e. Application environment.
                    if (ribbonBarTabs != null)
                    {
                        SolidEdgeFramework.RibbonBarTab     ribbonBarTab     = null;
                        SolidEdgeFramework.RibbonBarGroup   ribbonBarGroup   = null;
                        SolidEdgeFramework.RibbonBarControl ribbonBarControl = null;

                        // Check to see if the tab exists.
                        foreach (SolidEdgeFramework.RibbonBarTab tab in ribbonBarTabs)
                        {
                            if (tab.Name.Equals(_tabName, StringComparison.Ordinal))
                            {
                                ribbonBarTab = tab;
                            }
                        }

                        // Create the tab if it does not already exist.
                        if (ribbonBarTab == null)
                        {
                            var tabIndex = ribbonBarTabs.Count; // Insert at the end.
                            ribbonBarTab         = ribbonBarTabs.Insert(_tabName, tabIndex, SolidEdgeFramework.RibbonBarInsertMode.seRibbonBarInsertCreate);
                            ribbonBarTab.Visible = true;
                        }

                        var ribbonBarGroups = ribbonBarTab.RibbonBarGroups;

                        // Check to see if the group exists.
                        foreach (SolidEdgeFramework.RibbonBarGroup group in ribbonBarGroups)
                        {
                            if (group.Name.Equals(_groupName, StringComparison.Ordinal))
                            {
                                ribbonBarGroup = group;
                            }
                        }

                        // Create the group if it does not already exist.
                        if (ribbonBarGroup == null)
                        {
                            var groupIndex = ribbonBarGroups.Count; // Insert at the end.
                            ribbonBarGroup         = ribbonBarGroups.Insert(_groupName, groupIndex, SolidEdgeFramework.RibbonBarInsertMode.seRibbonBarInsertCreate);
                            ribbonBarGroup.Visible = true;
                        }

                        var ribbonBarControls = ribbonBarGroup.RibbonBarControls;

                        // Check to see if the control exists.
                        foreach (SolidEdgeFramework.RibbonBarControl control in ribbonBarControls)
                        {
                            if (control.Name.Equals(_macro, StringComparison.Ordinal))
                            {
                                ribbonBarControl = control;
                            }
                        }

                        // Create the control if it does not already exist.
                        if (ribbonBarControl == null)
                        {
                            object[] itemArray = { _macro };
                            ribbonBarControl         = ribbonBarControls.Insert(itemArray, null, SolidEdgeFramework.RibbonBarInsertMode.seRibbonBarInsertCreateButton);
                            ribbonBarControl.Visible = true;
                        }

                        break;
                    }
                }
            }

            ribbonBarThemes.ActivateTheme(_themeName);
            ribbonBarThemes.Commit();
            customization.EndCustomization();
        }
Exemplo n.º 13
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();
            }
        }
Exemplo n.º 14
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();
            }
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            // Start Solid Edge.
            var application = SolidEdgeUtils.Connect(true, true);

            // Disable (most) prompts.
            application.DisplayAlerts = false;

            var process            = Process.GetProcessById(application.ProcessID);
            var initialHandleCount = process.HandleCount;
            var initialWorkingSet  = process.WorkingSet64;
            var trainingFolderPath = SolidEdgeCommunity.SolidEdgeUtils.GetTrainingFolderPath();

            foreach (var fileName in Directory.EnumerateFiles(trainingFolderPath, "*.*", SearchOption.AllDirectories))
            {
                var extension = Path.GetExtension(fileName);

                if (
                    (extension.Equals(".asm", StringComparison.OrdinalIgnoreCase)) ||
                    (extension.Equals(".dft", StringComparison.OrdinalIgnoreCase)) ||
                    (extension.Equals(".par", StringComparison.OrdinalIgnoreCase)) ||
                    (extension.Equals(".psm", StringComparison.OrdinalIgnoreCase)) ||
                    (extension.Equals(".pwd", StringComparison.OrdinalIgnoreCase))
                    )
                {
                    Console.WriteLine("Opening & closing '{0}'", fileName);

                    var startHandleCount = process.HandleCount;
                    var startWorkingSet  = process.WorkingSet64;

                    using (var task = new IsolatedTask <OpenCloseTask>())
                    {
                        task.Proxy.Application = application;
                        task.Proxy.DoOpenClose(fileName);
                    }

                    process.Refresh();

                    var endHandleCount = process.HandleCount;
                    var endWorkingSet  = process.WorkingSet64;

                    Console.WriteLine("Handle count start\t\t'{0}'", startHandleCount);
                    Console.WriteLine("Handle count end\t\t'{0}'", endHandleCount);
                    Console.WriteLine("Handle count change\t\t'{0}'", endHandleCount - startHandleCount);
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Handle count total change\t'{0}'", endHandleCount - initialHandleCount);
                    Console.ForegroundColor = ConsoleColor.Gray;
                    Console.WriteLine("Working set start\t\t'{0}'", startWorkingSet);
                    Console.WriteLine("Working set end\t\t\t'{0}'", endWorkingSet);
                    Console.WriteLine("Working set change\t\t'{0}'", endWorkingSet - startWorkingSet);
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Working set total change\t'{0}'", endWorkingSet - initialWorkingSet);
                    Console.ForegroundColor = ConsoleColor.Gray;


                    Console.WriteLine();
                }
            }

            if (application != null)
            {
                application.DisplayAlerts = true;
            }

#if DEBUG
            System.Diagnostics.Debugger.Break();
#endif
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            var application = SolidEdgeUtils.Connect(true);

            application.Visible = true;
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application _application = null;

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

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

            // Get a folder that has Solid Edge files.
            //var folder = new DirectoryInfo("C:/Users/geevi/Documents/Work/Strath_CADfiles/summer work/step files/gate valves/ASAHI YUKIZAI/step files");
            var folder = new DirectoryInfo("C:/Users/geevi/Documents/Work/Strath_CADfiles/test_file");

            // Get the installed version of Solid Edge.
            var solidEdgeVesion = application.GetVersion();

            // Disable prompts.
            application.DisplayAlerts = false;


            int i = 0; //count the number of files with subassemblies
            int k = 1; //part number in a subassembly

            // Process the files.
            foreach (var file in folder.EnumerateFiles("*.stp", SearchOption.AllDirectories))
            {
                Console.WriteLine(file.FullName);



                var template = @"iso metric assembly.asm";
                //var template = @"iso metric part.par";
                // Open the document using a solid edge template
                var document = (SolidEdgeFramework.SolidEdgeDocument)documents.OpenWithTemplate(file.FullName, template);



                // Give Solid Edge a chance to do processing.
                application.DoIdle();

                AssemblyDocument _doc = application.ActiveDocument as AssemblyDocument;

                int part_count = _doc.Occurrences.Count;
                var occur      = _doc.Occurrences;

                //if there is more than one part in the assembly doc
                if (part_count > 1)
                {
                    for (int j = 1; j <= part_count; j++)
                    {
                        //string newfile_name = string.Format($"C:/Users/geevi/Documents/Work/Strath_CADfiles/test_file/Saved_Part_files/Part_{k}.par");
                        // _doc.SaveModelAs(occur.Item(j), newfile_name);
                        k++;
                    }

                    i++;
                }


                // Prior to ST8, we needed a reference to a document to close it.
                // That meant that SE can't fully close the document because we're holding a reference.
                if (solidEdgeVesion.Major < 108)
                {
                    // Close the document.
                    document.Close();

                    // Release our reference to the document.
                    Marshal.FinalReleaseComObject(document);
                    document = null;

                    // Give SE a chance to do post processing (finish closing the document).
                    application.DoIdle();
                }
                else
                {
                    // Release our reference to the document.
                    if (document != null)
                    {
                        Marshal.FinalReleaseComObject(document);

                        document = null;
                    }
                }

                documents.Close();
            }

            application.DisplayAlerts = true;

            // Additional cleanup.
            Marshal.FinalReleaseComObject(documents);
            Marshal.FinalReleaseComObject(application);
            Console.WriteLine("Finished reading files");
            //Console.WriteLine("The K value = {0}",k);
            Console.WriteLine("Number of files with more than one part = {0}", i);

            Console.Read();
        }