public static CadPart ParseItem(string partCachePath) { SolidEdgeFileProperties.PropertySets propertySets = null; SolidEdgeFileProperties.Properties properties = null; SolidEdgeFileProperties.Property JDE = null; SolidEdgeFileProperties.Property REVISION = null; //SolidEdgeFileProperties.Property FILENAME = null; try { // Create new instance of the PropertySets object propertySets = new SolidEdgeFileProperties.PropertySets(); // Open a file propertySets.Open(partCachePath, true); // Get a reference to the SummaryInformation properties properties = (SolidEdgeFileProperties.Properties)propertySets["ProjectInformation"]; //// Jde JDE = (SolidEdgeFileProperties.Property)properties["Document Number"]; //// Revision REVISION = (SolidEdgeFileProperties.Property)properties["Revision"]; //// filename string filename = System.IO.Path.GetFileName(partCachePath); // formatting for json extraction var part = new CadPart { JdeNumber = (string)JDE.Value, Revision = (string)REVISION.Value, Filename = filename }; return(part); //Console.WriteLine(JDE.Value); //Console.WriteLine(REVISION.Value); //Console.WriteLine(filename); } catch (System.Exception ex) { Console.WriteLine(ex.Message); var part = new CadPart { JdeNumber = null, Revision = null, Filename = null }; return(part); } }
public static string GetJde(string partCachePath) { SolidEdgeFileProperties.PropertySets propertySets = null; SolidEdgeFileProperties.Properties properties = null; SolidEdgeFileProperties.Property property = null; try { // Create new instance of the PropertySets object propertySets = new SolidEdgeFileProperties.PropertySets(); // Open a file propertySets.Open(partCachePath, true); // Get a reference to the SummaryInformation properties properties = (SolidEdgeFileProperties.Properties)propertySets["Custom"]; // Get a reference to the Title property by name property = (SolidEdgeFileProperties.Property)properties["JDELITM"]; // TODO: Print the list of available option. return(property.Value.ToString()); } catch (Exception ex) { Console.WriteLine(ex.Message); return(null); } finally { if (property != null) { Marshal.ReleaseComObject(property); } if (properties != null) { Marshal.ReleaseComObject(properties); } if (propertySets != null) { propertySets.Close(); Marshal.ReleaseComObject(propertySets); } } }
// Lista da doc collegato su discio (poi resta in read only) public string CreaListaProprietaDaFile(string fullname) { string msg = ""; if(DocumentoAperto(fullname)) { return("Documento aperto"); } SolidEdgeFileProperties.PropertySets propertySets3D = null; // Oggetti proprieta` del 3D SolidEdgeFileProperties.Properties properties3D = null; FileInfo dis3D = new FileInfo(fullname); // Crea rif. al file if (dis3D.Exists) // Se il file esiste { listaProprietaFile.Clear(); // Cancella la lista delle proprieta attuale try { propertySets3D = new SolidEdgeFileProperties.PropertySets(); // Oggetto PropertySets propertySets3D.Open(fullname, true); // Apre proprieta` file readonly (true) properties3D = (SolidEdgeFileProperties.Properties)propertySets3D["Custom"]; // Custom Property Set foreach (SolidEdgeFileProperties.Property pr in properties3D) // Legge le proprieta` { listaProprietaFile.Add(new ProprietaSolidEdge(pr.Name, pr.Value, pr.ID)); // e le mette in una lista if (pr != null) { Marshal.ReleaseComObject(pr); } } msg = "Lettura proprieta` completata"; } catch (System.Exception ex) { msg += ex.Message + " in CreaListaProprietaDaFile()"; } finally // ATTENZIONE: NON RILASCIA IL FILE 3D, che rimane read-only ! { if (properties3D != null) { Marshal.ReleaseComObject(properties3D); properties3D = null; } if (propertySets3D != null) { propertySets3D.Close(); // Chiude il file prima di rilasciare il COM Marshal.ReleaseComObject(propertySets3D); Marshal.FinalReleaseComObject(propertySets3D); propertySets3D = null; } GC.Collect(); // Per evitare errore di share violation dopo rilascio dei COM ? GC.WaitForPendingFinalizers(); // Ma il file resta aperto. } } // fine blocco if(dis3D.Exists) else { msg = "File inesistente"; } return msg; }