- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've read the information and followed the instructions in https://thebuildingcoder.typepad.com/blog/2012/05/devblog-devcamp-element-and-project-wide-data.html... to create a DataStorage with project-wide settings. The problem is, after the call to DataStorage.Create(), I do get a new data storage object with an ElementId, but then this element does not exist in the document when I try to retrieve it or snoop it.
Here I make the transaction:
RevitProjectExportSettings exportProjectSettings = new RevitProjectExportSettings(exportOptions);
RevitProjectDataStorage dataStorage = new RevitProjectDataStorage();
using (Transaction t = new Transaction(doc, "Write project settings"))
{
t.Start();
dataStorage.writeProjectSettings(doc, exportProjectSettings);
t.Commit();
}
Here is writeProjectSettings() routine:
public void writeProjectSettings(Document doc, RevitProjectExportSettings settings)
{
var settingDataStorage = getSettingsDataStorage(doc);
if (settingDataStorage is null)
{
// Here I do get a new DataStorage element with a proper ElementId,
// but when I snoop the database later it does not exist.
settingDataStorage = DataStorage.Create(doc);
}
Entity settingsEntity = new Entity(RevitProjectExportSettingsSchema.getSchema());
// Save all settings to the entity.
settingsEntity.Set(RevitProjectExportSettingsSchema.EXPORT_FILE_NAME, settings.ExportFileName);
settingsEntity.Set(RevitProjectExportSettingsSchema.EXPORT_FILE_PATH, settings.ExportPath);
settingsEntity.Set(RevitProjectExportSettingsSchema.EXPORT_MODE, settings.ExportMode);
settingsEntity.Set(RevitProjectExportSettingsSchema.EXPORT_UNIT_SET, settings.UnitSet);
// Identify settings data storage.
Entity idEntity = new Entity(DataStorageUniqueIdSchema.getSchema());
idEntity.Set("Id", dataStorageId);
settingDataStorage.SetEntity(idEntity);
settingDataStorage.SetEntity(settingsEntity);
}
Here is the getSettingsDataStorage() routine:
private DataStorage getSettingsDataStorage(Document doc)
{
FilteredElementCollector collector = new FilteredElementCollector(doc);
var dataStorages = collector.OfClass(typeof(DataStorage));
// Find our data storage identified by containing our specific settings schema.
foreach (DataStorage dataStorage in dataStorages)
{
Entity settingIdEntity = dataStorage.GetEntity(DataStorageUniqueIdSchema.getSchema());
if (!settingIdEntity.IsValid()) continue;
// Check that the id matches our storage id.
var id = settingIdEntity.Get<Guid>("Id");
if (id.Equals(dataStorageId))
{
return dataStorage;
}
}
return null;
}
Solved! Go to Solution.