Example #1
0
        /// <summary>
        /// Performs a SEEC query to Teamcenter to determine if there are any draft files found for the ItemID / Rev.
        /// Document.FullFileName will not be empty if it found one draft file to open.
        /// </summary>
        /// <param name="Document"></param>
        internal void FetchTeamcenterFilesForItem(SEDocument Document)
        {
            object _listOfFilenamesInTC = null;
            int    _totalFilesFoundInTC = 0;
            int    _totalDraftsFound    = 0;

            try
            {
                CustomEvents.OnProgressChanged($"Searching TC for {Document.ItemID};{Document.RevID}!");
                SEEC.GetListOfFilesFromTeamcenterServer(Document.ItemID, Document.RevID, out _listOfFilenamesInTC, out _totalFilesFoundInTC);

                foreach (object file in (object[])_listOfFilenamesInTC)
                {
                    if (file.ToString().EndsWith(".dft", StringComparison.CurrentCultureIgnoreCase))
                    {
                        _totalDraftsFound++;
                        Document.FullFilePath = file.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                CustomEvents.OnProgressChanged($"SEEC Error: {ex.Message}");
            }

            CustomEvents.OnProgressChanged($"Total drafts found from TC: {_totalDraftsFound}");
            if (_totalDraftsFound > 1)
            {
                // Clearing out the file path since we had too many draft results
                // this will cause it to fail out on return...
                Document.FullFilePath = string.Empty;
            }
        }
 /// <summary>
 /// Load all of the background sheets for a particular document.
 /// </summary>
 /// <param name="DocumentObj"></param>
 internal static void LoadBackgroundSheets(SEDocument DocumentObj)
 {
     CustomEvents.OnProgressChanged($"Loading sheets for: {DocumentObj.CombinedListingName}");
     foreach (Sheet _sheet in (DocumentObj.SEDocumentInstance as DraftDocument).Sections.BackgroundSection.Sheets)
     {
         DocumentObj.BackgroundDocumentSheets.Add(_sheet);
     }
     CustomEvents.OnProgressChanged($"{DocumentObj.BackgroundDocumentSheets.Count} total sheets loaded");
 }
Example #3
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
     {
     }
 }
Example #4
0
        /// <summary>
        /// This method is only used if Solid Edge is in SEEC mode.
        /// This will perform the actual processing of the background sheet replacements
        /// </summary>
        /// <param name="TargetDoc"></param>
        /// <param name="TemplateDoc"></param>
        internal void ProcessSeecDocuments(SEDocument TargetDoc, SEDocument TemplateDoc)
        {
            // Initialize the SEEC Controller
            using (SEECController _sc = new SEECController(SEApplication))
            {
                // Confirm we are in SEEC mode
                if (!_sc.IsInSEECMode())
                {
                    CustomEvents.OnProgressChanged("Solid Edge is not in SEEC mode!");
                    throw new Exception("Solid Edge is not in SEEC mode!");
                }


                // Launch the file lookup window to select an already open file from SE. This is the target document for the replacements.
                CustomEvents.OnProgressChanged("Launching the file lookup");
                TargetDoc = SolidEdgeDocumentController.LoadOpenDocument(SEApplication);
                if (TargetDoc == null)
                {
                    throw new Exception("No target document selected!");
                }

                // Call the SEEC method to search for the item and rev provided by the user for the template draft doc.
                _sc.FetchTeamcenterFilesForItem(TemplateDoc);
                if (string.IsNullOrWhiteSpace(TemplateDoc.FullFilePath))
                {
                    CustomEvents.OnProgressChanged("Unable to find a file to open from TC!");
                    throw new Exception("Unable to find a file to open from TC!");
                }

                // Turn display alerts off and attempt to load the found template file into the cache
                SEApplication.DisplayAlerts = false;
                _sc.DownloadTCFileToCache(TemplateDoc);
                if (string.IsNullOrWhiteSpace(TemplateDoc.FullFilePath))
                {
                    throw new Exception("Failed to download file from TC!");
                }
                SEApplication.DisplayAlerts = true;


                // Attempt to open the template document from the local SEEC cache
                CustomEvents.OnProgressChanged("Loading up the template document");
                SolidEdgeDocumentController.OpenDocument(SEApplication, TemplateDoc, true);
                if (TargetDoc.SEDocumentInstance == null)
                {
                    throw new Exception("Template document failed to load!");
                }

                performSheetReplacement(TargetDoc, TemplateDoc);
            }
        }
        /// <summary>
        /// Perform the actual background sheet replacement.
        /// </summary>
        /// <param name="sheetReplacement"></param>
        /// <param name="TargetDocument"></param>
        /// <param name="TemplateDocument"></param>
        /// <param name="SEAppObj"></param>
        internal static void BackgroundReplacer(List <SheetReplacement> sheetReplacement, SEDocument TargetDocument,
                                                SEDocument TemplateDocument, SolidEdgeFramework.Application SEAppObj)
        {
            foreach (var item in sheetReplacement)
            {
                CustomEvents.OnProgressChanged($"Replacing background for target sheet: {item.TargetSheet.Name} with background sheet: {item.TemplateSheet.Name}");
                // Activate the target document
                TargetDocument.SEDocumentInstance.Activate();
                SEAppObj.DoIdle();

                // Active the target sheet where we want to paste our new template and clear it out
                item.TargetSheet.Activate();
                SEAppObj.DoIdle();

                TargetDocument.SEDocumentInstance.SelectSet.AddAll();
                TargetDocument.SEDocumentInstance.SelectSet.Delete();
                TargetDocument.SEDocumentInstance.SelectSet.RemoveAll();


                // Fetch the template background
                TemplateDocument.SEDocumentInstance.Activate();
                SEAppObj.DoIdle();

                item.TemplateSheet.Activate();
                SEAppObj.DoIdle();

                TemplateDocument.SEDocumentInstance.SelectSet.AddAll();
                TemplateDocument.SEDocumentInstance.SelectSet.Copy();
                TemplateDocument.SEDocumentInstance.SelectSet.RemoveAll();



                // Paste our copied background into the target doc/sheet
                TargetDocument.SEDocumentInstance.Activate();
                (SEAppObj.ActiveWindow as dynamic).Paste();

                if (ReplacementSettings.ResetTargetDraftToPageOneOnClose)
                {
                    // Reset the target document to sheet 1
                    try
                    {
                        (TargetDocument.SEDocumentInstance as SolidEdgeDraft.DraftDocument).Sections.WorkingSection.Sheets.Item(1).Activate();
                    }
                    catch
                    { }
                }
            }

            CustomEvents.OnProgressChanged("Replacement done!");
        }
Example #6
0
        /// <summary>
        /// This method will launch the sheet replacer prompt and perform the sheet replacements.
        /// </summary>
        /// <param name="TargetDoc"></param>
        /// <param name="TemplateDoc"></param>
        private void performSheetReplacement(SEDocument TargetDoc, SEDocument TemplateDoc)
        {
            CustomEvents.OnProgressChanged("Loading the sheet pointer");
            frmSheetReplacerPicker _sr = new frmSheetReplacerPicker(TargetDoc, TemplateDoc);

            _sr.ShowDialog();

            // Get the listing of sheets from the dialog. This will be empty if they choose not to replace any sheets.
            var _slist = _sr.SheetReplacerList;

            if (_slist.Count > 0)
            {
                CustomEvents.OnProgressChanged($"Performing the sheet replacer on {_slist.Count} sheets");
                SolidEdgeSheetController.BackgroundReplacer(_slist, TargetDoc, TemplateDoc, SEApplication);
            }
            else
            {
                throw new Exception("No sheets were selected to be replaced by anything!");
            }
        }
Example #7
0
        /// <summary>
        /// Performs the download of the Teamcenter file into the local cache.
        /// After download has finished, it will adjust the Document.FullFilePath to have the extended file path to the file in the cache.
        /// </summary>
        /// <param name="Document"></param>
        internal void DownloadTCFileToCache(SEDocument Document)
        {
            string _pdmCachePath = string.Empty;

            // get the SEEC managed path
            SEEC.GetPDMCachePath(out _pdmCachePath);

            try
            {
                CustomEvents.OnProgressChanged($"Downloading template document {Document.FullFilePath} from TC to local SEEC cache");
                SEEC.CheckOutDocumentsFromTeamCenterServer(Document.ItemID, Document.RevID, true, Document.FullFilePath, DocumentDownloadLevel.SEECDownloadFirstLevel);
            }
            catch (Exception ex)
            {
                CustomEvents.OnProgressChanged($"SEEC Error: {ex.Message}");
                Document.FullFilePath = string.Empty;
                return;
            }

            Document.FullFilePath = System.IO.Path.Combine(_pdmCachePath, Document.FullFilePath);
        }
Example #8
0
        /// <summary>
        /// This method is only used if Solid Edge is in managed mode.
        /// This will perform the actual processing of the background sheet replacements
        /// </summary>
        /// <param name="TargetDoc"></param>
        /// <param name="TemplateDoc"></param>
        internal void ProcessUnmanagedDocuments(SEDocument TargetDoc, SEDocument TemplateDoc)
        {
            if (isApplicationInSEECMode())
            {
                CustomEvents.OnProgressChanged("Solid Edge is in SEEC mode!");
                throw new Exception("Solid Edge is in SEEC mode, but you have selected Unmanaged!");
            }

            // Either load the file lookup window to select an already open file, or open a file via the FullFilePath location.
            if (string.IsNullOrWhiteSpace(TargetDoc.FullFilePath))
            {
                CustomEvents.OnProgressChanged("No target file defined, launching the open file lookup");
                TargetDoc = SolidEdgeDocumentController.LoadOpenDocument(SEApplication);
                if (TargetDoc == null)
                {
                    throw new Exception("No target document selected!");
                }
            }
            else
            {
                CustomEvents.OnProgressChanged("Target file is defined, opening up the document");
                SolidEdgeDocumentController.OpenDocument(SEApplication, TargetDoc, false);
                if (TargetDoc.SEDocumentInstance == null)
                {
                    throw new Exception("Target document failed to load!");
                }
            }

            // Attempt to open the Template document
            CustomEvents.OnProgressChanged("Loading up the template document");
            SolidEdgeDocumentController.OpenDocument(SEApplication, TemplateDoc, true);
            if (TargetDoc.SEDocumentInstance == null)
            {
                throw new Exception("Template document failed to load!");
            }

            performSheetReplacement(TargetDoc, TemplateDoc);
        }
        /// <summary>
        /// Open a document in Solid edge.
        /// </summary>
        /// <param name="SEAppObj"></param>
        /// <param name="DocumentObj"></param>
        /// <param name="OpenDraftReadOnly"></param>
        internal static void OpenDocument(Application SEAppObj, SEDocument DocumentObj, bool OpenDraftReadOnly)
        {
            // Turn display alerts off so any extra SE prompts dont show up on/after open.
            SEAppObj.DisplayAlerts = false;

            object _originalOpenDraftReadOnlyValue = null;
            object _fileReadOnlySetting            = OpenDraftReadOnly;

            try
            {
                // Fetch the user's readonly attribute for draft files to restore it after we process our open.
                SEAppObj.GetGlobalParameter(ApplicationGlobalConstants.seApplicationGlobalOpenAsReadOnlyDftFile,
                                            _originalOpenDraftReadOnlyValue);

                // Set the readonly attribute per our bool on the input
                SEAppObj.SetGlobalParameter(ApplicationGlobalConstants.seApplicationGlobalOpenAsReadOnlyDftFile,
                                            _fileReadOnlySetting);

                CustomEvents.OnProgressChanged($"Opening document: {DocumentObj.FullFilePath}");

                DocumentObj.SEDocumentInstance = (SolidEdgeDocument)SEAppObj.Documents.Open(DocumentObj.FullFilePath);
                DocumentObj.FileName           = DocumentObj.SEDocumentInstance.Name;
                LoadBackgroundSheets(DocumentObj);
            }
            catch
            {
            }
            finally
            {
                SEAppObj.DisplayAlerts = true;

                // Reset the readonly attribute back to the users defined value
                SEAppObj.SetGlobalParameter(ApplicationGlobalConstants.seApplicationGlobalOpenAsReadOnlyDftFile,
                                            _originalOpenDraftReadOnlyValue);
            }
        }
Example #10
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!validateFilePaths())
            {
                return;
            }

            if (clearLogChkbox.Checked)
            {
                richTextBox1.Text = "";
            }


            ReplacementSettings.ResetTargetDraftToPageOneOnClose = resetSheet1Chkbox.Checked;


            using (SolidEdgeApplicationController _ac = new SolidEdgeApplicationController())
            {
                _ac.LoadSolidEdgeApplication(!fileAlreadyOpenChkBox.Checked);

                if (_ac.SEApplication == null)
                {
                    MessageBox.Show("Solid Edge is not currently running. You cannot already have the target file open.");
                    return;
                }

                if (seecRadio.Checked)
                {
                    using (SEDocument _targetDoc = new SEDocument(string.Empty, false, false))
                        using (SEDocument _templateDoc = new SEDocument(string.Empty, !leaveTempOpenChkBox.Checked, false)
                        {
                            ItemID = itemIDTxtbox.Text, RevID = revTxtbox.Text
                        })
                        {
                            try
                            {
                                _ac.ProcessSeecDocuments(_targetDoc, _templateDoc);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show($"Error!\r\n\r\n{ex.Message}");
                            }
                        }
                }

                if (unmanagedRadio.Checked)
                {
                    using (SEDocument _targetDoc = new SEDocument(targetFileTextbox.Text, false, false))
                        using (SEDocument _templateDoc = new SEDocument(templateFileTextBox.Text, !leaveTempOpenChkBox.Checked, false))
                        {
                            try
                            {
                                _ac.ProcessUnmanagedDocuments(_targetDoc, _templateDoc);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show($"Error!\r\n\r\n{ex.Message}");
                            }
                        }
                }

                CustomEvents.OnProgressChanged("Finished!");

                _ac.SEApplication.DisplayAlerts = true;
            }

            MessageBox.Show("Done");
        }