/// <summary> /// Generates the name for the element to be created. /// </summary> /// <param name="baseName">If not null, generates a name if Name is invalid.</param> /// <returns>The name.</returns> protected string GetName(string baseName) { if (string.IsNullOrWhiteSpace(Name)) { if (!string.IsNullOrWhiteSpace(baseName)) { return(baseName + " " + Id); } return(null); } return(IFCNamingUtil.CleanIFCName(Name)); }
private static string GetMaterialName(int id, string originalName) { // Disallow creating multiple materials with the same name. This means that the // same material, with different styles, will be created with different names. string materialName = Importer.TheCache.CreatedMaterials.GetUniqueMaterialName(originalName, id); string revitMaterialName = IFCNamingUtil.CleanIFCName(materialName); if (revitMaterialName != null) { return(revitMaterialName); } return(String.Format(Resources.IFCDefaultMaterialName, id)); }
/// <summary> /// Create a schedule for a given property set. /// </summary> /// <param name="doc">The document.</param> /// <param name="element">The element being created.</param> /// <param name="category">The category of the element.</param> /// <param name="parameterGroupMap">The parameters of the element. Cached for performance.</param> /// <param name="parametersCreated">The created parameters.</param> protected void CreateScheduleForPropertySet(Document doc, Element element, Category category, IFCParameterSetByGroup parameterGroupMap, ISet <string> parametersCreated) { // Don't bother creating schedules if we are maximizing performance. if (IFCImportFile.TheFile.Options.UseStreamlinedOptions) { return; } if (parametersCreated.Count == 0) { return; } if (category == null) { return; } ElementId categoryId = category.Id; bool elementIsType = (element is ElementType); string cleanName = IFCNamingUtil.CleanIFCName(Name); Tuple <ElementId, bool, string> scheduleKey = Tuple.Create(categoryId, elementIsType, cleanName); ISet <string> viewScheduleNames = Importer.TheCache.ViewScheduleNames; IDictionary <Tuple <ElementId, bool, string>, ElementId> viewSchedules = Importer.TheCache.ViewSchedules; ElementId viewScheduleId; if (!viewSchedules.TryGetValue(scheduleKey, out viewScheduleId)) { string scheduleName = scheduleKey.Item3; string scheduleTypeName = elementIsType ? " " + Resources.IFCTypeSchedule : string.Empty; int index = 1; while (viewScheduleNames.Contains(scheduleName)) { string indexString = (index > 1) ? " " + index.ToString() : string.Empty; scheduleName += " (" + category.Name + scheduleTypeName + indexString + ")"; index++; if (index > 1000) { Importer.TheLog.LogWarning(Id, "Too many property sets with the name " + scheduleKey.Item3 + ", no longer creating schedules with that name.", true); return; } } // Not all categories allow creating schedules. Skip these. ViewSchedule viewSchedule = null; try { viewSchedule = ViewSchedule.CreateSchedule(doc, scheduleKey.Item1); } catch { // Only try to create the schedule once per key. viewSchedules[scheduleKey] = ElementId.InvalidElementId; return; } if (viewSchedule != null) { viewSchedule.Name = scheduleName; viewSchedules[scheduleKey] = viewSchedule.Id; viewScheduleNames.Add(scheduleName); ElementId ifcGUIDId = new ElementId(elementIsType ? BuiltInParameter.IFC_TYPE_GUID : BuiltInParameter.IFC_GUID); string propertySetListName = elementIsType ? Resources.IFCTypeSchedule + " IfcPropertySetList" : "IfcPropertySetList"; ScheduleDefinition viewScheduleDefinition = viewSchedule.Definition; IList <SchedulableField> schedulableFields = viewScheduleDefinition.GetSchedulableFields(); bool filtered = false; foreach (SchedulableField sf in schedulableFields) { string fieldName = sf.GetName(doc); if (parametersCreated.Contains(fieldName) || sf.ParameterId == ifcGUIDId) { viewScheduleDefinition.AddField(sf); } else if (!filtered && fieldName == propertySetListName) { // We want to filter the schedule for specifically those elements that have this property set assigned. ScheduleField scheduleField = viewScheduleDefinition.AddField(sf); scheduleField.IsHidden = true; ScheduleFilter filter = new ScheduleFilter(scheduleField.FieldId, ScheduleFilterType.Contains, "\"" + Name + "\""); viewScheduleDefinition.AddFilter(filter); filtered = true; } } } } return; }