示例#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 = ExporterCacheManager.ExportOptionsCache.PropertySetOptions.ExportUserDefinedPsetsFileName;
                if (!File.Exists(filename))
                {
                    // This allows for the original behavior of looking in the directory of the export DLL to look for the default file name.
                    filename = GetUserDefPsetFilename();
                }
                if (!File.Exists(filename))
                {
                    return(userDefinedPsets);
                }

                string extension = Path.GetExtension(filename);
                //if (string.Compare(extension, ".ifcxml", true) == 0 || string.Compare(extension, ".ifcjson", true) == 0 || string.Compare(extension, ".ifc", true) == 0)
                //{
                //DatabaseIfc db = new DatabaseIfc(filename);
                //IfcContext context = db.Context;
                //if (context == null)
                //return userDefinedPsets;
                //foreach (IfcRelDeclares relDeclares in context.Declares)
                //{
                //foreach (IfcPropertySetTemplate template in relDeclares.RelatedDefinitions.OfType<IfcPropertySetTemplate>())
                //{
                //userDefinedPset = new PropertySetDef();
                //userDefinedPset.applicableElements = new List<string>(template.ApplicableEntity.Split(",".ToCharArray()));
                //userDefinedPset.propertyDefs = new List<PropertyDef>();

                //userDefinedPset.propertySetName = template.Name;
                //userDefinedPset.propertySetDescription = template.Description;
                //userDefinedPset.applicableTo = (template.TemplateType == IfcPropertySetTemplateTypeEnum.PSET_TYPEDRIVENONLY || template.TemplateType == IfcPropertySetTemplateTypeEnum.QTO_TYPEDRIVENONLY ? TypeOrInstance.Type : TypeOrInstance.Instance);
                //userDefinedPsets.Add(userDefinedPset);
                //foreach (IfcPropertyTemplate propTemplate in template.HasPropertyTemplates)
                //{
                //List<PropertyParameterDefinition> definitions = new List<PropertyParameterDefinition>();
                //IfcValue value = null;
                //foreach (IfcRelAssociates associates in propTemplate.HasAssociations)
                //{
                //IfcRelAssociatesClassification associatesClassification = associates as IfcRelAssociatesClassification;
                //if (associatesClassification != null)
                //{
                //IfcClassificationReference classificationReference = associatesClassification.RelatingClassification as IfcClassificationReference;
                //if (classificationReference != null)
                //{
                //string id = classificationReference.Identification;
                //if (id.ToLower().StartsWith("builtinparameter."))
                //{
                //Autodesk.Revit.DB.BuiltInParameter builtInParameter = Autodesk.Revit.DB.BuiltInParameter.INVALID;
                //id = id.Substring(17);
                //if (Enum.TryParse<Autodesk.Revit.DB.BuiltInParameter>(id, out builtInParameter) && builtInParameter != Autodesk.Revit.DB.BuiltInParameter.INVALID)
                //definitions.Add(new PropertyParameterDefinition(builtInParameter));
                //else
                //{
                //}
                //}
                //else
                //definitions.Add(new PropertyParameterDefinition(id));
                //}
                //}
                //else
                //{
                //IfcRelAssociatesConstraint associatesConstraint = associates as IfcRelAssociatesConstraint;
                //if (associatesConstraint != null)
                //{
                //IfcMetric metric = associatesConstraint.RelatingConstraint as IfcMetric;
                //if (metric != null)
                //{
                //value = metric.DataValue as IfcValue;
                //}
                //}
                //}
                //}
                //if (definitions.Count > 0 || value != null)
                //{
                //PropertyDef propertyDefUnit = new PropertyDef(propTemplate.Name, definitions);
                //IfcSimplePropertyTemplate simple = propTemplate as IfcSimplePropertyTemplate;
                //if (simple != null)
                //{
                //propertyDefUnit.PropertyDataType = simple.PrimaryMeasureType.ToLower().Replace("ifc", "");
                //}
                //propertyDefUnit.DefaultValue = value;
                //userDefinedPset.propertyDefs.Add(propertyDefUnit);
                //}
                //}
                //}
                //}
                //}
                //else
                {
                    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 = null;
                                    if (split.Count() >= 2)
                                    {
                                        if (split.Count() >= 3)
                                        {
                                            propertyDefUnit = new PropertyDef(split[0], new PropertyParameterDefinition(split[2]));
                                        }
                                        else
                                        {
                                            propertyDefUnit = new PropertyDef(split[0]);
                                        }
                                        propertyDefUnit.PropertyDataType = split[1];
                                        userDefinedPsets.Last().propertyDefs.Add(propertyDefUnit);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }

            return(userDefinedPsets);
        }
示例#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 = ExporterCacheManager.ExportOptionsCache.PropertySetOptions.ExportUserDefinedPsetsFileName;
                if (!File.Exists(filename))
                {
                    // This allows for the original behavior of looking in the directory of the export DLL to look for the default file name.
                    filename = GetUserDefPsetFilename();
                }
                if (!File.Exists(filename))
                    return userDefinedPsets;

                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;
        }
示例#3
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 = ExporterCacheManager.ExportOptionsCache.PropertySetOptions.ExportUserDefinedPsetsFileName;
                if (!File.Exists(filename))
                {
                    // This allows for the original behavior of looking in the directory of the export DLL to look for the default file name.
                    filename = GetUserDefPsetFilename();
                }
                if (!File.Exists(filename))
                {
                    return(userDefinedPsets);
                }

                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);
        }