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);
        }
예제 #2
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);
        }
        public void GetAllPropertiesName()
        {
            _swModelDocExtComp = _swModel.Extension;

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

            _swCustPropMgrComp = _swModelDocExtComp.CustomPropertyManager[String.Empty];

            _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++)
            {
                MessageBox.Show(asCustPropName[i]);
            }
        }
예제 #4
0
        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);
        }