public static void WriteCusp(ModelDoc2 Doc) { CustomPropertyManager SwCusp = Doc.Extension.CustomPropertyManager[""]; string PartName = "长方体 \"D2@草图2@Solidworks属性学习.SLDPRT\"X\"D1@草图2@Solidworks属性学习.SLDPRT\"X\"D1@凸台-拉伸1@Solidworks属性学习.SLDPRT\""; SwCusp.Add3("零件名", (int)swCustomInfoType_e.swCustomInfoText, PartName, (int)swCustomPropertyAddOption_e.swCustomPropertyReplaceValue); SwCusp.Add3("代号", (int)swCustomInfoType_e.swCustomInfoText, "001", (int)swCustomPropertyAddOption_e.swCustomPropertyReplaceValue); SwCusp.Add3("重量", (int)swCustomInfoType_e.swCustomInfoText, "\"SW-质量@Solidworks属性学习.SLDPRT\"", (int)swCustomPropertyAddOption_e.swCustomPropertyReplaceValue); SwCusp.Add3("材料", (int)swCustomInfoType_e.swCustomInfoText, "\"SW-材质@Solidworks属性学习.SLDPRT\"", (int)swCustomPropertyAddOption_e.swCustomPropertyReplaceValue); System.Windows.MessageBox.Show("属性写入成功!"); }
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); }
/// <summary> /// Метод добавляет свойство в соответствующую конфигурацию /// объекта и в ModelDoc2 /// </summary> /// <param name="nameConfig"></param> /// <param name="prop"></param> /// <returns></returns> public int Add(string nameConfig, SwProperty prop) { if (prop == null) { throw new System.ArgumentNullException(nameof(prop)); } if (!_ConfigPropertys.ContainsKey(nameConfig)) { throw new KeyNotFoundException(nameof(prop)); } // Выбираем исполнение в котором собираемся менять свойства _customPropManager = SwModel.Extension.CustomPropertyManager[nameConfig]; //Если свойство уже имеется в списке // изменить его значение Value, иначе добавить в список. if (_ConfigPropertys[nameConfig].Contains(prop)) { _ConfigPropertys[nameConfig].First(x => x.Name == prop.Name).Value = prop.Value; } else { _ConfigPropertys[nameConfig].Add(prop); } //Добавляем свойство в модель SolidWorks return(_customPropManager.Add3(prop.Name, (int)swCustomInfoType_e.swCustomInfoText, prop.Value, (int)swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)); }
public override void Write(ModelDoc2 md) { if (md != null) { Configuration cf = md.ConfigurationManager.ActiveConfiguration; CustomPropertyManager gcpm = md.Extension.get_CustomPropertyManager(string.Empty); CustomPropertyManager scpm = md.Extension.get_CustomPropertyManager(string.Empty); if (SWCustPropMgr != null) { scpm = SWCustPropMgr; } // Null reference on drawings. Not good. Let's just make everything global if there's no config. if (cf != null) { scpm = md.Extension.get_CustomPropertyManager(cf.Name); } // Rather than changing values, we'll just completely overwrite them. swCustomPropertyAddOption_e ao = swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd; int res; string v = ID; res = gcpm.Add3(this.Name, (int)swCustomInfoType_e.swCustomInfoNumber, v, (int)ao); } //base.Write(md); }
/// <summary> /// Удаляет свойства, если они не в своей категории /// </summary> public static void FixPropertys() { string ValOut; string ResValOut; bool WasResolved; cust = swModel.Extension.CustomPropertyManager[""]; cust2 = swModel.Extension.CustomPropertyManager[EditProp.configuracione]; cust.Delete2("Обозначение"); cust.Delete2("Наименование"); cust.Delete2("Наименование_ФБ"); cust.Delete2("Number"); cust.Delete2("RenameSWP"); cust.Delete2("DescriptionEng"); cust.Delete2("Сборка"); cust.Delete2("Примечание"); cust.Delete2("Формат"); cust.Delete2("DrawnBy"); cust2.Get5("Проверил", true, out ValOut, out ResValOut, out WasResolved); Propertiy.ChechedBy = ResValOut; cust2.Delete2("Проверил"); cust.Add3("Проверил", 30, Propertiy.ChechedBy, (int)swCustomPropertyAddOption_e.swCustomPropertyOnlyIfNew); cust2.Get5("Утвердил", true, out ValOut, out ResValOut, out WasResolved); Propertiy.ApprovedBy = ResValOut; cust2.Delete2("Утвердил"); cust.Add3("Утвердил", 30, ResValOut, (int)swCustomPropertyAddOption_e.swCustomPropertyOnlyIfNew); cust2.Get5("Техконтроль", true, out ValOut, out ResValOut, out WasResolved); Propertiy.TControl = ResValOut; cust2.Delete2("Техконтроль"); cust.Add3("Техконтроль", 30, ResValOut, (int)swCustomPropertyAddOption_e.swCustomPropertyOnlyIfNew); cust2.Get5("Масса_Таблица", true, out ValOut, out ResValOut, out WasResolved); Propertiy.Weight = ResValOut; cust2.Delete2("Масса_Таблица"); cust2.Add3("Масса", 30, ResValOut, (int)swCustomPropertyAddOption_e.swCustomPropertyOnlyIfNew); cust2.Delete2("CheckedBy"); cust2.Delete2("EngineeringApproval"); swModel.ForceRebuild3(false); }
private void assignModelProperties() { //Activate the model document //asign custom property manager swModel = swApp.ActiveDoc; CusProMan = swModel.Extension.CustomPropertyManager[""]; //set the author name swModel.SummaryInfo[2] = CreatePart.txtAuthor; if (CreatePart.choforItemType == "Vendor") { if (CreatePart.exisCheck == 1) { //create different custom properties that are assigned to the document CusProMan.Add3("Vendor SKU", 30, CreatePart.txtVenSKU, 2); CusProMan.Add3("Vendor Name", 30, CreatePart.txtVendor, 2); CusProMan.Add3("Vendor Costs", 30, CreatePart.txtVenCost, 2); } else { swModel.SummaryInfo[0] = CreatePart.txtVenName; CusProMan.Add3("Vendor SKU", 30, CreatePart.txtVenSKU, 2); CusProMan.Add3("Vendor Name", 30, CreatePart.txtVendor, 0); CusProMan.Add3("Vendor Costs", 30, CreatePart.txtVenCost, 2); } } else { //set the name of the part swModel.SummaryInfo[0] = CreatePart.txtManName; } }
protected override void Command() { try { String NomProp = "Date"; CustomPropertyManager PM = MdlBase.eGestProp(""); if (MdlBase.ePropExiste(NomProp)) { PM.Add3(NomProp, (int)swCustomInfoType_e.swCustomInfoDate, DateTime.Today.ToString("d"), (int)swCustomPropertyAddOption_e.swCustomPropertyReplaceValue); } else { PM.Add3(NomProp, (int)swCustomInfoType_e.swCustomInfoDate, DateTime.Today.ToString("d"), (int)swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd); } MdlBase.EditRebuild3(); } catch (Exception e) { this.LogErreur(new Object[] { e }); } }
public void WriteCustomProp(DataRow dr) { string thisConfigName = (string)dr["configname"]; if (thisConfigName != "" && !configNames.Contains(thisConfigName)) { string strExcept = String.Format("Config name {0} is not in this model", thisConfigName); throw new Exception(strExcept); } CustomPropertyManager swCustPropMgr = (CustomPropertyManager)swModelDocExt.get_CustomPropertyManager(thisConfigName); // Get existing property names string[] nameArray = swCustPropMgr.GetNames(); List <string> propNames = new List <string>(); if (nameArray != null) { propNames.AddRange(swCustPropMgr.GetNames()); } // Check for a part number bool hasPartNum = dr["PartNum"].ToString() != ""; // So far, we always store custom properties as text (i.e. swCustomInfoType_e.swCustomInfoText) foreach (DataRow drField in propScaffold.FieldDefs.Select("sw_prop is not null")) { string propName = drField["sw_prop"].ToString(); string fieldName = drField["field"].ToString(); string typeName = drField["dt_type"].ToString(); if (CheckPropDefaultValue(dr[fieldName], typeName)) { // Remove the custom property swCustPropMgr.Delete2(propName); } else { // Add the custom property swCustPropMgr.Add3( propName, propScaffold.PropTypes[propName], dr[fieldName].ToString(), (int)swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd); } } swMainModel.SetSaveFlag(); }
private void AjouterInfos(ModelDoc2 Mdl) { try { if (!_ListeComp.Contains(Mdl.GetPathName()) && (ComposantsExterne || Mdl.eEstDansLeDossier(MdlBase))) { _ListeComp.Add(Mdl.GetPathName()); WindowLog.Ecrire(Mdl.eNomAvecExt()); CustomPropertyManager PM = Mdl.Extension.get_CustomPropertyManager(""); foreach (String k in _Dic.Keys) { PM.Add3(k, (int)swCustomInfoType_e.swCustomInfoText, _Dic[k], (int)swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd); } } } catch (Exception e) { this.LogMethode(new Object[] { e }); } }
private void m_createSWCustomPropertyButton_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; try { ModelDoc2 swModel = m_swApp.ActiveDoc; ModelDocExtension swModelDocExt = swModel.Extension; CustomPropertyManager swCustProp = swModelDocExt.CustomPropertyManager["Default"]; swCustProp.Add3(CustomPropertyName, ((int)swCustomInfoType_e.swCustomInfoText), CustomPropertyValue, ((int)swCustomPropertyAddOption_e.swCustomPropertyReplaceValue)); } catch { } finally { this.Cursor = Cursors.Default; } }
static void AddProperty(CustomPropertyManager propManger, KeyValuePair <string, string> propName) { propManger.Add3(propName.Key == "ERP code" ? "Код материала" : "Заготовка_" + propName.Key, (int)swCustomInfoType_e.swCustomInfoText, propName.Value, (int)swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd); }
public void Write2(ModelDoc2 md) { if (md != null && (!Old ^ (Properties.Settings.Default.Testing && Old))) { Configuration cf = md.ConfigurationManager.ActiveConfiguration; CustomPropertyManager gcpm = md.Extension.get_CustomPropertyManager(string.Empty); CustomPropertyManager scpm = md.Extension.get_CustomPropertyManager(string.Empty); if (SWCustPropMgr != null) { scpm = SWCustPropMgr; } // Null reference on drawings. Not good. Let's just make everything global if there's no config. if (cf != null) { scpm = md.Extension.get_CustomPropertyManager(cf.Name); } // Rather than changing values, we'll just completely overwrite them. swCustomPropertyAddOption_e ao = swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd; // This is for checking if the writing actually happened. It usually does. Don't know what I'd do if it didn't. int res; switch (Type) { case swCustomInfoType_e.swCustomInfoDate: res = gcpm.Add3(Name, (int)Type, Value, (int)ao); break; case swCustomInfoType_e.swCustomInfoDouble: res = gcpm.Add3(Name, (int)Type, Value, (int)ao); break; case swCustomInfoType_e.swCustomInfoNumber: if (Global) { if (Name.ToUpper().Contains("BLANK") || Name.ToUpper().Contains("CRC")) { res = gcpm.Add3(Name, (int)this.Type, Value, (int)ao); } else { res = gcpm.Add3(Name, (int)Type, ID, (int)ao); } } else { scpm.Add3(Name, (int)Type, ID, (int)ao); } break; case swCustomInfoType_e.swCustomInfoText: if (!Name.ToUpper().StartsWith("STUB")) { if (Global) { if (Name.ToUpper().EndsWith("ID")) { res = gcpm.Add3(Name, (int)swCustomInfoType_e.swCustomInfoNumber, ID, (int)ao); } else if (Name.ToUpper().StartsWith("OP"))// && !Name.ToUpper().EndsWith("ID")) { res = gcpm.Add3(Name, (int)Type, Descr, (int)ao); } else if (Name.ToUpper().Contains("UPDATE")) { res = gcpm.Add3(Name, (int)swCustomInfoType_e.swCustomInfoYesOrNo, (ID == "True" ? "Yes" : "N"), (int)ao); } else { res = gcpm.Add3(Name, (int)Type, Value, (int)ao); } } else { res = scpm.Add3(Name, (int)Type, Value, (int)ao); } } break; case swCustomInfoType_e.swCustomInfoUnknown: break; case swCustomInfoType_e.swCustomInfoYesOrNo: if (Ctl != null) { if ((Ctl as System.Windows.Forms.CheckBox).Checked) { res = gcpm.Add3(Name, (int)Type, "Yes", (int)ao); } else { res = gcpm.Add3(Name, (int)Type, "N", (int)ao); } } else { res = gcpm.Add3(Name, (int)Type, Value, (int)ao); } break; default: // we never get here, of course. break; } } }
/// <summary> /// Writes data using the custom property managers of a selected ModelDoc2. /// </summary> /// <param name="md">A ModelDoc2 object</param> public virtual void Write(ModelDoc2 md) { if (md != null) { Configuration cf = md.ConfigurationManager.ActiveConfiguration; CustomPropertyManager gcpm = md.Extension.get_CustomPropertyManager(string.Empty); CustomPropertyManager scpm = md.Extension.get_CustomPropertyManager(string.Empty); if (SWCustPropMgr != null) { scpm = SWCustPropMgr; } // Null reference on drawings. Not good. Let's just make everything global if there's no config. if (cf != null) { scpm = md.Extension.get_CustomPropertyManager(cf.Name); } // Rather than changing values, we'll just completely overwrite them. swCustomPropertyAddOption_e ao = swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd; // This is for checking if the writing actually happened. It usually does. Don't know what I'd do if it didn't. int res; if (Global) { // This is a global prop that gets a db ID #, so instead of an actual description, we get the # from the datarow in the combobox. if (( ((Name.ToUpper().StartsWith("OP") && !Name.ToUpper().EndsWith("ID"))) || Name.ToUpper().Contains("DEPARTMENT")) && Ctl != null && Properties.Settings.Default.Testing) { System.Data.DataRowView drv = ((Ctl as System.Windows.Forms.ComboBox).SelectedItem as System.Data.DataRowView); string v = Descr; res = gcpm.Add3(Name, (int)swCustomInfoType_e.swCustomInfoText, v, (int)ao); } if (((Name.ToUpper().EndsWith("ID")) || Name.ToUpper().Contains("DEPT")) && Ctl != null) { string v = ID; res = gcpm.Add3(this.Name, (int)swCustomInfoType_e.swCustomInfoNumber, v, (int)ao); } else if (this.Name.ToUpper().Contains("UPDATE")) { this.Type = swCustomInfoType_e.swCustomInfoYesOrNo; if ((Ctl as System.Windows.Forms.CheckBox).Checked) { res = gcpm.Add3(Name, (int)Type, "Yes", (int)ao); } else { res = gcpm.Add3(Name, (int)Type, "NO", (int)ao); } } else // Regular text, double, and date type global props can just be written. { res = gcpm.Add3(Name, (int)Type, Value, (int)ao); } } else { // Configuration specific props. if (Name.Contains("CUTLIST MATERIAL") && Properties.Settings.Default.Testing) { string v = Descr; res = scpm.Add3(Name, (int)swCustomInfoType_e.swCustomInfoText, v, (int)ao); } if (Name.Contains("EDGE") && Properties.Settings.Default.Testing) { string v = Descr; res = scpm.Add3(Name, (int)swCustomInfoType_e.swCustomInfoText, v, (int)ao); } } } else { } }
///// internal static HelperResult processModel(SldWorks swApp, FileObj file, BindingList <PropertyObject> prop_list, PropProcessFlag flag, CancellationToken cancellationToken) { if (swApp == null) { return(HelperResult.SLDWORKS_NOT_RUNNING); } Console.WriteLine("Helper.processModel"); int Warning = 0; int Error = 0; try { if (cancellationToken.IsCancellationRequested) { file.Note = "Cancel"; return(HelperResult.CANCELED); } if (file.Read_only) { file.Note = "Skiped (Read only!)"; return(HelperResult.SKIPED); } ModelDoc2 swDoc = swApp.OpenDoc6(file.PathToFile, (int)file.SwType_e, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref Error, ref Warning); if (Error != 0 || swDoc == null) { file.Note = "Error to open file"; return(HelperResult.OPEN_ERROR); } //* //this code error if (file.SwType_e == swDocumentTypes_e.swDocASSEMBLY || file.SwType_e == swDocumentTypes_e.swDocPART) { file.ConfigNames.AddRange(swDoc.GetConfigurationNames()); if (!file.ConfigNames.Any()) { swApp.QuitDoc(swDoc.GetTitle()); swDoc = null; file.Note = "Skiped (Unknown error)"; return(HelperResult.UNKNOWN); } } //*/ if ((flag & PropProcessFlag.MAIN_CUSTOM) == PropProcessFlag.MAIN_CUSTOM) { try { CustomPropertyManager manager = swDoc.Extension.CustomPropertyManager[""]; foreach (PropertyObject property in prop_list) { Console.WriteLine("field={0},type={1},value={2}", property.FieldName, property.FieldType, property.Value); int ret = manager.Add3(property.FieldName, (int)property.FieldType, property.Value, (int)swCustomPropertyAddOption_e.swCustomPropertyReplaceValue); if (ret != 0) { file.Note = "Error to add, err num = " + ret; } } } catch (Exception ex) { Console.WriteLine("error in add method" + ex.Message); file.Note = "error(" + ex.Message + ")"; //throw ex; } } if (((flag & PropProcessFlag.CONFIG_CUSTOM) == PropProcessFlag.CONFIG_CUSTOM) && file.ConfigNames.Any()) { try { foreach (string conf in file.ConfigNames) { Console.WriteLine(conf); CustomPropertyManager manager = swDoc.Extension.CustomPropertyManager[conf]; foreach (PropertyObject property in prop_list) { string value = property.Value; string pattern = @"[^@]+"; MatchCollection matches = Regex.Matches(value, pattern); if (matches.Count >= 3) { property.Value = Regex.Replace(value, matches[matches.Count - 2].Value, conf); } Console.WriteLine("field={0},type={1},value={2},config{3}", property.FieldName, property.FieldType, property.Value, conf); int ret = manager.Add3(property.FieldName, (int)property.FieldType, property.Value, (int)swCustomPropertyAddOption_e.swCustomPropertyReplaceValue); if (ret != 0) { file.Note = "Error to add, err num = " + ret; break; } } } } catch (Exception ex) { Console.WriteLine("error in add method" + ex.Message); file.Note = "error(" + ex.Message + ")"; //throw ex; } } file.Note = "Done"; swDoc.SaveSilent(); swApp.QuitDoc(swDoc.GetTitle()); swDoc = null; } catch (Exception e) { Console.WriteLine(e.Message); throw e; } return(HelperResult.SUCCESS); }
public static void SetProperties(string confName) { cust = swModel.Extension.CustomPropertyManager[""]; cust2 = swModel.Extension.CustomPropertyManager[confName]; cust.Add3("Конструктор", 30, Propertiy.DevelopedBy, 2); cust.Add3("Проверил", 30, Propertiy.ChechedBy, 2); cust.Add3("Техконтроль", 30, Propertiy.TControl, 2); cust.Add3("Нормоконтроль", 30, Propertiy.NControl, 2); cust.Add3("Утвердил", 30, Propertiy.ApprovedBy, 2); cust.Add3("Контора", 30, Propertiy.Subvision, 2); cust.Add3("N извещения", 30, Propertiy.Notification, 2); cust.Add3("Изменение", 30, Propertiy.Changing, 2); cust.Add3("MassaFormat", 30, Propertiy.MassaFormat, 2); cust.Add3("Код документа", 30, Propertiy.DocCode, 2); if (confName != "")// свойства для Configuration { cust2.Add3("Обозначение", 30, Propertiy.Designition, 2); cust2.Add3("Раздел", 30, Propertiy.Division, 2); cust2.Add3("Масса", 30, Propertiy.Weight, 2); cust2.Add3("Наименование", 30, Propertiy.Name, 2); cust2.Add3("Исполнение", 30, Propertiy._Version, 2); if (Propertiy.Division == "Материалы") { cust2.Add3("PDMFlag", 30, "5", 2); } } else { if (docType != swDocumentTypes_e.swDocDRAWING) { cust.Add3("Тип документа", 30, Propertiy.DocType, 2); } else if (docType == swDocumentTypes_e.swDocDRAWING) { cust2.Add3("Обозначение", 30, Propertiy.Designition, 2); cust2.Add3("Раздел", 30, Propertiy.Division, 2); cust2.Add3("Масса", 30, Propertiy.Weight, 2); cust2.Add3("Наименование", 30, Propertiy.Name, 2); cust.Add3("Литера", 30, Propertiy.Letter, 2); cust.Add3("Масштаб", 30, Propertiy.Scale, 2); cust.Add3("Материал", 30, Propertiy.Material, 2); cust.Add3("Тип документа1", 30, Propertiy.DocType1, 2); cust.Add3("Литера2", 30, Propertiy.Letter2, 2); cust.Add3("Литера3", 30, Propertiy.Letter3, 2); cust.Add3("Раздел", 30, Propertiy.Division, 2); cust.Add3("Лист", 30, Propertiy.Sheet, 2); cust.Add3("Листов", 30, Propertiy.Sheets, 2); cust.Add3("Формат", 30, Propertiy.Format, 2); CustFromDRWToModel(); SetProperties(EditProp.configuracione); CustFromModelToDRW(); } } swModel.ForceRebuild3(false); }