示例#1
0
        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);
        }
示例#2
0
        private String GetRev(ModelDocExtension swModExt)
        {
            swCustPropMgr = (CustomPropertyManager)swModExt.get_CustomPropertyManager("");
            String[] propNames      = (String[])swCustPropMgr.GetNames();
            String   ValOut         = String.Empty;
            String   ResolvedValOut = String.Empty;
            Boolean  WasResolved    = false;

            String result = String.Empty;

            foreach (String name in propNames)
            {
                swCustPropMgr.Get5(name, false, out ValOut, out ResolvedValOut, out WasResolved);
                if (name.Contains("REVISION") && !name.Contains(@"LEVEL") && ValOut != String.Empty)
                {
                    result = "-" + ValOut;
                }
            }

            if (result.Length != 3)
            {
                MustHaveRevException e = new MustHaveRevException("Check to make sure drawing is at least revision AA or later.");
                //e.Data.Add("who", System.Environment.UserName);
                //e.Data.Add("when", DateTime.Now);
                //e.Data.Add("result", result);
                throw e;
            }

            //System.Diagnostics.Debug.Print(result);
            return(result);
        }
示例#3
0
        private bool ExistProperty(ModelDoc2 model, string prop)
        {
            ModelDocExtension     swExt   = model.Extension;
            CustomPropertyManager propMgr = swExt.get_CustomPropertyManager(cfgName);
            object propNames  = null;
            object propTypes  = null;
            object propValues = null;

            string resol = string.Empty;

            propMgr.GetAll(ref propNames, ref propTypes, ref propValues);

            bool has = false;

            if (propNames != null)
            {
                string[] arr = ((string[])propNames);
                for (int i = 0; i < arr.Length; i++)
                {
                    if (string.Compare(arr[i], prop, true) == 0)
                    {
                        has = true;
                        break;
                    }
                }
            }

            return(has);
        }
示例#4
0
        /// <summary>
        /// Deletes the prop from the SW doc, assigning the SwApp object.
        /// </summary>
        /// <param name="sw"></param>
        public void Del(SldWorks sw)
        {
            if (sw != null)
            {
                SwApp = sw;
                ModelDoc2     md = (ModelDoc2)sw.ActiveDoc;
                Configuration cf = md.ConfigurationManager.ActiveConfiguration;

                CustomPropertyManager gcpm = md.Extension.get_CustomPropertyManager(string.Empty);
                CustomPropertyManager scpm;
                if (cf != null)
                {
                    scpm = md.Extension.get_CustomPropertyManager(cf.Name);
                }
                else
                {
                    scpm = md.Extension.get_CustomPropertyManager(string.Empty);
                }

                int res;

                if (Global)
                {
                    res = gcpm.Delete2(Name);
                }
                else
                {
                    res = scpm.Delete2(Name);
                }
            }
            else
            {
                throw new NullReferenceException("sw is null");
            }
        }
示例#5
0
        internal static bool processModel(SldWorks swApp, string file, List <CustomPropertyObject> CustomProperties, CancellationToken cancellationToken)
        {
            int Warning = 0;
            int Error   = 0;

            try
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return(false);
                }

                string extension = Path.GetExtension(file);
                int    type      = 0;
                if (extension.ToLower().Contains("sldprt"))
                {
                    type = (int)swDocumentTypes_e.swDocPART;
                }
                else
                {
                    type = (int)swDocumentTypes_e.swDocASSEMBLY;
                }


                ModelDoc2 swModel = swApp.OpenDoc6(file, type, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref Error, ref Warning) as ModelDoc2;
                if (Error != 0)
                {
                    return(false);
                }

                if (swModel == null)
                {
                    return(false);
                }

                swModel.Visible = false;
                foreach (CustomPropertyObject obj in CustomProperties)
                {
                    CustomPropertyManager customPropertyManager = swModel.Extension.CustomPropertyManager[""];
                    if (obj.Delete)
                    {
                        DeleteCustomProperty(customPropertyManager, obj.Name);
                    }
                    else
                    {
                        replaceCustomPropertyValue(customPropertyManager, obj.Name, obj.Value, obj.NewVal);
                    }

                    swModel.SaveSilent();
                    swApp.QuitDoc(swModel.GetTitle());

                    swModel = null;
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#6
0
        /// <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();
        }
示例#7
0
        /// <summary>
        /// Deletes the prop from the selected ModelDoc2 object.
        /// </summary>
        /// <param name="md">A ModelDoc2 object.</param>
        public void Del(ModelDoc2 md)
        {
            Configuration cf = md.ConfigurationManager.ActiveConfiguration;

            CustomPropertyManager gcpm = md.Extension.get_CustomPropertyManager(string.Empty);
            CustomPropertyManager scpm;

            if (cf != null)
            {
                scpm = md.Extension.get_CustomPropertyManager(cf.Name);
            }
            else
            {
                scpm = md.Extension.get_CustomPropertyManager(string.Empty);
            }

            int res;

            if (this.Global)
            {
                res = gcpm.Delete2(Name);
            }
            else
            {
                res = scpm.Delete2(Name);
            }
        }
        public List <PropertiesClass> ListProperties()
        {
            var listString = new List <PropertiesClass>();

            _swModelDocExtComp = SwModel.Extension;

            var propNames  = default(object);
            var propTypes  = default(object);
            var propValues = default(object);

            _swCustPropMgrComp = _swModelDocExtComp.CustomPropertyManager["00"];

            _swCustPropMgrComp.GetAll(ref propNames, ref propTypes, ref propValues);

            var asCustPropName = (string[])propNames;

            //var asCustPropValues = (string[])propValues;

            for (var i = 0; i < asCustPropName.GetUpperBound(0) - 1; i++)
            {
                var columnValue = new PropertiesClass
                {
                    PropertiesName = asCustPropName[i]
                };

                listString.Add(columnValue);
            }
            return(listString);
        }
示例#9
0
        protected override SwCustomProperty CreatePropertyInstance(CustomPropertyManager prpMgr, string name, bool isCreated)
        {
            var prp = new SwCutListCustomProperty(prpMgr, name, m_ParentDoc, m_ParentConf, isCreated, m_App);

            InitProperty(prp);
            return(prp);
        }
示例#10
0
        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;
            }
        }
示例#11
0
        private SwProperty AssignProperty(CustomPropertyManager pm, string name)
        {
            int    res;
            int    success   = (int)swCustomInfoGetResult_e.swCustomInfoGetResult_ResolvedValue;
            bool   useCached = false;
            string valOut    = string.Empty;
            string resValOut = string.Empty;
            bool   wasResolved;

            SwProperty rp = new SwProperty();

            rp.SwApp = this.SwApp;

            if (!InThere(pm, name))
            {
                return(rp);
            }
            else
            {
            }

            res = pm.Get5(name, useCached, out valOut, out resValOut, out wasResolved);

            if (res == success)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("Found {0}.", name));
                rp.Name     = name;
                rp.Value    = valOut;
                rp.ResValue = resValOut;
                rp.Type     = swCustomInfoType_e.swCustomInfoText;
                rp.Global   = true;
            }
            return(rp);
        }
        /// <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));
        }
        /// <summary>
        /// Метод удаляет свойство в соответствующую конфигурацию
        /// объекта и в ModelDoc2
        /// </summary>
        /// <param name="nameConfig"></param>
        /// <param name="prop"></param>
        /// <returns></returns>
        public int Remove(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];

            //Удаляем из списка свойств.
            if (_ConfigPropertys[nameConfig].Remove(prop))
            {
                //Удаляем свойство из модели SolidWorks
                return(_customPropManager.Delete2(prop.Name));
            }
            else
            {
                return(1);
            }
        }
        protected override SwCustomProperty CreatePropertyInstance(CustomPropertyManager prpMgr, string name, bool isCreated)
        {
            var prp = new SwConfigurationCustomProperty(prpMgr, name, isCreated, m_Doc, m_ConfName, m_App);

            InitProperty(prp);
            return(prp);
        }
示例#15
0
        private Dimension CreerParam(ModelDoc2 mdl, Feature fDossier, String nomCfg, int indexDimension)
        {
            Dimension param = null;

            try
            {
                // On recherche si le dossier contient déjà la propriété RefDossier
                //      Si non, on ajoute la propriété au dossier selon le modèle suivant :
                //              P"D1@REPERAGE_DOSSIER@Nom_de_la_piece.SLDPRT"
                //      Si oui, on récupère le nom du paramètre à configurer

                CustomPropertyManager PM = fDossier.CustomPropertyManager;
                String val;

                String nomParam = String.Format("D{0}@{1}", indexDimension, CONSTANTES.NOM_ESQUISSE_NUMEROTER);
                val = String.Format("{0}\"{1}@{2}\"", CONSTANTES.PREFIXE_REF_DOSSIER, nomParam, mdl.eNomAvecExt());
                var r = PM.ePropAdd(CONSTANTES.REF_DOSSIER, val);

                PM.ePropAdd(CONSTANTES.DESC_DOSSIER, val);
                val = String.Format("\"SW-CutListItemName@@@{0}@{1}\"", fDossier.Name, mdl.eNomAvecExt());
                PM.ePropAdd(CONSTANTES.NOM_DOSSIER, val);

                param = mdl.Parameter(nomParam);
                param.SetSystemValue3(0.5 * 0.001, (int)swSetValueInConfiguration_e.swSetValue_InSpecificConfigurations, nomCfg);
            }
            catch (Exception e) { this.LogErreur(new Object[] { e }); }

            return(param);
        }
示例#16
0
        /// <summary>
        /// Pull the description string from a part/assembly in a View.
        /// </summary>
        /// <param name="v">A View object.</param>
        /// <returns>A description string.</returns>
        public static string get_description(SolidWorks.Interop.sldworks.View v)
        {
            ModelDoc2            md    = (ModelDoc2)v.ReferencedDocument;
            ConfigurationManager cfMgr = md.ConfigurationManager;
            Configuration        cf    = cfMgr.ActiveConfiguration;

            CustomPropertyManager gcpm = md.Extension.get_CustomPropertyManager(string.Empty);
            CustomPropertyManager scpm;

            string _value    = "PART";
            string _resValue = string.Empty;
            bool   wasResolved;
            bool   useCached = false;

            if (cf != null)
            {
                scpm = cf.CustomPropertyManager;
            }
            else
            {
                scpm = gcpm;
            }
            int res;

            res = gcpm.Get5("Description", useCached, out _value, out _resValue, out wasResolved);
            if (_value == string.Empty)
            {
                res = scpm.Get5("Description", useCached, out _value, out _resValue, out wasResolved);
            }
            return(_value);
        }
        protected virtual SwCustomProperty CreatePropertyInstance(CustomPropertyManager prpMgr, string name, bool isCreated)
        {
            var prp = new SwCustomProperty(prpMgr, name, isCreated, m_Doc.App);

            prp.SetEventsHandler(CreateEventsHandler(prp));
            return(prp);
        }
示例#18
0
 internal SwCutListCustomProperty(CustomPropertyManager prpMgr, string name,
                                  ISwDocument3D refDoc, ISwConfiguration refConf, bool isCommited, ISwApplication app)
     : base(prpMgr, name, isCommited, app)
 {
     m_RefDoc  = refDoc;
     m_RefConf = refConf;
 }
示例#19
0
        /// <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();
        }
示例#20
0
        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
        }
示例#21
0
        internal SwCutListCustomPropertiesCollection(CustomPropertyManager prpsMgr,
                                                     ISwDocument3D parentDoc, ISwConfiguration parentConf, ISwApplication app)
            : base((SwDocument)parentDoc, app)
        {
            PrpMgr = prpsMgr;

            m_ParentDoc  = parentDoc;
            m_ParentConf = parentConf;
        }
示例#22
0
        public void Write()
        {
            ModelDoc2             md  = (ModelDoc2)this._swApp.ActiveDoc;
            CustomPropertyManager glP = md.Extension.get_CustomPropertyManager(string.Empty);

            this.ClearProps();
            foreach (SwProperty p in this._innerArray)
            {
                p.Write();
            }
        }
示例#23
0
            private String Quantite()
            {
                CustomPropertyManager PM = MdlBase.Extension.get_CustomPropertyManager("");

                if (MdlBase.ePropExiste(PropQuantite.GetValeur <String>()))
                {
                    return(Math.Max(MdlBase.eGetProp(PropQuantite.GetValeur <String>()).eToInteger(), 1).ToString());
                }

                return("1");
            }
示例#24
0
 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;
 }
        public TabletModelInformation(string hobNumber)
        {
            HobNumber = hobNumber;
            string                modelPath = GetTabletPath(hobNumber) + ".SLDPRT";
            ModelDoc2             tablet    = (ModelDoc2)sldWorks.OpenDoc(modelPath, (int)swDocumentTypes_e.swDocPART);
            CustomPropertyManager cpmTablet = (CustomPropertyManager)tablet.Extension.CustomPropertyManager[""];

            GetDieNumber(tablet, cpmTablet);
            GetSize(tablet);
            sldWorks.CloseDoc(HobNumber);
        }
示例#26
0
 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;
 }
示例#27
0
        public void Write(ModelDoc2 md)
        {
            CustomPropertyManager glP = md.Extension.get_CustomPropertyManager(string.Empty);

            CutlistData.IncrementOdometer(CutlistData.Functions.GreenCheck);
            this.ClearProps(md);
            foreach (SwProperty p in this._innerArray)
            {
                p.Write(md);
            }
        }
示例#28
0
        public static string GetAttValueByName(string AtrName, ModelDoc2 swModel)
        {
            string cfgname2 = swModel.ConfigurationManager.ActiveConfiguration.Name;

            CustomPropertyManager cpmMdl = swModel.Extension.get_CustomPropertyManager(cfgname2);
            string outval = "";
            string sovVal = "";

            cpmMdl.Get2(AtrName, out outval, out sovVal);
            return(sovVal);
        }
示例#29
0
        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);
        }
        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("属性写入成功!");
        }
示例#31
0
        /// <summary>
        /// Directly draws from SW.
        /// </summary>
        public void Get()
        {
            if (SwApp != null)
            {
                ModelDoc2            md    = (ModelDoc2)this.SwApp.ActiveDoc;
                ConfigurationManager cfMgr = md.ConfigurationManager;
                Configuration        cf    = cfMgr.ActiveConfiguration;

                CustomPropertyManager gcpm = md.Extension.get_CustomPropertyManager(string.Empty);
                CustomPropertyManager scpm;

                bool wasResolved;
                bool useCached = false;

                if (cf != null)
                {
                    scpm = cf.CustomPropertyManager;
                }
                else
                {
                    scpm = gcpm;
                }

                if (SWCustPropMgr != null)
                {
                    scpm = SWCustPropMgr;
                }

                int res;

                if (this.Global)
                {
                    res       = gcpm.Get5(Name, useCached, out _value, out _resValue, out wasResolved);
                    this.Type = (swCustomInfoType_e)gcpm.GetType2(this.Name);


                    if (Type == swCustomInfoType_e.swCustomInfoNumber && Name.ToUpper().Contains("OVER"))
                    {
                        Type = swCustomInfoType_e.swCustomInfoDouble;
                    }
                }
                else
                {
                    res       = scpm.Get5(Name, useCached, out _value, out _resValue, out wasResolved);
                    this.Type = (swCustomInfoType_e)gcpm.GetType2(Name);
                }
            }
            else
            {
                throw new NullReferenceException("sw is null");
            }
        }
        /// <summary>
        /// Méthode interne
        /// Initialise l'objet GestDeProprietes
        /// </summary>
        /// <param name="SwGestionnaire"></param>
        /// <param name="Modele"></param>
        /// <returns></returns>
        internal Boolean Init(CustomPropertyManager SwGestionnaire, eConfiguration Configuration)
        {
            Log.Methode(cNOMCLASSE);

            if ((SwGestionnaire != null) && (Configuration != null) && Configuration.EstInitialise)
            {
                _SwGestDeProprietes = SwGestionnaire;
                _Configuration = Configuration;
                _Modele = Configuration.Modele;
                _EstInitialise = true;
            }
            else
            {
                Log.Message("!!!!! Erreur d'initialisation");
            }

            return _EstInitialise;
        }