/// <summary> /// Contructor with vars. /// </summary> /// <param name="PropertyName">This is more or less permanent, and yan't add one if it already exists.</param> /// <param name="swType">This gets reassigned appropriately on write because so many old models have it wrong.</param> /// <param name="testValue">Unresolved val.</param> /// <param name="global">This gets reassigned appropriately on write because so many old models have it wrong.</param> public SwProperty(string PropertyName, swCustomInfoType_e swType, string testValue, bool global) { Name = PropertyName; Type = swType; ID = "0"; Old = false; Value = testValue; ResValue = testValue; Global = global; }
public SwProperty(CustomPropertyManager c, string PropertyName, swCustomInfoType_e swType, string testValue, bool global) { SWCustPropMgr = c; Name = PropertyName; Type = swType; ID = "0"; Old = false; Value = testValue; ResValue = testValue; Global = global; }
private void btnOK_Click(object sender, EventArgs e) { DrawingRev r = null; swCustomInfoType_e tType = swCustomInfoType_e.swCustomInfoText; SwProperty rev = new SwProperty("REVISION " + (char)(nodeCount + 65), tType, cbRev.Text, true); SwProperty eco = new SwProperty("ECO " + (nodeCount + 1).ToString(), tType, tbECO.Text, true); // I usually only apply this filter on insertion, but this field is only ever // displayed on drawings. We only want all caps for that as well. SwProperty desc = new SwProperty("DESCRIPTION " + (nodeCount + 1).ToString(), tType, CutlistData.FilterString(tbDesc.Text, Properties.Settings.Default.FlameWar), true); cbBy.ValueMember = "INITIAL"; SwProperty list; if (cbBy.SelectedValue != null) { list = new SwProperty("LIST " + (nodeCount + 1).ToString(), tType, (cbBy.SelectedValue as string).Substring(0, 2), true); } else { list = new SwProperty("LIST " + (nodeCount + 1).ToString(), tType, string.Empty, true); } SwProperty date = new SwProperty("DATE " + (nodeCount + 1).ToString(), tType, dtpDate.Value.ToShortDateString(), true); if (Revs.Contains("REVISION " + (char)(nodeCount + 65))) { r = Revs.GetRev("REVISION " + (char)(nodeCount + 65)); r.Revision = rev; r.Eco = eco; r.Description = desc; r.List = list; r.Date = date; } else { r = new DrawingRev(rev, eco, desc, list, date); Revs.Add(r); } r.SwApp = Revs.SwApp; if (new_rev) { try { AddECRItem(r); } catch (Exception ex) { r.SwApp.SendMsgToUser2(ex.Message, (int)swMessageBoxIcon_e.swMbStop, (int)swMessageBoxBtn_e.swMbOk); } } this.Close(); }
/// <summary> /// Sets the value of a custom property by name /// </summary> /// <param name="name">The name of the custom property</param> /// <param name="value">The value of the custom property</param> /// <param name="type">The type of the custom property</param> /// <returns></returns> public void SetCustomProperty(string name, string value, swCustomInfoType_e type = swCustomInfoType_e.swCustomInfoText) { // TODO: Add error checking and exception catching // NOTE: We use Add here to create a property if one doesn't exist // I feel this is the expected behaviour of Set // // To mimic the Set behaviour of the SolidWorks API // Simply do CustomPropertyExists() to check first if it exists // // Set new one BaseObject.Add3(name, (int)type, value, (int)swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd); }
public SwProperty(string name, object value, swCustomInfoType_e type) { this.Name = name; // имя свойства this.Value = (string)value; // значение свойства this.Type = type; // тип свойства }
public bool SetModelProperty(ModelDoc2 model, string fieldName, string cfgName, swCustomInfoType_e fieldType, string val, bool checkFirst = false) { bool isPropertyChanged = false; string fieldValue = string.Empty; if (checkFirst) { fieldValue = model.GetCustomInfoValue(cfgName, fieldName); if (fieldValue == val) return isPropertyChanged; } if (!string.IsNullOrEmpty(fieldValue.Trim()) && fieldValue != "-" && !fieldValue.Contains("Color")) isPropertyChanged = true; model.AddCustomInfo3(cfgName, fieldName, (int)fieldType, val); model.set_CustomInfo2(cfgName, fieldName, val); return isPropertyChanged; }
public List <Tuple <string, string, string, object> > GetProperties(string FileName) { // check for solidworks instance if (swApp == null) { return(null); } if (!File.Exists(FileName)) { return(null); } // config name // property name // property type // resolved value (boxed object) List <Tuple <string, string, string, object> > lstProps = new List <Tuple <string, string, string, object> >(); // get doc type swDocumentTypes_e swDocType = GetTypeFromString(FileName); if (swDocType == swDocumentTypes_e.swDocNONE) { return(null); } // document open options // swOpenDocOptions_e is a bitmask enumerator // use bitwise "and" to select multiple options swOpenDocOptions_e swOpenDocOptions = swOpenDocOptions_e.swOpenDocOptions_Silent & swOpenDocOptions_e.swOpenDocOptions_DontLoadHiddenComponents & swOpenDocOptions_e.swOpenDocOptions_LoadLightweight & swOpenDocOptions_e.swOpenDocOptions_Silent & swOpenDocOptions_e.swOpenDocOptions_ReadOnly; // try to load the model file int intWarnings = 0; int intErrors = 0; ModelDoc2 swModelDoc; try { swModelDoc = swApp.OpenDoc6(FileName, (int)swDocType, (int)swOpenDocOptions, "", ref intErrors, ref intWarnings); } catch { return(null); } ModelDocExtension swDocExt = swModelDoc.Extension; // get list of configs //string[] strConfgNames = (string[])swModelDoc.GetConfigurationNames(); List <string> lstConfigNames = new List <string>(); if (swDocType != swDocumentTypes_e.swDocDRAWING) { lstConfigNames = new List <string>((string[])swModelDoc.GetConfigurationNames()); } lstConfigNames.Add(""); foreach (string strConfigName in lstConfigNames) { CustomPropertyManager swCustPropMgr = swDocExt.get_CustomPropertyManager(strConfigName); object oPropNames = null; object oPropTypes = null; object oPropValues = null; //object oResolved = null; //swCustPropMgr.GetAll2(ref oPropNames, ref oPropTypes, ref oPropValues, ref oResolved); swCustPropMgr.GetAll(ref oPropNames, ref oPropTypes, ref oPropValues); if (oPropNames == null) { continue; } // get list of properties for this config int intPropCount = ((string[])oPropNames).Length; for (int i = 0; i < intPropCount; i++) { // property name string strPropName = ((string[])oPropNames)[i]; // property name // property type string strPropType = ""; swCustomInfoType_e eCustInfoType = ((swCustomInfoType_e[])oPropTypes)[i]; // property type switch (eCustInfoType) { case swCustomInfoType_e.swCustomInfoDate: strPropType = "date"; break; case swCustomInfoType_e.swCustomInfoDouble: strPropType = "number"; break; case swCustomInfoType_e.swCustomInfoNumber: strPropType = "number"; break; case swCustomInfoType_e.swCustomInfoText: strPropType = "text"; break; case swCustomInfoType_e.swCustomInfoUnknown: strPropType = ""; break; case swCustomInfoType_e.swCustomInfoYesOrNo: strPropType = "yesno"; break; } // property value //object oPropValue = ((object[])oResolved)[i]; // resolved value, with GetAll2() object oPropValue = ((object[])oPropValues)[i]; // resolved value, with GetAll() oPropValue.GetType(); if (oPropValue.GetType() == typeof(System.Double)) { oPropValue = (Decimal)oPropValue; } // add to list lstProps.Add(Tuple.Create <string, string, string, object>(strConfigName, strPropName, strPropType, oPropValue)); } } swModelDoc = null; swApp.CloseDoc(FileName); return(lstProps); }
/// <summary> /// Ajouter une propriété /// </summary> /// <param name="Nom"></param> /// <param name="TypePropriete"></param> /// <param name="Expression"></param> /// <param name="EcraserExistante"></param> /// <returns></returns> public ePropriete AjouterPropriete(String Nom, swCustomInfoType_e TypePropriete, String Expression, Boolean EcraserExistante = false) { Log.Methode(cNOMCLASSE); // Si on écrase, on supprime la propriété if (EcraserExistante) _SwGestDeProprietes.Delete(Nom); // On la récupère ePropriete Propriete = RecupererPropriete(Nom); // Si elle n'existe pas on la crée et on lui assigne l'expression if (Propriete == null) { _SwGestDeProprietes.Add2(Nom, (int)TypePropriete, Expression); Propriete = new ePropriete(); Propriete.Init(this, Nom); } // Si tout est ok, on la renvoi if (Propriete.EstInitialise) return Propriete; return null; }