private SldDMComponentItem GetComponentInfo( SwDMComponent9 currentComponent, int level, int parentId) { if (currentComponent == null || level < 0 || parentId <= 0) { return(null); } string fullPath = currentComponent.PathName;; SldDMComponentItem item = SldDMComponentItem.GenerateTheNext(); item.ParentId = parentId; item.Level = level; try { item.FullPath = fullPath; item.FeatureName = currentComponent.Name2; item.FeatureId = currentComponent.GetID(); item.IsSuppressed = currentComponent.IsSuppressed(); item.FileName2D = EngineeringDrawingFile.Get2DFileNameIfExisting(fullPath); item.Visible = !currentComponent.IsHidden(); SwDmDocumentOpenError openResult; SwDMDocument17 doc = currentComponent.GetDocument2(true, this.GlobalSearchOption, out openResult) as SwDMDocument17; if (doc == null || openResult != SwDmDocumentOpenError.swDmDocumentOpenErrorNone) { Debug.WriteLine(string.Format("GetComponentInfo:couldn't open {0},the return value is:{1}", fullPath, openResult.ToString())); return(null); } SwDMConfiguration14 config = doc.ConfigurationManager.GetConfigurationByName(currentComponent.ConfigurationName) as SwDMConfiguration14; if (File.Exists(fullPath)) { item.AllCustomProperties = GetDocumentPropertiesViaDM.RetrievePropertiesUnderConfig( fullPath, config, GetDocumentPropertiesViaDM.PropertyNamesOftenUsed, true); } item.ConfigurationCount = doc.ConfigurationManager.GetConfigurationCount(); item.ChildrenCount = doc.GetComponentCount(); doc.CloseDoc(); Marshal.ReleaseComObject(doc); this.CallbackGettingExtraInfo?.Invoke(ref item); } catch (Exception ex) { Debug.WriteLine(string.Format("GetComponentInfo:when dealing {0}, exception occurred:{1}", fullPath, ex.Message)); } return(item); }
private void CopyFromPreviousPart(ComponentAndTask_Part previousComponentAndTask, int newLevel, int newParentId) { if (previousComponentAndTask == null || previousComponentAndTask.Id <= 0) { Debug.WriteLine(string.Format("CopyFromPreviousPart: invalid parameter")); return; } previousComponentAndTask.TheTask.Wait(); SldDMComponentItem thePartInfo = this.ResultsAtPopulating.FirstOrDefault(x => x.Id == previousComponentAndTask.Id); if (thePartInfo == null) { Debug.WriteLine(string.Format("CopyFromPreviousPart: couldn't find component with Id={0}", previousComponentAndTask.Id)); return; } SldDMComponentItem me = SldDMComponentItem.Clone(thePartInfo, newLevel, newParentId); this.ResultsAtPopulating.Enqueue(me); }
private void IterateBatch(IEnumerable <SwDMComponent9> items, int level, int parentId) { if (items == null || items.Count() <= 0 || level < 0) { return; } try { foreach (SwDMComponent9 activeComponent in items) { SldDMComponentItem singlePartInfo = this.GetComponentInfo(activeComponent, level, parentId); this.ResultsAtPopulating.Enqueue(singlePartInfo); Console.WriteLine(string.Format("IterateBatch:遍历成功ID={0}的零件:{1}", singlePartInfo.Id, singlePartInfo.FullPath)); } } catch (Exception ex) { Trace.WriteLine(string.Format("IterateBatch:遍历ID={0}装配体下的零件时发生异常:{1}", parentId, ex.Message)); } }
/// <summary> /// Clone an item /// </summary> /// <param name="item">The item to be cloned from</param> /// <param name="newLevel">new level for the cloned item</param> /// <param name="newParentId">new parent if of the cloned item</param> /// <returns>The cloned item</returns> public static SldDMComponentItem Clone(SldDMComponentItem item, int newLevel, int newParentId) { if (item == null) { return(null); } SldDMComponentItem cloned = GenerateTheNext(); cloned.Level = newLevel; cloned.ParentId = newParentId; cloned.ChildrenCount = item.ChildrenCount; cloned.FullPath = item.FullPath; cloned.Tag = item.Tag; cloned.FeatureName = item.FeatureName; cloned.FeatureId = item.FeatureId; cloned.IsSuppressed = item.IsSuppressed; cloned.ConfigurationCount = item.ConfigurationCount; cloned.FileName2D = item.FileName2D; cloned.Visible = item.Visible; cloned.AllCustomProperties = item.AllCustomProperties; return(cloned); }
private int GetTopDocumentInfo( string fullPath, SwDMDocument17 currentDocument, SwDMConfiguration14 currentConfig) { if (string.IsNullOrEmpty(fullPath) || currentDocument == null || currentConfig == null) { return(-1); } SldDMComponentItem root = SldDMComponentItem.GenerateTheRoot(); Task task = Task.Factory.StartNew(() => { root.FullPath = fullPath; root.FeatureName = currentDocument.Title; root.ConfigurationCount = currentDocument.GetComponentCount(); object[] subComponents = currentConfig.GetComponents(); root.ChildrenCount = subComponents == null ? 0 : subComponents.Length; if (File.Exists(fullPath)) { root.AllCustomProperties = GetDocumentPropertiesViaDM.RetrievePropertiesUnderConfig( fullPath, currentConfig, GetDocumentPropertiesViaDM.PropertyNamesOftenUsed, true); } this.ResultsAtPopulating.Enqueue(root); this.CallbackGettingExtraInfo?.Invoke(ref root); Debug.WriteLine(string.Format("GetTopDocumentInfo:got [{0}]", fullPath)); }); this.AllWalkingTasks.Enqueue(new ComponentAndTask_Assembly() { ParentId = -1, TheTask = task, FullPath = fullPath, Id = root.Id }); return(root.Id); }
private void CopyFromPreviousSubAssembly(ComponentAndTask_Assembly assemblyComponentAndTask, int newLevel, int newParentId) { if (assemblyComponentAndTask == null || assemblyComponentAndTask.Id <= 0) { Debug.WriteLine(string.Format("CopyFromPreviousSubAssembly: invalid parameter")); return; } assemblyComponentAndTask.TheTask.Wait(); SldDMComponentItem theAssemblyInfo = this.ResultsAtPopulating.FirstOrDefault(x => x.Id == assemblyComponentAndTask.Id); if (theAssemblyInfo == null) { Debug.WriteLine(string.Format("CopyFromPreviousSubAssembly: couldn't find sub assembly with Id={0}", assemblyComponentAndTask.Id)); return; } SldDMComponentItem me = SldDMComponentItem.Clone(theAssemblyInfo, newLevel, newParentId); this.ResultsAtPopulating.Enqueue(me); IEnumerable <ComponentAndTask> subComponentsAndTasks = this.AllWalkingTasks.Where(x => x.ParentId == assemblyComponentAndTask.Id); if (subComponentsAndTasks == null || subComponentsAndTasks.Count() <= 0) { return; } Task[] allSubTasks = subComponentsAndTasks.Select(x => x.TheTask).ToArray(); Task.WaitAll(allSubTasks); foreach (var v in subComponentsAndTasks) { if (v is ComponentAndTask_Assembly) { this.CopyFromPreviousSubAssembly(v as ComponentAndTask_Assembly, me.Level + 1, me.Id); } else { this.CopyFromPreviousPart(v as ComponentAndTask_Part, me.Level + 1, me.Id); } } }
private int GetCurrentComponentInfo( SwDMComponent9 currentComponent, string fullPath, int level, int parentId) { if (currentComponent == null || string.IsNullOrEmpty(fullPath) || level < 0 || parentId <= 0) { return(-1); } SldDMComponentItem item = SldDMComponentItem.GenerateTheNext(); Task task = Task.Factory.StartNew(() => { item.ParentId = parentId; item.Level = level; item.FullPath = fullPath; item.FeatureName = currentComponent.Name2; item.FeatureId = currentComponent.GetID(); item.IsSuppressed = currentComponent.IsSuppressed(); item.FileName2D = EngineeringDrawingFile.Get2DFileNameIfExisting(fullPath); item.Visible = !currentComponent.IsHidden(); try { SwDmDocumentOpenError openResult; SwDMDocument17 doc = currentComponent.GetDocument2(true, this.GlobalSearchOption, out openResult) as SwDMDocument17; if (doc == null || openResult != SwDmDocumentOpenError.swDmDocumentOpenErrorNone) { Debug.WriteLine(string.Format("GetCurrentComponentInfo:couldn't open {0},the return value is :{1}", fullPath, openResult.ToString())); return; } SwDMConfiguration14 config = doc.ConfigurationManager.GetConfigurationByName(currentComponent.ConfigurationName) as SwDMConfiguration14; if (File.Exists(fullPath)) { item.AllCustomProperties = GetDocumentPropertiesViaDM.RetrievePropertiesUnderConfig( fullPath, config, GetDocumentPropertiesViaDM.PropertyNamesOftenUsed, true); } item.ConfigurationCount = doc.ConfigurationManager.GetConfigurationCount(); item.ChildrenCount = doc.GetComponentCount(); this.ResultsAtPopulating.Enqueue(item); doc.CloseDoc(); Marshal.ReleaseComObject(doc); } catch (Exception ex) { Debug.WriteLine(string.Format("GetCurrentComponentInfo:when dealing {0}, exception occurred:{1}", fullPath, ex.Message)); return; } this.CallbackGettingExtraInfo?.Invoke(ref item); Debug.WriteLine(string.Format("GetCurrentComponentInfo:got [{0}] (ID={1})", fullPath, item.Id)); }); string originalExt; SwDmDocumentType docType = SldFileExtentionChecker.CheckDM(fullPath, out originalExt); if (docType == SwDmDocumentType.swDmDocumentAssembly) { this.AllWalkingTasks.Enqueue(new ComponentAndTask_Assembly() { ParentId = parentId, TheTask = task, FullPath = fullPath, Id = item.Id }); } else { this.AllWalkingTasks.Enqueue(new ComponentAndTask_Part() { ParentId = parentId, TheTask = task, FullPath = fullPath, Id = item.Id }); } return(item.Id); }