Advertisement
Guest User

Solid Edge read custom properties

a guest
Dec 17th, 2014
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.75 KB | None | 0 0
  1. private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             SolidEdgeFileProperties.PropertySets propertySets = null;
  4.             SolidEdgeFileProperties.Properties properties = null;
  5.             SolidEdgeFileProperties.Property property = null;
  6.             string format1 = "[{0}]";
  7.             string format2 = "{0} = {1}";
  8.             try
  9.             {
  10.                 // Create new instance of the PropertySets object
  11.                 propertySets = new SolidEdgeFileProperties.PropertySets();
  12.                 // Open a file
  13.                 propertySets.Open(Directory.GetCurrentDirectory() + @"\327935-01.par", true);
  14.                 // Example: Loop through all properties
  15.                 // Note that indexes are zero based
  16.                 for (int i = 0; i < propertySets.Count; i++)
  17.                 {
  18.                     properties = (SolidEdgeFileProperties.Properties)propertySets[i];
  19.                     // Note that indexes are zero based
  20.                     for (int j = 0; j < properties.Count; j++)
  21.                     {
  22.                         property = (SolidEdgeFileProperties.Property)properties[j];
  23.                         try
  24.                         {
  25.                             Console.WriteLine(
  26.                             string.Format(
  27.                             format2, property.Name, property.Value));
  28.                         }
  29.                         catch
  30.                         {
  31.                             Console.WriteLine(
  32.                             string.Format(
  33.                             format2, property.Name, "ERROR"));
  34.                         }
  35.                     }
  36.                 }
  37.                 // Get a reference to the SummaryInformation properties
  38.                 properties = (SolidEdgeFileProperties.Properties)
  39.                 propertySets["SummaryInformation"];
  40.                 // Get a reference to the Title property by name
  41.                 property = (SolidEdgeFileProperties.Property)
  42.                 properties["Title"];
  43.             }
  44.             catch (System.Exception ex)
  45.             {
  46.                 Console.WriteLine(ex.Message);
  47.             }
  48.             finally
  49.             {
  50.                 if (property != null)
  51.                 {
  52.                     Marshal.ReleaseComObject(property);
  53.                     property = null;
  54.                 }
  55.                 if (properties != null)
  56.                 {
  57.                     Marshal.ReleaseComObject(properties);
  58.                     properties = null;
  59.                 }
  60.                 if (propertySets != null)
  61.                 {
  62.                     propertySets.Close();
  63.                     Marshal.ReleaseComObject(propertySets);
  64.                     propertySets = null;
  65.                 }
  66.             }
  67.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement