public static void GetEquationValueByName(ModelDoc2 Part, string VariableName, ref object Value) { /// <summary> /// 获取方程式中全局变量的值,Golbal Variables /// </summary> /// <param name="VariableName">全局变量的名称</param> /// <param name="Part">模型</param> /// <returns>如果没有找到这个全局变量,返回-1</returns> EquationMgr emgr = (EquationMgr)Part.GetEquationMgr(); int ic = emgr.GetCount(); for (int i = 0; i < ic; i++) { string s = emgr.get_Equation(i); s = s.Replace("\"", ""); s = s.Remove(s.IndexOf('=')); s = s.Trim(); if (s.ToLower() == VariableName.ToLower()) { Value = emgr.get_Value(i); return; } } Value = -1; }
public void Load() { this.swDoc = OpenSWDoc(this.FilePath); #region 00. 获取方程式的值 Sizes.Clear(); EquationMgr emgr = (EquationMgr)swDoc.GetEquationMgr(); int ic = emgr.GetCount(); for (int i = 0; i < ic; i++) { //在这里想办法只获取全局变量 string s = emgr.get_Equation(i); if (s.Contains("@")) { continue; } s = s.Replace("\"", ""); s = s.Remove(s.IndexOf('=')); s = s.Trim(); s = s.ToUpper(); object v = emgr.get_Value(i); if (Sizes.ContainsKey(s)) { Sizes[s] = v; } else { Sizes.Add(s, v); } } _Sizes = new Dictionary <string, object>(Sizes); #endregion #region 10. 获取零部件属性的值 Attrs.Clear(); object[] PropNames; string cfgname2 = swDoc.ConfigurationManager.ActiveConfiguration.Name; CustomPropertyManager cpmMdl = swDoc.Extension.get_CustomPropertyManager(cfgname2); if (cpmMdl.Count > 0) { PropNames = (object[])cpmMdl.GetNames(); string outval = ""; string sovVal = ""; foreach (object AtrName in PropNames) { string s = AtrName.ToString(); cpmMdl.Get2(AtrName.ToString(), out outval, out sovVal); if (Attrs.ContainsKey(s)) { Attrs[s] = sovVal; } else { Attrs.Add(s, sovVal); } } } _Attrs = new Dictionary <string, string>(Attrs); #endregion }
/// <summary> /// 获取方程式中全局变量的值,Golbal Variables /// </summary> /// <param name="VariableName">全局变量的名称</param> /// <param name="Part">模型</param> /// <returns>如果没有找到这个全局变量,返回-1</returns> public double getGolbalVariablesValue(string VariableName, ModelDoc2 Part) { EquationMgr emgr = (EquationMgr)Part.GetEquationMgr(); int ic = emgr.GetCount(); for (int i = 0; i < ic; i++) { string s = emgr.get_Equation(i); s = s.Replace("\"", ""); s = s.Remove(s.IndexOf('=')); s = s.Trim(); if (s.ToLower() == VariableName.ToLower()) { return(emgr.get_Value(i)); } } return(-1); }
public override Dictionary <string, string> initPartParamNameUnit() { for (int i = 0; i < m_partParams.GetCount(); i++) { if (m_partParams.get_GlobalVariable(i)) { string equation = m_partParams.get_Equation(i); string name = equation.Substring(1, equation.IndexOf('=') - 2); string value = equation.Substring(equation.IndexOf('=') + 2); //Console.WriteLine(name); //Console.WriteLine(value); nameIndexPair.Add(name, i); string unit = getUnit(value); //Console.WriteLine(unit); nameUnitPair.Add(name, unit); } } return(nameUnitPair); }
public static bool setGolbalVariablesValue(string VariableName, ModelDoc2 Part, string Value) { EquationMgr emgr = (EquationMgr)Part.GetEquationMgr(); int ic = emgr.GetCount(); for (int i = 0; i < ic; i++) { string s = emgr.get_Equation(i); s = s.Replace("\"", ""); s = s.Remove(s.IndexOf('=')); s = s.Trim(); if (s.ToLower() == VariableName.ToLower()) { emgr.set_Equation(i, Value); return(true); } } return(false); }
private void OpenDoc(string _FilePath) { this.FilePath = _FilePath; swDoc = OpenSWDoc(_FilePath); #region 00. 获取方程式的值 Sizes.Clear(); EquationMgr emgr = (EquationMgr)swDoc.GetEquationMgr(); int ic = emgr.GetCount(); for (int i = 0; i < ic; i++) { //在这里想办法只获取全局变量 string s = emgr.get_Equation(i); if (s.Contains("@")) { continue; } s = s.Replace("\"", ""); s = s.Remove(s.IndexOf('=')); s = s.Trim(); s = s.ToUpper(); object v = emgr.get_Value(i); if (Sizes.ContainsKey(s)) { Sizes[s] = v; } else { Sizes.Add(s, v); } } _Sizes = new Dictionary <string, object>(Sizes); #endregion #region 10. 获取零部件属性的值 Attrs.Clear(); _Attrs = new Dictionary <string, string>(Attrs); #endregion //CloseDoc(); }
public void Commit() { #region 00. 提交尺寸 EquationMgr emgr = (EquationMgr)swDoc.GetEquationMgr(); int ic = emgr.GetCount(); for (int i = 0; i < ic; i++) { //在这里想办法只获取全局变量 string s = emgr.get_Equation(i); if (s.Contains("@")) { continue; } s = s.Replace("\"", ""); s = s.Remove(s.IndexOf('=')); s = s.Trim(); s = s.ToUpper(); if (Sizes.ContainsKey(s)) { if (Sizes[s] != _Sizes[s]) { string Equation = JswFunc.FormatEquation(s, Sizes[s].ToString()); emgr.set_Equation(i, Equation); } } else { if (_Sizes.ContainsKey(s)) { emgr.Delete(i); i--; ic--; } } } //foreach (string key in Sizes.Keys) //{ // if (Sizes[key] != _Sizes[key]) // { // JswFunc.SetEquationValueByName(swDoc, key, Sizes[key]); // } //} _Sizes = new Dictionary <string, object>(Sizes); #endregion #region 10. 提交属性 string cfgname2 = swDoc.ConfigurationManager.ActiveConfiguration.Name; CustomPropertyManager cpmMdl = swDoc.Extension.get_CustomPropertyManager(cfgname2); //修改属性 foreach (string key in Attrs.Keys) { if (_Attrs.ContainsKey(key)) { if (Attrs[key] != _Attrs[key]) { cpmMdl.Set(key, Attrs[key]); } } else { //如果该Key在_Attrs中找不到,表示为新增的属性 int outval = 30; string sovVal = ""; // cpmMdl.Set(AtrName, Value); cpmMdl.Add2(key, outval, Attrs[key]); } } //清理已经删除的属性 foreach (string key in _Attrs.Keys) { if (!Attrs.ContainsKey(key)) { //旧属性不在新列表中,表示该属性已被删除。 cpmMdl.Delete(key); } } _Attrs = new Dictionary <string, string>(Attrs); #endregion }