Ejemplo n.º 1
0
      protected IFCImportCache(Document doc, string fileName)
      {
         // Get all categories of current document
         Settings documentSettings = doc.Settings;

         DocumentCategories = documentSettings.Categories;
         GenericModelsCategory = DocumentCategories.get_Item(BuiltInCategory.OST_GenericModel);

         ProjectInfo projectInfo = doc.ProjectInformation;
         ProjectInformationId = (projectInfo == null) ? ElementId.InvalidElementId : projectInfo.Id;

         // Cache the original shared parameters file, and create and read in a new one.
         OriginalSharedParametersFile = doc.Application.SharedParametersFilename;
         doc.Application.SharedParametersFilename = fileName + ".sharedparameters.txt";

         DefinitionFile definitionFile = doc.Application.OpenSharedParameterFile();
         if (definitionFile == null)
         {
            StreamWriter definitionFileStream = new StreamWriter(doc.Application.SharedParametersFilename, false);
            definitionFileStream.Close();
            definitionFile = doc.Application.OpenSharedParameterFile();
         }

         if (definitionFile == null)
            throw new InvalidOperationException("Can't create definition file for shared parameters, aborting import.");

         DefinitionInstanceGroup = definitionFile.Groups.get_Item("IFC Parameters");
         if (DefinitionInstanceGroup == null)
            DefinitionInstanceGroup = definitionFile.Groups.Create("IFC Parameters");

         DefinitionTypeGroup = definitionFile.Groups.get_Item("IFC Type Parameters");
         if (DefinitionTypeGroup == null)
            DefinitionTypeGroup = definitionFile.Groups.Create("IFC Type Parameters");

         // Cache list of schedules.
         FilteredElementCollector viewScheduleCollector = new FilteredElementCollector(doc);
         ICollection<Element> viewSchedules = viewScheduleCollector.OfClass(typeof(ViewSchedule)).ToElements();
         foreach (Element viewSchedule in viewSchedules)
         {
            ScheduleDefinition definition = (viewSchedule as ViewSchedule).Definition;
            if (definition == null)
               continue;

            ElementId categoryId = definition.CategoryId;
            if (categoryId == ElementId.InvalidElementId)
               continue;

            ViewSchedules[new KeyValuePair<ElementId, string>(categoryId, viewSchedule.Name)] = viewSchedule.Id;
            ViewScheduleNames.Add(viewSchedule.Name);
         }

         // Find the status bar, so we can add messages.
         StatusBar = RevitStatusBar.Create();
      }