/// <summary> /// Called when Solid Edge raises the SolidEdgeFramework.ISEAddInEdgeBarEvents[Ex].AddPage() event. /// </summary> public override void OnCreateEdgeBarPage(SolidEdgeCommunity.AddIn.EdgeBarController controller, SolidEdgeFramework.SolidEdgeDocument document) { // Note: Confirmed with Solid Edge development, OnCreateEdgeBarPage does not get called when Solid Edge is first open and the first document is open. // i.e. Under the hood, SolidEdgeFramework.ISEAddInEdgeBarEvents[Ex].AddPage() is not getting called. // As an alternative, you can call DemoAddIn.Instance.EdgeBarController.Add() in some other event if you need. // Get the document type of the passed in document. var documentType = document.Type; var imageId = 1; // Depending on the document type, you may have different edgebar controls. switch (documentType) { case SolidEdgeFramework.DocumentTypeConstants.igAssemblyDocument: case SolidEdgeFramework.DocumentTypeConstants.igDraftDocument: case SolidEdgeFramework.DocumentTypeConstants.igPartDocument: case SolidEdgeFramework.DocumentTypeConstants.igSheetMetalDocument: controller.Add <MyEdgeBarControl>(document, imageId); break; } }
// Scrive singola prop text nel doc attivo public bool ScriviSingolaProprieta(string nomeP, string valoreP) { bool ret = false; try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { application = null; } if (application != null) { SolidEdgeFramework.PropertySets propertySets = null; // Proprieta` del documento aperto SolidEdgeFramework.Properties properties = null; SolidEdgeFramework.Property property = null; try { document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; propertySets = (SolidEdgeFramework.PropertySets)document.Properties; properties = propertySets.Item("Custom"); property = properties.Add(nomeP, valoreP); ret = true; } catch // Restituisce false se eccezione { ret = false; } finally { if (property != null) { Marshal.ReleaseComObject(property); property = null; } if (properties != null) { Marshal.ReleaseComObject(properties); properties = null; } if (propertySets != null) { Marshal.ReleaseComObject(propertySets); propertySets = null; } if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } } return ret; }
// Restituisce string con il tipo di documento attivo public string TipoDocumentoAttivo() { string tipoDoc = ""; try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { tipoDoc = "Nessuna istanza attiva"; application = null; } if(application != null) // Se SE e` in funzione, cerca di leggere il tipo di documento attivo { try { document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; switch (document.Type) { case DocumentTypeConstants.igAssemblyDocument: tipoDoc = tipoAssembly; break; case DocumentTypeConstants.igDraftDocument: tipoDoc = tipoDraft; break; case DocumentTypeConstants.igPartDocument: tipoDoc = tipoPart; break; case DocumentTypeConstants.igSheetMetalDocument: tipoDoc = tipoSheetMetal; break; case DocumentTypeConstants.igUnknownDocument: tipoDoc = tipoSconosciuto; break; case DocumentTypeConstants.igWeldmentAssemblyDocument: tipoDoc = tipoWeldmentAssembly; break; case DocumentTypeConstants.igWeldmentDocument: tipoDoc = tipoWeldment; break; } } catch { tipoDoc = "Nessun documento attivo"; } finally { if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } } return tipoDoc; }
// Salva e restituisce il nome completo del doc attivo public string SaveDocumentoAttivo() { string nomeDoc = ""; try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { application = null; } if (application != null) // Se SE e` in funzione, cerca di leggere il tipo di documento attivo { try { document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; // Di tipo Draft nomeDoc = document.FullName; document.Save(); document.SaveAs(fullpdfDoc); // Salva il documento come pdf //document.SaveAs(fulldwgDoc); // Salva solo il foglio attivo come dwg SolidEdgeDraft.Sheet ActiveSheet; // Memorizza il foglio attivo ActiveSheet = ((SolidEdgeDraft.DraftDocument)document).ActiveSheet; // Percorre i fogli e li salva singolarmente in dwg SolidEdgeDraft.Sections sections = null; SolidEdgeDraft.Section section = null; SolidEdgeDraft.SectionSheets sectionSheets = null; SolidEdgeDraft.Sheet sheet = null; sections = ((SolidEdgeDraft.DraftDocument)document).Sections; // Le sezioni del documento dft section = sections.WorkingSection; // Sezione con i fogli di lavoro (non background) sectionSheets = section.Sheets; // Ottiene la lista dei fogli for (int j = 1; j <= sectionSheets.Count; j++) // Percorre tutti i fogli { sheet = sectionSheets.Item(j); sheet.Activate(); string dwgSuffix = ""; // Se solo 1 foglio, nessuna estensione if(sectionSheets.Count> 1) dwgSuffix = dwgShExt + j.ToString(); document.SaveAs(fulldwgDoc + dwgSuffix + dwgExt); // Salva il foglio attivo come dwg con estensione } ActiveSheet.Activate(); // Riattiva il foglio memorizzato } catch { //nomeDoc = ""; } finally { if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } } return nomeDoc; }
// Scrive lista prop nel doc attivo (in lista dati o tutte) public bool ScriviListaProprieta(bool bTutte) { bool ret = false; try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { application = null; } if(application != null) { SolidEdgeFramework.PropertySets propertySets = null; // Proprieta` del documento aperto (non del file) SolidEdgeFramework.Properties properties = null; SolidEdgeFramework.Property property = null; try { document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; propertySets = (SolidEdgeFramework.PropertySets)document.Properties; properties = propertySets.Item("Custom"); foreach(ProprietaSolidEdge pr in listaProprietaFile) // Percorre la lista proprieta` { if(listaProprietaDati.Contains(pr.Nome) || bTutte) // Copia se in lista o se flag property = properties.Add(pr.Nome, pr.Valore); } ret = true; } catch // Restituisce false se eccezione { ret = false; } finally { if (property != null) { Marshal.ReleaseComObject(property); property = null; } if (properties != null) { Marshal.ReleaseComObject(properties); properties = null; } if (propertySets != null) { Marshal.ReleaseComObject(propertySets); propertySets = null; } if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } } return ret; }
// Restituisce il nome del foglio di background attivo public string NomeFoglioBackgroundAttivo() { string messaggio = ""; // Cancella i dati preesistenti try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { messaggio = "Nessuna istanza attiva"; application = null; } try { document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; if (document.Type == DocumentTypeConstants.igDraftDocument) // Se e` un draft... { messaggio = ((SolidEdgeDraft.DraftDocument)document).ActiveSheet.Background.Name; } else { messaggio = "Non e` un draft"; } } catch (System.Exception ex) // Messaggio se eccezione { messaggio = "Eccezione: " + ex.Message + " + Nessun documento attivo"; } finally { if (drawingViews != null) { foreach (SolidEdgeDraft.DrawingView drawingView in drawingViews) { Marshal.ReleaseComObject(drawingView); } } if (drawingViews != null) { Marshal.ReleaseComObject(drawingViews); drawingViews = null; } if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } return messaggio; }
// Imposta i nomi completi del file attivo... public bool PreparaNomifile() { // ...solo se e` una dft bool done = false; string simplenameDoc = ""; string pathDoc = ""; string codenameDoc = ""; fullnameDoc = ""; fullpdfDoc = ""; fulldwgDoc = ""; // Azzera i nomi try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { application = null; } if (application != null) // Se SE e` in funzione, cerca di leggere il tipo di documento attivo { try { document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; if(document.Type == DocumentTypeConstants.igDraftDocument) { fullnameDoc = document.FullName; // Nome completo string codice = ""; string[] split = document.Name.Split(new Char [] {'.'}); simplenameDoc = split[0]; // Nome senza estensioni pathDoc = document.Path + SolidEdgeUtils.pathSeparator; // Path con separatore CreaListaProprietaDaIstanzaSolidEdge(fullnameDoc); // Riempie lista proprieta` del doc attivo foreach (ProprietaSolidEdge pr in listaProprietaFile) // Legge le proprieta` { if(pr.Nome == listaProprietaDati[0]) // Estrae quelle con il primo nome { // del file di configurazione codice = pr.Valore; } } List<string>[] lst = Codici(codice); // Estrae codici ed estensioni foreach(string s in lst[0]) { codenameDoc += s; // Nomi senza estensione } if(codenameDoc != simplenameDoc) // Corrispondenza nomefile e codice nomecodicicorrispondono = false; else nomecodicicorrispondono = true; foreach(string s in lst[1]) // Aggiunge estensione { codenameDoc += s; } fullpdfDoc = pathDoc + "PDF" + SolidEdgeUtils.pathSeparator + codenameDoc + pdfExt; fulldwgDoc = pathDoc + "DWG" + SolidEdgeUtils.pathSeparator + codenameDoc; //+ dwgExt; //MessageBox.Show(fullnameDoc + "\n" + fullpdfDoc + "\n" + fulldwgDoc); done = true; } else { //MessageBox.Show(document.Type.ToString()); } } catch /*(System.Exception ex)*/ { fullnameDoc = ""; //MessageBox.Show(ex.Message); } finally { if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } } return done; }
// Restituisce il nome completo del doc attivo public string NomeDocumentoAttivo() { string nomeDoc = ""; try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { application = null; } if (application != null) // Se SE e` in funzione, cerca di leggere il tipo di documento attivo { try { document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; nomeDoc = document.FullName; } catch { nomeDoc = ""; } finally { if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } } return nomeDoc; }
// Restituisce true se il doc indicato e` aperto nella sessione SE public bool DocumentoAperto(string fullname) { bool ret = false; try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { application = null; } if (application != null) // Se SE e` in funzione, leggere i documenti aperti e li mette in una lista { try { foreach (SolidEdgeFramework.SolidEdgeDocument doc in application.Documents) { if(doc.FullName == fullname) { ret = true; break; } } } catch { ret = false; } finally { if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } } return ret; }
// Riempie una lista con le scale delle viste del draft public string CreaListaScale() { string messaggio = ""; // Cancella i dati preesistenti listaScale.Clear(); try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { messaggio = "Nessuna istanza attiva"; application = null; } try { document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; if (document.Type == DocumentTypeConstants.igDraftDocument) // Se e` un draft... { int count, i; // ... estrae le viste del foglio attivo double scala; string tScala; drawingViews = ((SolidEdgeDraft.DraftDocument)document).ActiveSheet.DrawingViews; count = drawingViews.Count; for (i = 0; i < count; i++) // Percorre le viste { drawingView = drawingViews.Item(i+1); scala = drawingView.ScaleFactor; if(scala >= 1.0) tScala = scala.ToString()+":1"; else tScala = "1:"+(1.0/scala).ToString(); listaScale.Add(tScala); } } else { messaggio = "Non e` un draft"; } } catch (System.Exception ex) // Messaggio se eccezione { messaggio = "Eccezione: " + ex.Message + " + Nessun documento attivo"; } finally { if (drawingViews != null) { foreach (SolidEdgeDraft.DrawingView drawingView in drawingViews) { Marshal.ReleaseComObject(drawingView); } } if (drawingViews != null) { Marshal.ReleaseComObject(drawingViews); drawingViews = null; } if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } return messaggio; }
// Lista da doc collegato aperto public string CreaListaProprietaDaIstanzaSolidEdge(string fullname) { string msg = ""; SolidEdgeFramework.SolidEdgeDocument activeDocument = null; // Documento attivo SolidEdgeFramework.PropertySets propertySets = null; // Proprieta` del documento aperto (non del file) SolidEdgeFramework.Properties properties = null; //SolidEdgeFramework.Property property = null; try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { application = null; } if (application != null) // Se SE e` in funzione... { listaProprietaFile.Clear(); // Cancella la lista delle proprieta attuale try { activeDocument = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; // Salva il rif. al doc. attivo if(AttivaDocumento(fullname)) // Attiva il documento aperto con il nome file richiesto... { msg += " - "; application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; // Ne legge i rif. alle proprieta` propertySets = (SolidEdgeFramework.PropertySets)document.Properties; properties = propertySets.Item("Custom"); foreach (SolidEdgeFramework.Property pr in properties) // Percorre le proprieta` { listaProprietaFile.Add(new ProprietaSolidEdge(pr.Name, pr.get_Value(), 0)); // e le mette in una lista if (pr != null) { Marshal.ReleaseComObject(pr); } } msg = "Lettura proprieta` completata"; } } catch (System.Exception ex) { msg += ex.Message + " in CreaListaProprietaDaIstanzaSolidEdge()"; } finally { if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } activeDocument.Activate(); // Ripristina il doc che era attivo all'inizio della funzione } } return msg; }
// Riempie la lista dei nomi file collegati e rest. string messaggio public string CreaListaModelli() { string messaggio = ""; // Cancella i dati preesistenti listaModelli.Clear(); try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { messaggio = "Nessuna istanza attiva"; application = null; } try { document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; if(document.Type == DocumentTypeConstants.igDraftDocument) // Se e` un draft... { int count, i; // ...estrae i documenti linkati modelLinks = ((SolidEdgeDraft.DraftDocument)document).ModelLinks; count = modelLinks.Count; for (i = 0; i < count; i++) // Li inserisce in una lista { modelLink = modelLinks.Item(i + 1); string nomeFile = modelLink.FileName; // Filename completo int indx = nomeFile.IndexOf(altSeparator); // Elimina alternate assembly if( indx != -1) { nomeFile = nomeFile.Remove(indx); // Tutto cio` dopo '!' } listaModelli.Add(nomeFile); } } else { messaggio = "Non e` un draft"; } } catch (System.Exception ex) // Messaggio se eccezione { messaggio = "Eccezione: " + ex.Message + " + Nessun documento attivo"; } finally { if (modelLinks != null) { foreach(SolidEdgeDraft.ModelLink modelLink in modelLinks) { Marshal.ReleaseComObject(modelLink); } } if (modelLinks != null) { Marshal.ReleaseComObject(modelLinks); modelLinks = null; } if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } return messaggio; }