///// <summary> ///// Returns all property sets as an IEnumerable. ///// </summary> ///// <param name="propertySets"></param> //public static IEnumerable<SolidEdgeFileProperties.Properties> AsEnumerable(this SolidEdgeFileProperties.PropertySets propertySets) //{ // List<SolidEdgeFileProperties.Properties> list = new List<SolidEdgeFileProperties.Properties>(); // foreach (var properties in propertySets) // { // list.Add((SolidEdgeFileProperties.Properties)properties); // } // return list.AsEnumerable(); //} /// <summary> /// Closes an open document with the option to save changes. /// </summary> /// <param name="propertySets"></param> /// <param name="saveChanges"></param> public static void Close(this SolidEdgeFileProperties.PropertySets propertySets, bool saveChanges) { if (saveChanges) { propertySets.Save(); } propertySets.Close(); }
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); } } }
/// <summary> /// Adds or modifies a custom property. /// </summary> public static SolidEdgeFileProperties.Property UpdateCustomProperty(this SolidEdgeFileProperties.PropertySets propertySets, string propertyName, double propertyValue) { return(propertySets.InternalUpdateCustomProperty(propertyName, propertyValue)); }
/// <summary> /// Adds or modifies a custom property. /// </summary> internal static SolidEdgeFileProperties.Property InternalUpdateCustomProperty(this SolidEdgeFileProperties.PropertySets propertySets, string propertyName, object propertyValue) { SolidEdgeFileProperties.Properties customPropertySet = null; SolidEdgeFileProperties.Property property = null; try { // Get a reference to the custom property set. customPropertySet = (SolidEdgeFileProperties.Properties)propertySets["Custom"]; // Attempt to get the custom property. property = (SolidEdgeFileProperties.Property)customPropertySet[propertyName]; // If we get here, the custom property exists so update the value. property.Value = propertyValue; } catch (System.Runtime.InteropServices.COMException) { // If we get here, the custom property does not exist so add it. property = (SolidEdgeFileProperties.Property)customPropertySet.Add(propertyName, propertyValue); } catch { throw; } return(property); }
// 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; }