Beispiel #1
0
        /// <summary>
        /// Load user-defined Property set
        /// Format:
        ///    PropertSet: <Pset_name> I[nstance]/T[ype] <IFC entity list separated by ','> 
        ///              Property_name   Data_type   Revit_Parameter
        ///              ...
        /// Datatype supported: Text, Integer, Real, Boolean
        /// Line divider between Property Mapping and User defined property sets:
        ///     #! UserDefinedPset
        /// </summary>
        /// <returns>List of property set definitions</returns>
        public static IList<PropertySetDef> LoadUserDefinedPset()
        {
            IList<PropertySetDef> userDefinedPsets = new List<PropertySetDef>();
            PropertySetDef userDefinedPset;

            try
            {
                string filename = GetUserDefPsetFilename();
                if (File.Exists(filename))
                {
                    using (StreamReader sr = new StreamReader(filename))
                    {
                        string line;

                        while ((line = sr.ReadLine()) != null)
                        {
                            line.TrimStart(' ', '\t');

                            if (String.IsNullOrEmpty(line)) continue;
                            if (line[0] != '#')
                            {
                                // Format: PropertSet: <Pset_name> I[nstance]/T[ype] <IFC entity list separated by ','> 
                                //              Property_name   Data_type   Revit_Parameter
                                // ** For now it only works for simple property with single value (datatype supported: Text, Integer, Real and Boolean)

                                string[] split = line.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
                                if (string.Compare(split[0], "PropertySet:", true) == 0)
                                {
                                    userDefinedPset = new PropertySetDef();
                                    userDefinedPset.applicableElements = new List<string>();
                                    userDefinedPset.propertyDefs = new List<PropertyDef>();

                                    if (split.Count() >= 4)         // Any entry with less than 3 par is malformed
                                    {
                                        userDefinedPset.propertySetName = split[1];
                                        switch (split[2][0])
                                        {
                                            case 'T':   userDefinedPset.applicableTo = TypeOrInstance.Type;
                                                        break;
                                            case 'I':   userDefinedPset.applicableTo = TypeOrInstance.Instance;
                                                        break;
                                            default:    userDefinedPset.applicableTo = TypeOrInstance.Instance;
                                                        break;
                                        }
                                        string[] elemlist = split[3].Split(new char[] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                                        foreach (string elem in elemlist)
                                            userDefinedPset.applicableElements.Add(elem);

                                        userDefinedPsets.Add(userDefinedPset);
                                    }
                                }
                                else
                                {
                                    PropertyDef propertyDefUnit = new PropertyDef();
                                    if (split.Count() >= 2)
                                    {
                                        propertyDefUnit.propertyName = split[0];
                                        propertyDefUnit.propertyDataType = split[1];
                                        if (split.Count() >= 3)
                                            propertyDefUnit.revitParameterName = split[2];
                                        else
                                            propertyDefUnit.revitParameterName = propertyDefUnit.propertyName;
                                        userDefinedPsets.Last().propertyDefs.Add(propertyDefUnit);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
            
            return userDefinedPsets;
        }
Beispiel #2
0
        /// <summary>
        /// Load user-defined Property set
        /// Format:
        ///    PropertSet: <Pset_name> I[nstance]/T[ype] <IFC entity list separated by ','>
        ///              Property_name   Data_type   Revit_Parameter
        ///              ...
        /// Datatype supported: Text, Integer, Real, Boolean
        /// Line divider between Property Mapping and User defined property sets:
        ///     #! UserDefinedPset
        /// </summary>
        /// <returns>List of property set definitions</returns>
        public static IList <PropertySetDef> LoadUserDefinedPset()
        {
            IList <PropertySetDef> userDefinedPsets = new List <PropertySetDef>();
            PropertySetDef         userDefinedPset;

            try
            {
                string filename = GetUserDefPsetFilename();
                if (File.Exists(filename))
                {
                    using (StreamReader sr = new StreamReader(filename))
                    {
                        string line;

                        while ((line = sr.ReadLine()) != null)
                        {
                            line.TrimStart(' ', '\t');

                            if (String.IsNullOrEmpty(line))
                            {
                                continue;
                            }
                            if (line[0] != '#')
                            {
                                // Format: PropertSet: <Pset_name> I[nstance]/T[ype] <IFC entity list separated by ','>
                                //              Property_name   Data_type   Revit_Parameter
                                // ** For now it only works for simple property with single value (datatype supported: Text, Integer, Real and Boolean)

                                string[] split = line.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
                                if (string.Compare(split[0], "PropertySet:", true) == 0)
                                {
                                    userDefinedPset = new PropertySetDef();
                                    userDefinedPset.applicableElements = new List <string>();
                                    userDefinedPset.propertyDefs       = new List <PropertyDef>();

                                    if (split.Count() >= 4)         // Any entry with less than 3 par is malformed
                                    {
                                        userDefinedPset.propertySetName = split[1];
                                        switch (split[2][0])
                                        {
                                        case 'T':   userDefinedPset.applicableTo = TypeOrInstance.Type;
                                            break;

                                        case 'I':   userDefinedPset.applicableTo = TypeOrInstance.Instance;
                                            break;

                                        default:    userDefinedPset.applicableTo = TypeOrInstance.Instance;
                                            break;
                                        }
                                        string[] elemlist = split[3].Split(new char[] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                                        foreach (string elem in elemlist)
                                        {
                                            userDefinedPset.applicableElements.Add(elem);
                                        }

                                        userDefinedPsets.Add(userDefinedPset);
                                    }
                                }
                                else
                                {
                                    PropertyDef propertyDefUnit = new PropertyDef();
                                    if (split.Count() >= 2)
                                    {
                                        propertyDefUnit.propertyName     = split[0];
                                        propertyDefUnit.propertyDataType = split[1];
                                        if (split.Count() >= 3)
                                        {
                                            propertyDefUnit.revitParameterName = split[2];
                                        }
                                        else
                                        {
                                            propertyDefUnit.revitParameterName = propertyDefUnit.propertyName;
                                        }
                                        userDefinedPsets.Last().propertyDefs.Add(propertyDefUnit);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }

            return(userDefinedPsets);
        }