public string GetPropertyIPart7(IPart7 part_, string PropertyName) { IKompasDocument3D _IKompasDocument3D = (IKompasDocument3D)GetIKompasDocument(part_.FileName, false, false); if (_IApplication != null) { IPropertyMng _IPropertyMng = (IPropertyMng)_IApplication; if (_IPropertyMng != null) { int count = _IPropertyMng.PropertyCount[_IKompasDocument3D]; for (int i = 0; i < count; i++) { IProperty Property = _IPropertyMng.GetProperty(_IKompasDocument3D, i); if (PropertyName == Property.Name) { object returnObject; if (GetValueProperty(part_, Property, out returnObject)) { if (returnObject.GetType().Name == "Double") { returnObject = Math.Round(Convert.ToDouble(returnObject), 3); } if (!string.IsNullOrEmpty(returnObject.ToString())) { return(returnObject.ToString()); } } break; } } } } return(GetVaribleValByName(part_, PropertyName)); }
public string GetVaribleValByName(IPart7 part_, string PropertyName) { string res = ""; try { IKompasDocument3D _IKompasDocument3D = (IKompasDocument3D)GetIKompasDocument(part_.FileName, false, false); part_ = _IKompasDocument3D.TopPart; if (part_ != null) { IFeature7 IF = (IFeature7)part_; Object[] ars = null; if (IF != null && IF.VariablesCount[false, true] > 0) { ars = IF.Variables[false, true]; } if (ars != null) { foreach (var v in ars) { string Expression = (v as IVariable7).Expression; if ((v as IVariable7).Name == PropertyName) { res = (v as IVariable7).Value.ToString(); break; } } } } } catch { ShowMsgBox($"Ошибка при обработке компонента {part_.FileName}\nНе удалось найти Переменную {PropertyName} в списке переменных!", MessageBoxIcon.Error); } return(res); }
public void OpenThisDocument() { if (!AppVersNOTValidStrongMessage()) { return; } if ((_IApplication.ActiveDocument is IKompasDocument3D) != true) { return; } IKompasDocument3D _IKompasDocument = (IKompasDocument3D)_IApplication.ActiveDocument; IPart7 TopPart = _IKompasDocument.TopPart; if (TopPart == null) { IPart7NothingMsg(_IKompasDocument.Path); return; } CheckMainControl(); treeView.Nodes.Clear(); TreeListNode node = treeView.Nodes.Add(); if (node.Tag == null) { node.Tag = GetParam(TopPart); AddCellsInNode(node, (ComponentInfo)node.Tag); } Recource(TopPart, node); node.ExpandAll(); CloseDocs(); }
public IPart7 GetPart7(string pathModel) // открыть модель и получить интерфейс IPart7 по пути к модели { IDocuments docs7 = TestKompas7(); if (docs7 == null) { //MessageBox.Show("Не удалось подключить интерфейс Компас.IDocuments."); return(null); } if (!File.Exists(pathModel)) { //MessageBox.Show("Не удалось найти файл " + Path.GetFileName(pathModel) + "."); return(null); } IKompasDocument3D doc = (IKompasDocument3D)docs7.Open(pathModel, true, false); if (doc == null) { //MessageBox.Show("Не удалось открыть докумемент."); return(null); } doc.Active = true; IPart7 part = doc.TopPart; if (part == null) { //MessageBox.Show("Не удалось подключить интерфейс Компас.IPart7."); return(null); } return(part); }
public bool ClosePart(IPart7 part) // закрыть модель { IDocuments docs7 = TestKompas7(); IKompasDocument3D doc = (IKompasDocument3D)docs7.Open(part.FileName, true, false); doc.Active = true; if (doc == null) { return(false); } return(doc.Close(DocumentCloseOptions.kdSaveChanges)); }
public void OpenThisDocument(string FFN) { if (!AppVersNOTValidStrongMessage()) { return; } CheckMainControl(); treeView.Nodes.Clear(); try { TreeListNode node; IKompasDocument3D _IKompasDocument = (IKompasDocument3D)_IApplication.Documents.Open(FFN, false, true); IPart7 TopPart = _IKompasDocument.TopPart; if (TopPart == null) { IPart7NothingMsg(FFN); return; } int currentEmbody = 0; IEmbodimentsManager _IEmbodimentsManager = (IEmbodimentsManager)TopPart; int EmbodyCount = _IEmbodimentsManager.EmbodimentCount; for (int j = 0; j < EmbodyCount; j++) { Embodiment tmp_Embodiment; tmp_Embodiment = _IEmbodimentsManager.Embodiment[j]; if (tmp_Embodiment.IsCurrent == true) { currentEmbody = j; } tmp_Embodiment.IsCurrent = true; node = treeView.Nodes.Add(); if (node.Tag == null) { if (tmp_Embodiment.Part == null) { IPart7NothingMsg(FFN); return; } node.Tag = GetParam(tmp_Embodiment.Part); AddCellsInNode(node, (ComponentInfo)node.Tag); } Recource(tmp_Embodiment.Part, node); node.ExpandAll(); } _IEmbodimentsManager.Embodiment[currentEmbody].IsCurrent = true; //_IKompasDocument.Close(DocumentCloseOptions.kdDoNotSaveChanges); CloseDocs(); } catch { } }
public string GetPropertyBodyIPart7(IPart7 part_, IBody7 Body, string PropertyName) { object res = ""; IKompasDocument3D _IKompasDocument3D = (IKompasDocument3D)GetIKompasDocument(part_.FileName, false, false); if (_IApplication != null) { IPropertyMng _IPropertyMng = (IPropertyMng)_IApplication; if (_IPropertyMng != null) { bool Baseunit, FromSource; Baseunit = false; IPropertyKeeper propertyKeeper = (IPropertyKeeper)Body; if (propertyKeeper != null) { IProperty Property = _IPropertyMng.GetProperty(_IKompasDocument3D, PropertyName); if (Property != null) { propertyKeeper.GetPropertyValue((_Property)Property, out res, Baseunit, out FromSource); } } } } if (res != null) { if (res.GetType().Name == "Double") { res = Math.Round(Convert.ToDouble(res), 3); } } else { return(null); } return(res.ToString()); }