internal SwDmConfiguration(ISwDMConfiguration conf, SwDmDocument3D doc) : base(conf) { Configuration = conf; Document = doc; m_Properties = new Lazy <ISwDmCustomPropertiesCollection>( () => new SwDmConfigurationCustomPropertiesCollection(this)); }
private void CountComponents(ISwDMConfiguration conf, Dictionary <string, int> cachedCount, ref int totalCount) { foreach (ISwDMComponent6 comp in ((ISwDMConfiguration2)conf).GetComponents() as object[] ?? new object[0]) { totalCount++; if (comp.DocumentType == SwDmDocumentType.swDmDocumentAssembly && !comp.IsSuppressed()) { try { var path = m_PathResolver.ResolvePath(Path.GetDirectoryName(m_ParentAssm.Path), comp.PathName); var confName = comp.ConfigurationName; var cacheKey = $"{path}:{confName}"; if (cachedCount.TryGetValue(cacheKey, out int count)) { totalCount += count; } else { if (File.Exists(path)) { int subTotalCount = 0; var subAssm = m_ParentAssm.SwDmApp.SwDocMgr .GetDocument(path, SwDmDocumentType.swDmDocumentAssembly, true, out SwDmDocumentOpenError err); try { if (subAssm != null) { var subConf = subAssm.ConfigurationManager.GetConfigurationByName(confName); if (subConf != null) { CountComponents(subConf, cachedCount, ref subTotalCount); } } totalCount += subTotalCount; cachedCount.Add(cacheKey, subTotalCount); } finally { subAssm?.CloseDoc(); } } } } catch { } } } }
/// <summary> /// Gets the custom property. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <param name="swDmDocument">The SolidWorks document manager document.</param> /// <param name="configuration">The configuration (the generic custom property will be used if no configuration specified).</param> /// <returns>The property value, or null if the property is not found.</returns> public static string GetCustomProperty(string propertyName, ISwDMDocument swDmDocument, string configuration = null) { string propertyValue; SwDmCustomInfoType type; if (string.IsNullOrEmpty(configuration)) { // Get the generic (non configuration specific) custom property propertyValue = swDmDocument.GetCustomProperty(propertyName, out type); } else { // Get the configuration specific custom property ISwDMConfiguration swDmConfiguration = swDmDocument.ConfigurationManager.GetConfigurationByName(configuration); propertyValue = swDmConfiguration.GetCustomProperty(propertyName, out type); } return(propertyValue); }