/// <summary> /// Sets string value of a built-in parameter of an element. /// </summary> /// <param name="element">The element.</param> /// <param name="builtInParameter">The built-in parameter.</param> /// <param name="propertyValue">The property value.</param> /// <exception cref="System.ArgumentNullException">Thrown when element is null.</exception> /// <exception cref="System.ArgumentException">Thrown when builtInParameter in invalid.</exception> public static void SetStringParameter(Element element, BuiltInParameter builtInParameter, string propertyValue) { if (element == null) { throw new ArgumentNullException("element"); } if (builtInParameter == BuiltInParameter.INVALID) { throw new ArgumentException("BuiltInParameter is INVALID", "builtInParameter"); } Parameter parameter = element.get_Parameter(builtInParameter); if (parameter != null && parameter.HasValue && parameter.StorageType == StorageType.String) { if (!parameter.IsReadOnly) { parameter.Set(propertyValue); } return; } ElementId parameterId = new ElementId(builtInParameter); ExporterIFCUtils.AddValueString(element, parameterId, propertyValue); }
protected virtual void CreateParametersInternal(Document doc, Element element) { if (element != null) { // Set the element name. SetName(doc, element); // Set the element description. SetDescription(doc, element); // The list of materials. SetMaterialParameter(doc, element); // Set the "IfcSystem" parameter. SetSystemParameter(doc, element); // Set the element GUID. bool elementIsType = (element is ElementType); BuiltInParameter ifcGUIDId = GetGUIDParameter(element, elementIsType); Parameter guidParam = element.get_Parameter(ifcGUIDId); if (guidParam != null) { if (!guidParam.IsReadOnly) { guidParam.Set(GlobalId); } } else { ExporterIFCUtils.AddValueString(element, new ElementId(ifcGUIDId), GlobalId); } // Set the "IfcExportAs" parameter. string ifcExportAs = IFCCategoryUtil.GetCustomCategoryName(this); if (!string.IsNullOrWhiteSpace(ifcExportAs)) { IFCPropertySet.AddParameterString(doc, element, "IfcExportAs", ifcExportAs, Id); } // Add property set-based parameters. // We are going to create this "fake" parameter so that we can filter elements in schedules based on their property sets. string propertySetListName = elementIsType ? "Type IfcPropertySetList" : "IfcPropertySetList"; IFCPropertySet.AddParameterString(doc, element, propertySetListName, "", Id); // Set the IFCElementAssembly Parameter if (Decomposes != null && Decomposes is IFCElementAssembly) { IFCPropertySet.AddParameterString(doc, element, "IfcElementAssembly", Decomposes.Name, Id); } } }
private void SetGUIDParameter(Element element, BuiltInParameter builtInParameter, string guidValue) { Parameter parameter = element.get_Parameter(builtInParameter); if (parameter != null && parameter.HasValue && parameter.StorageType == StorageType.String) { parameter.SetValueString(guidValue); } else { ElementId parameterId = new ElementId(builtInParameter); ExporterIFCUtils.AddValueString(element, parameterId, guidValue); } }
/// <summary> /// Sets string value of a built-in parameter of an element. /// </summary> /// <param name="element">The element.</param> /// <param name="builtInParameter">The built-in parameter.</param> /// <param name="propertyValue">The property value.</param> /// <exception cref="System.ArgumentNullException">Thrown when element is null.</exception> /// <exception cref="System.ArgumentException">Thrown when builtInParameter in invalid.</exception> public static void SetStringParameter(Element element, BuiltInParameter builtInParameter, string propertyValue) { if (element == null) { throw new ArgumentNullException("element"); } if (builtInParameter == BuiltInParameter.INVALID) { throw new ArgumentException("BuiltInParameter is INVALID", "builtInParameter"); } ElementId parameterId = new ElementId(builtInParameter); ExporterIFCUtils.AddValueString(element, parameterId, propertyValue); }
private static void StoreIFCCreatorInfo(IFCFile ifcFile, ProjectInfo projectInfo) { if (ifcFile == null || projectInfo == null) { return; } IList <IFCAnyHandle> applications = ifcFile.GetInstances(IFCAnyHandleUtil.GetIFCEntityTypeName(IFCEntityType.IfcApplication), false); IFCAnyHandle application = applications.FirstOrDefault(); if (application != null) { var appFullName = IFCAnyHandleUtil.GetStringAttribute(application, "ApplicationFullName"); if (!string.IsNullOrEmpty(appFullName)) { var applicationNameId = new ElementId(BuiltInParameter.IFC_APPLICATION_NAME); ExporterIFCUtils.AddValueString(projectInfo, applicationNameId, appFullName); } var appVersion = IFCAnyHandleUtil.GetStringAttribute(application, "Version"); if (!string.IsNullOrEmpty(appVersion)) { var applicationVersionId = new ElementId(BuiltInParameter.IFC_APPLICATION_VERSION); ExporterIFCUtils.AddValueString(projectInfo, applicationVersionId, appVersion); } } IList <IFCAnyHandle> organisations = ifcFile.GetInstances(IFCAnyHandleUtil.GetIFCEntityTypeName(IFCEntityType.IfcOrganization), false); IFCAnyHandle organisation = organisations.LastOrDefault(); if (organisation != null) { var orgName = IFCAnyHandleUtil.GetStringAttribute(organisation, "Name"); if (!string.IsNullOrEmpty(orgName)) { var organizationId = new ElementId(BuiltInParameter.IFC_ORGANIZATION); ExporterIFCUtils.AddValueString(projectInfo, organizationId, orgName); } } }
protected virtual void CreateParametersInternal(Document doc, Element element) { if (element != null) { // Set the element name. SetName(doc, element); // Set the element description. SetDescription(doc, element); // The list of materials. SetMaterialParameter(doc, element); // Set the "IfcSystem" parameter. SetSystemParameter(doc, element); // Set the element GUID. bool elementIsType = (element is ElementType); BuiltInParameter ifcGUIDId = GetGUIDParameter(element, elementIsType); Parameter guidParam = element.get_Parameter(ifcGUIDId); if (guidParam != null) { if (!guidParam.IsReadOnly) { guidParam.Set(GlobalId); } } else { ExporterIFCUtils.AddValueString(element, new ElementId(ifcGUIDId), GlobalId); } // Set the "IfcExportAs" parameter. string ifcExportAs = IFCCategoryUtil.GetCustomCategoryName(this); if (!string.IsNullOrWhiteSpace(ifcExportAs)) { IFCPropertySet.AddParameterString(doc, element, "IfcExportAs", ifcExportAs, Id); } // Add property set-based parameters. // We are going to create this "fake" parameter so that we can filter elements in schedules based on their property sets. string propertySetListName = elementIsType ? "Type IfcPropertySetList" : "IfcPropertySetList"; IFCPropertySet.AddParameterString(doc, element, propertySetListName, "", Id); // Set the IFCElementAssembly Parameter if (Decomposes != null && Decomposes is IFCElementAssembly) { IFCPropertySet.AddParameterString(doc, element, "IfcElementAssembly", Decomposes.Name, Id); } // Set additional parameters (if any), e.g. for Classification assignments if (AdditionalIntParameters.Count > 0) { foreach (KeyValuePair <string, object> parItem in AdditionalIntParameters) { if (parItem.Value is string) { IFCPropertySet.AddParameterString(doc, element, parItem.Key, (string)parItem.Value, Id); } else if (parItem.Value is double) { IFCPropertySet.AddParameterDouble(doc, element, parItem.Key, UnitType.UT_Custom, (double)parItem.Value, Id); } else if (parItem.Value is int) { IFCPropertySet.AddParameterInt(doc, element, parItem.Key, (int)parItem.Value, Id); } else if (parItem.Value is bool) { IFCPropertySet.AddParameterBoolean(doc, element, parItem.Key, (bool)parItem.Value, Id); } } } } }
protected virtual void CreateParametersInternal(Document doc, Element element) { if (element != null) { Category category = IFCPropertySet.GetCategoryForParameterIfValid(element, Id); // Set the element name. SetName(doc, element, category); // Set the element description. SetDescription(doc, element, category); // The list of materials. SetMaterialParameter(doc, element, category); // Set the "IfcSystem" parameter. SetSystemParameter(doc, element, category); // Set the element GUID. bool elementIsType = (element is ElementType); BuiltInParameter ifcGUIDId = GetGUIDParameter(element, elementIsType); Parameter guidParam = element.get_Parameter(ifcGUIDId); if (guidParam != null) { if (!guidParam.IsReadOnly) { guidParam.Set(GlobalId); } } else { ExporterIFCUtils.AddValueString(element, new ElementId(ifcGUIDId), GlobalId); } // Set the "IfcExportAs" parameter. string ifcExportAs = IFCCategoryUtil.GetCustomCategoryName(this); if (!string.IsNullOrWhiteSpace(ifcExportAs)) { IFCPropertySet.AddParameterString(doc, element, category, this, IFCSharedParameters.IfcExportAs, ifcExportAs, Id); } // Set the IFCElementAssembly Parameter if (Decomposes != null) { string containerParamName = (Decomposes is IFCElementAssembly) ? "IfcElementAssembly" : "IfcDecomposes"; string containerParamGUIDName = (Decomposes is IFCElementAssembly) ? "IfcElementAssemblyGUID" : "IfcDecomposesGUID"; IFCPropertySet.AddParameterString(doc, element, category, containerParamName, Decomposes.Name, Id); IFCPropertySet.AddParameterString(doc, element, category, containerParamGUIDName, Decomposes.GlobalId, Id); } // Set additional parameters (if any), e.g. for Classification assignments if (AdditionalIntParameters.Count > 0) { foreach (KeyValuePair <string, object> parItem in AdditionalIntParameters) { if (parItem.Value is string) { IFCPropertySet.AddParameterString(doc, element, category, parItem.Key, (string)parItem.Value, Id); } else if (parItem.Value is double) { IFCPropertySet.AddParameterDouble(doc, element, category, parItem.Key, SpecTypeId.Custom, (double)parItem.Value, Id); } else if (parItem.Value is int) { IFCPropertySet.AddParameterInt(doc, element, category, parItem.Key, (int)parItem.Value, Id); } else if (parItem.Value is bool) { IFCPropertySet.AddParameterBoolean(doc, element, category, parItem.Key, (bool)parItem.Value, Id); } } } } }