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); }
private ComponentInfo Add_BodyInfo_In_Component(IPart7 Part, IBody7 _body, ComponentInfo componentInfo) { ComponentInfo componentInfo_Copy = (ComponentInfo)componentInfo.Clone(); componentInfo_Copy.Body = GetParamBody(_body); double kolvo = Convert.ToDouble(GetPropertyBodyIPart7(Part, _body, "Количество")); if (kolvo == 0) { componentInfo_Copy.Body.QNT = 1; componentInfo_Copy.Body.QNT_False = true; } else { componentInfo_Copy.Body.QNT = kolvo; componentInfo_Copy.Body.QNT_False = false; } componentInfo_Copy.Key = Part.FileName + "|" + Part.Marking + "|" + _body.Marking; Dictionary <string, string> ParamValueList = new Dictionary <string, string>(); foreach (string ParamName in FindParam_Model) { string ParamValue = null; ParamValue = OptionsFold.tools_class.FixInvalidChars_St(GetPropertyBodyIPart7(Part, _body, ParamName), ""); if (Split_Naim && ParamName == "Наименование") { ParamValue = OptionsFold.tools_class.SplitString(ParamValue); } ParamValueList.Add(ParamName, ParamValue); } componentInfo_Copy.Body.ParamValueList = ParamValueList; return(componentInfo_Copy); }
public static bool IsSheetMetal(IPart7 Part, out bool NoSheetMetal) //проверка на листовой материал { bool isOpen; NoSheetMetal = false; ISheetMetalContainer _ISheetMetalContainer = (ISheetMetalContainer)Part; if (_ISheetMetalContainer != null) { ISheetMetalBodies _ISheetMetalBodies = _ISheetMetalContainer.SheetMetalBodies; if (_ISheetMetalBodies != null) { if (_ISheetMetalBodies.Count > 0) { return(true); } else { VariableTable _VariableTable = Part.VariableTable; if (_VariableTable != null) { if (isVaribale(Part, true)) { return(true); } } } } } return(false); }
public static bool isVaribale(IPart7 part_, bool inSource = true) { bool res = false; if (part_ != null) { IFeature7 IF = (IFeature7)part_; Object[] ars = null; if (IF != null && IF.VariablesCount[false, inSource] > 0) { try { ars = IF.Variables[false, inSource]; } catch (Exception exc) { } } if (ars != null) { foreach (var v in ars) { string Expression = (v as IVariable7).Expression; if ((v as IVariable7).Name == "SM_Thickness") { res = true; break; } } } } return(res); }
public static bool GetValueProperty(IPart7 part, IProperty Property, out object returnObject) { bool res = false; returnObject = null; if (Property != null) { IPropertyKeeper Prop = (IPropertyKeeper)part; if (Prop != null) { bool Baseunit, FromSource; Baseunit = false; _Property classresProperty = (_Property)Property; if (classresProperty != null) { Prop.GetPropertyValue((_Property)classresProperty, out returnObject, Baseunit, out FromSource); if (returnObject != null) { res = true; } } } } return(res); }
public string[] GetMaterialModel(string pathModel) // получить материал из модели { string strMaterial = ""; IPart7 part = GetPart7(pathModel); if (part == null) { return(null); } strMaterial = part.Material; string[] ArrStr = strMaterial.Split(';'); int KolStr = ArrStr.Length; if (KolStr == 2) { ArrStr[0] = ArrStr[0].Replace("$d", " "); ArrStr[0] = ArrStr[0].Trim(); ArrStr[1] = ArrStr[1].Replace("$", ""); ArrStr[1] = ArrStr[1].Trim(); } return(ArrStr); }
private void getBodyResoure(IPart7 Part, ComponentInfo componentInfo, TreeListNode node) { IFeature7 feature = (IFeature7)Part; var RB = feature.ResultBodies; if (RB == null) { return; } try { foreach (IBody7 _body in RB) { try { ComponentInfo componentInfo_Copy = Add_BodyInfo_In_Component(Part, _body, componentInfo); TreeListNode TempNode; TempNode = AddNode(node, componentInfo_Copy, true); TempNode.Tag = componentInfo_Copy; } catch { } } } catch { IBody7 _body = (IBody7)RB; ComponentInfo componentInfo_Copy = Add_BodyInfo_In_Component(Part, _body, componentInfo); TreeListNode TempNode; TempNode = AddNode(node, componentInfo_Copy, true); TempNode.Tag = componentInfo_Copy; } }
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 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 static double GetThickBeVarible(IPart7 part_, bool inSource = true) { double res = 0; if (part_ != null) { IFeature7 IF = (IFeature7)part_; Object[] ars = null; if (IF != null && IF.VariablesCount[false, inSource] > 0) { ars = IF.Variables[false, inSource]; } if (ars != null) { foreach (var v in ars) { string Expression = (v as IVariable7).Expression; if ((v as IVariable7).Name == "SM_Thickness") { res = Convert.ToDouble((v as IVariable7).Value); break; } } } } return(res); }
public static double GetThicknessPart(IPart7 Part_, bool inSource = true) //процедура возвращает значение толщины ЛТ { try { ISheetMetalContainer pSheetMetalContainer = (ISheetMetalContainer)Part_; ISheetMetalBodies pSheetMetalBodies = pSheetMetalContainer.SheetMetalBodies; if (pSheetMetalBodies.Count != 0) { ISheetMetalBody pSheetMetalBody = pSheetMetalBodies.SheetMetalBody[0]; return(pSheetMetalBody.Thickness); } else { if (AppVersNOTValid) { return(GetThickBeVarible(Part_, true)); /*если версия компаса не валидна*/ } if (pSheetMetalContainer.SheetMetalRuledShells.Count != 0) { ISheetMetalBody obech = pSheetMetalContainer.SheetMetalRuledShells.SheetMetalBody[0]; return(obech.Thickness); } } } catch { } return(-1); }
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 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 double GetMassModel(string pathModel) // получить массу из модели (не удалось код -1) { double MassModel = 0; IPart7 part = GetPart7(pathModel); if (part == null) { return(-1); } MassModel = part.Mass / 1000; // масса в кг return(MassModel); }
private List <string> GetPartList(IPart7 Parent_Assembly) { List <string> PartList = new List <string>(); var Parts = Parent_Assembly.Parts; foreach (IPart7 item in Parts) { try { if (item.Hidden != true) { PartList.Add(item.FileName + "|" + item.Marking); } } catch { } } return(PartList); }
public void Recource(IPart7 TopPart, TreeListNode node) //процедура перебирает компоненты в сборке { if (TopPart != null) { if (!TopPart.Detail) { getBodyResoure(TopPart, (ComponentInfo)node.Tag, node); } var Parts = TopPart.PartsEx[1]; if (Parts != null) { foreach (IPart7 item in Parts) { try { if (item.Hidden != true) { ComponentInfo componentInfo = GetParam(item); AddWaitStatus(Path.GetFileNameWithoutExtension(componentInfo.FFN)); if (!componentInfo.QNT_False) { componentInfo.QNT = GetQNTIn_PartsList(item.FileName + "|" + item.Marking, GetPartList(TopPart)); } try { componentInfo.ParamValueList["Количество"] = componentInfo.QNT.ToString(); } catch { } TreeListNode TempNode; TempNode = AddNode(node, componentInfo, false); TempNode.Tag = componentInfo; //getBodyResoure(item, componentInfo, TempNode); if (!item.Detail && All_Level_Search) { Recource(item, TempNode); } } } catch (Exception Ex) { ShowMsgBox("Ошибка при обработке компонента " + item.FileName + Environment.NewLine + Ex.Message, MessageBoxIcon.Error); } } } } }
public static bool GetHasFlatPattern(IPart7 part) { //процедура проверяет наличие развертки для данной детали //проверка на существование развертки в детали //если есть развертка - возвращает 1, если нет - - //для версии компас ниже 18, выдается ошибка и возвращается 1 if (!AppVersNOTValid) { return(true); } try { ISheetMetalContainer _ISheetMetalContainer = (ISheetMetalContainer)part; ISheetMetalBendUnfoldParameters _SheetMetalBendUnfoldParameters = _ISheetMetalContainer.SheetMetalBendUnfoldParameters; if (_SheetMetalBendUnfoldParameters != null) { if (_SheetMetalBendUnfoldParameters.IsCreated == false) { return(false); } else { return(true); } } else { return(false); } } catch (Exception Ex) { if (thisFirstMessage == true) { ShowMsgBox("Ошибка при проверке наличия развертки!" + Environment.NewLine + "Возможно вы используете версия Kompas ниже " + Body.KompasVersion + Environment.NewLine + "Во избежание ошибок при создании разверток, рекомендуем обновиться до версии" + Body.KompasVersion + Environment.NewLine + Ex.Message, MessageBoxIcon.Error); thisFirstMessage = false; } return(true); } }
private double GetQNTInParts(IPart7 Find_Item, IPart7 TopPart) { double QNT = 0; var Parts = TopPart.Parts; foreach (IPart7 item in Parts) { try { if (item.Hidden != true) { if (Find_Item.FileName + "|" + Find_Item.Marking == item.FileName + "|" + item.Marking) { QNT += 1; } } } catch {} } return(QNT); }
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()); }
private ComponentInfo GetParam(IPart7 part) { string ComponentKey = part.FileName + "|" + part.Marking; //FindModel_List ComponentInfo iMSH = GetExistNode_By_ComponentKey(ComponentKey); if (iMSH != null) { return(iMSH); } IMassInertiaParam7 massInertiaParam = (IMassInertiaParam7)part; massInertiaParam.Calculate(); massInertiaParam.LengthUnits = ksLengthUnitsEnum.ksLUnMM; massInertiaParam.MassUnits = ksMassUnitsEnum.ksMUnKG; iMSH = new ComponentInfo(); Dictionary <string, string> ParamValueList = new Dictionary <string, string>(); //iMSH.ParamValueList = FindParam_Model; foreach (string ParamName in FindParam_Model) { string ParamValue = ""; switch (ParamName) { case "Обозначение": ParamValue = OptionsFold.tools_class.FixInvalidChars_St(part.Marking, ""); break; case "Имя файла": ParamValue = System.IO.Path.GetFileNameWithoutExtension(part.FileName); break; case "Наименование": ParamValue = OptionsFold.tools_class.FixInvalidChars_St(part.Name, ""); if (Split_Naim) { ParamValue = OptionsFold.tools_class.SplitString(ParamValue); } break; case "Масса": ParamValue = OptionsFold.tools_class.FixInvalidChars_St(Math.Round(part.Mass, 3).ToString(), ""); break; case "Материал": ParamValue = OptionsFold.tools_class.FixInvalidChars_St(part.Material, ""); break; case "Толщина": ParamValue = Convert.ToString(GetThicknessPart(part, true)); break; case "Количество": ParamValue = OptionsFold.tools_class.FixInvalidChars_St(GetPropertyIPart7(part, ParamName), ""); if (string.IsNullOrEmpty(ParamValue)) { ParamValue = "1"; } break; case "Количество общ.": //ParamValue = OptionsFold.tools_class.FixInvalidChars_St(GetPropertyIPart7(part, ParamName), ""); //if (string.IsNullOrEmpty(ParamValue)) ParamValue = "1"; break; case "Площадь": ParamValue = Math.Round(massInertiaParam.Area, 3).ToString(); break; case "Объем": ParamValue = Math.Round(massInertiaParam.Volume, 3).ToString(); break; case "Xc": ParamValue = massInertiaParam.Xc.ToString(); break; case "Yc": ParamValue = massInertiaParam.Yc.ToString(); break; case "Zc": ParamValue = massInertiaParam.Zc.ToString(); break; case "Полное имя файла": ParamValue = part.FileName; break; //case "Наличие развертки": // if (GetHasFlatPattern(part)) // ParamValue = "1"; // else // ParamValue = "-1"; // break; default: ParamValue = OptionsFold.tools_class.FixInvalidChars_St(GetPropertyIPart7(part, ParamName), ""); //ParamValue = OptionsFold.tools_class.FixInvalidChars_St(GetPropertyIPart7(part, ParamName), ""); break; } ParamValueList.Add(ParamName, ParamValue); } iMSH.ParamValueList = ParamValueList; double Kolvo = Convert.ToDouble(GetPropertyIPart7(part, "Количество")); if (Kolvo == 1 || Kolvo == 0) { iMSH.QNT = 1; iMSH.QNT_False = false; } else { iMSH.QNT = Kolvo; iMSH.QNT_False = true; } iMSH.Oboz = part.Marking; iMSH.Mass = part.Mass; iMSH.Naim = part.Name; iMSH._MCH.Xc = massInertiaParam.Xc; iMSH._MCH.Yc = massInertiaParam.Yc; iMSH._MCH.Zc = massInertiaParam.Zc; iMSH._MCH.Area = massInertiaParam.Area; iMSH._MCH.Volume = massInertiaParam.Volume; iMSH.FFN = part.FileName; iMSH.material = part.Material; bool isSHeetmetall = false; iMSH.SheeMetall = IsSheetMetal(part, out isSHeetmetall); iMSH.HaveUnfold = GetHasFlatPattern(part); iMSH.isDetal = part.Detail; iMSH.standardComponent = part.Standard; iMSH.Key = ComponentKey; return(iMSH); }