public void WriteSettings( Document doc, MyProjectSettings settings) { var settingDs = GetSettingsDataStorage( doc); if (settingDs == null) { settingDs = DataStorage.Create(doc); } Entity settingsEntity = new Entity( MyProjectSettingsSchema.GetSchema()); settingsEntity.Set("Parameter1", settings.Parameter1); settingsEntity.Set("Parameter2", settings.Parameter2); // Identify settings data storage Entity idEntity = new Entity( DataStorageUniqueIdSchema.GetSchema()); idEntity.Set("Id", settingDsId); settingDs.SetEntity(idEntity); settingDs.SetEntity(settingsEntity); }
private DataStorage GetSettingsDataStorage( Document doc) { // Retrieve all data storages from project FilteredElementCollector collector = new FilteredElementCollector(doc); var dataStorages = collector.OfClass(typeof(DataStorage)); // Find setting data storage foreach (DataStorage dataStorage in dataStorages) { Entity settingIdEntity = dataStorage.GetEntity( DataStorageUniqueIdSchema.GetSchema()); if (!settingIdEntity.IsValid()) { continue; } var id = settingIdEntity.Get <Guid>("Id"); if (!id.Equals(settingDsId)) { continue; } return(dataStorage); } return(null); }