/// <summary> /// Called when the reset button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ResetButton_Click(object sender, RoutedEventArgs e) { var model = SolidWorksEnvironment.Application.ActiveModel; var model2 = (ModelDoc2)SolidWorksEnvironment.Application.UnsafeObject.ActiveDoc; ModelDocExtension extension = model2.Extension; CustomPropertyManager propertyManager = default(CustomPropertyManager); propertyManager = extension.get_CustomPropertyManager(""); // Remove feature tolerances manually // since there is a variable number of them model.CustomProperties((properties) => { // Find all feature-tolerance custom properties List <CustomProperty> found = properties.FindAll(property => property.Name.Contains(CustomPropertyFeatureTolerance)); // Delete each one foreach (CustomProperty item in found) { propertyManager.Delete(item.Name); } }); mFeatureTolerances.Clear(); FeatureTolerance_Display.Items.Refresh(); RawMaterialList.SelectedIndex = -1; NoteGrid.Children.Clear(); AddNewNote(); }
/// <summary> /// Called when the apply button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ApplyButton_Click(object sender, RoutedEventArgs e) { var model = SolidWorksEnvironment.Application.ActiveModel; var model2 = (ModelDoc2)SolidWorksEnvironment.Application.UnsafeObject.ActiveDoc; ModelDocExtension extension = model2.Extension; CustomPropertyManager propertyManager = default(CustomPropertyManager); propertyManager = extension.get_CustomPropertyManager(""); // Check if we have a part if (model == null || !model.IsPart) { return; } // Notes // First clear the existing note custom properties model.CustomProperties((properties) => { List <CustomProperty> found = properties.FindAll(property => property.Name.Contains(CustomPropertyNote)); foreach (CustomProperty item in found) { propertyManager.Delete(item.Name); } }); int j = 1; foreach (var child in NoteGrid.Children) { if (child.GetType() == typeof(System.Windows.Controls.TextBox)) { model.SetCustomProperty(CustomPropertyNote + " " + j.ToString(), ((System.Windows.Controls.TextBox)child).Text); j++; } } // Feature Tolerances for (int i = 0; i < mFeatureTolerances.Count; i++) { FeatureToleranceObject item = mFeatureTolerances.ElementAt(i); string CustomPropertyName = CustomPropertyFeatureTolerance + item.FeatureName; model.SetCustomProperty(CustomPropertyName, item.FeatureTolerance); } // If user does not have a material selected, clear it if (RawMaterialList.SelectedIndex < 0) { model.SetMaterial(null); } // Otherwise set the material to the selected one else { model.SetMaterial((Material)RawMaterialList.SelectedItem); } // Re-read details to confirm they are correct ReadDetails(); }
public static string DelAttValueByName(string AtrName, ModelDoc2 swModel, string Value) { string cfgname2 = swModel.ConfigurationManager.ActiveConfiguration.Name; CustomPropertyManager cpmMdl = swModel.Extension.get_CustomPropertyManager(cfgname2); int outval = 30; string sovVal = ""; // cpmMdl.Set(AtrName, Value); cpmMdl.Delete(AtrName); return(sovVal); }
private void InserirPropriedade(Coletor c) { string descricao = ""; descricao += "COL S "; descricao += c.DiametroTuboAcoColetor + "\" "; descricao += c.QuantidadeCompressor + "CP "; descricao += c.DiametroSuccaoCompressor + "\" X "; descricao += c.DiametroSuccaoRack + "\" "; swModel = swApp.ActiveDoc; ConfigurationManager configMgr; configMgr = swModel.ConfigurationManager; Configuration config = configMgr.ActiveConfiguration; string nomeConfig = config.Name; swExt = swModel.Extension; // Deleta prop da custom swCustomMgr = swExt.CustomPropertyManager[""]; string[] nomesProp = null; nomesProp = (string[])swCustomMgr.GetNames(); foreach (var nome in nomesProp) { swCustomMgr.Delete(nome); } // Deleta prop da personalizada swCustomMgr = swExt.CustomPropertyManager[nomeConfig]; nomesProp = null; nomesProp = (string[])swCustomMgr.GetNames(); foreach (var nome in nomesProp) { swCustomMgr.Delete(nome); } swCustomMgr.Add3("DESCRIÇÃO", (int)swCustomInfoType_e.swCustomInfoText, descricao, (int)swCustomPropertyAddOption_e.swCustomPropertyReplaceValue); swCustomMgr.Add3("PROJETISTA", (int)swCustomInfoType_e.swCustomInfoText, "RICARDO R.", (int)swCustomPropertyAddOption_e.swCustomPropertyReplaceValue); swCustomMgr.Add3("PROJETISTA2D", (int)swCustomInfoType_e.swCustomInfoText, "RICARDO R.", (int)swCustomPropertyAddOption_e.swCustomPropertyReplaceValue); swCustomMgr.Add3("GRUPO ITEM", (int)swCustomInfoType_e.swCustomInfoText, "494", (int)swCustomPropertyAddOption_e.swCustomPropertyReplaceValue); swCustomMgr.Add3("REVISÃO", (int)swCustomInfoType_e.swCustomInfoText, "01", (int)swCustomPropertyAddOption_e.swCustomPropertyReplaceValue); }
internal static bool DeleteCustomProperty(CustomPropertyManager customPropertyManager, string CustomProperty) { //get custom property value var Val = customPropertyManager.Get(CustomProperty); //check if custom Property exists if (!string.IsNullOrEmpty(CustomProperty)) { int ret = customPropertyManager.Delete(CustomProperty); if (ret == 0) { return(true); } else { return(false); } } 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 }