public override void setDimsNum(Dictionary <string, double> nameDimsPair) { foreach (KeyValuePair <string, double> kvp in nameDimsPair) { string unit = ""; if (nameUnitPair[kvp.Key] != "unitless") { unit = nameUnitPair[kvp.Key]; } string equation = "\"" + kvp.Key + "\"=" + kvp.Value.ToString() + unit; m_partParams.set_Equation(nameIndexPair[kvp.Key], equation); } m_partInstance.SaveSilent(); }
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); }
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 }