| | |
| | | using SolidWorks.Interop.sldworks; |
| | | using SolidWorks.Interop.swconst; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | |
| | | namespace PdmSwPlugin.Common.Util |
| | |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取文档属性 |
| | | /// </summary> |
| | | /// <param name="currentModelDoc">文档</param> |
| | | /// <param name="needResolve">是否转换值</param> |
| | | /// <param name="skipName">跳过的name</param> |
| | | /// <returns></returns> |
| | | public static Dictionary<string, string> GetCustomProperties2(ModelDoc2 currentModelDoc, |
| | | bool needResolve, |
| | | HashSet<string> skipName = null) |
| | | { |
| | | CustomPropertyManager customPropertyManager = GetCustomPropertyManager(currentModelDoc); |
| | | if (customPropertyManager == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | Dictionary<string, string> Properties = new Dictionary<string, string>(); |
| | | string[] names = customPropertyManager.GetNames(); |
| | | if (names == null) |
| | | { |
| | | return Properties; |
| | | } |
| | | foreach (string name in names) |
| | | { |
| | | if (customPropertyManager.Get6(name, false, out string valueOut, out string resolvedValueOut, out _, out _) |
| | | != (int)swCustomInfoGetResult_e.swCustomInfoGetResult_NotPresent) |
| | | { |
| | | string value = (needResolve && (skipName == null || !skipName.Contains(name))) ? resolvedValueOut : valueOut; |
| | | Properties[name] = value; |
| | | } |
| | | } |
| | | return Properties; |
| | | } |
| | | |
| | | public static bool SaveDoc(ModelDoc2 doc, Dictionary<string, string> props, ref int err, ref int warn) |
| | | { |
| | | SetCustomProperties(doc, props); |
| | | if (doc.Save3((int)swSaveAsOptions_e.swSaveAsOptions_AvoidRebuildOnSave, |
| | | ref err, ref warn)) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | |
| | | public static Dictionary<string, string> GetCustomProperties(ModelDoc2 currentModelDoc, |
| | | bool needResolve, |
| | | HashSet<string> skipValue = null) |
| | |
| | | return Properties; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取文档属性 |
| | | /// </summary> |
| | | /// <param name="currentModelDoc">文档</param> |
| | | /// <param name="needResolve">是否转换值</param> |
| | | /// <param name="skipName">跳过的name</param> |
| | | /// <returns></returns> |
| | | public static Dictionary<string, string> GetCustomProperties2(ModelDoc2 currentModelDoc, |
| | | bool needResolve, |
| | | HashSet<string> skipName, |
| | | HashSet<string> skipResolveName) |
| | | { |
| | | CustomPropertyManager customPropertyManager = GetCustomPropertyManager(currentModelDoc); |
| | | if (customPropertyManager == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | Dictionary<string, string> Properties = new Dictionary<string, string>(); |
| | | string[] names = customPropertyManager.GetNames(); |
| | | if (names == null) |
| | | { |
| | | return Properties; |
| | | } |
| | | foreach (string name in names) |
| | | { |
| | | if (skipName != null && skipName.Contains(name)) continue; |
| | | if (customPropertyManager.Get6(name, false, out string valueOut, out string resolvedValueOut, out _, out _) |
| | | != (int)swCustomInfoGetResult_e.swCustomInfoGetResult_NotPresent) |
| | | { |
| | | string value = (needResolve && (skipResolveName == null || !skipResolveName.Contains(name))) ? resolvedValueOut : valueOut; |
| | | Properties[name] = value; |
| | | } |
| | | } |
| | | return Properties; |
| | | } |
| | | |
| | | public static bool SaveDoc(ModelDoc2 doc, Dictionary<string, string> props, ref int err, ref int warn) |
| | | { |
| | | SetCustomProperties(doc, props); |
| | | if (doc.Save3((int)swSaveAsOptions_e.swSaveAsOptions_AvoidRebuildOnSave, |
| | | ref err, ref warn)) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | public static string GetCustomValue(this Dictionary<string, string> datas, string name, bool ignoreCase = false) |
| | | { |
| | |
| | | return values[5].ToString(); |
| | | } |
| | | |
| | | public static string GetMassBySWDM(ModelDoc2 doc) |
| | | { |
| | | if (doc == null) return null; |
| | | double[] values = SwDMUtil.GetMassProperty(doc.GetPathName(), out string errMSg); |
| | | if (values == null) |
| | | { |
| | | return null; |
| | | } |
| | | return values[5].ToString(); |
| | | } |
| | | |
| | | public static bool SetCustomProperties(ModelDoc2 doc, string key, string value) |
| | | { |
| | | CustomPropertyManager cpm = doc.Extension.CustomPropertyManager[""]; |