Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        private Entity GetSettingsEntity(
            Document doc)
        {
            FilteredElementCollector collector =
                new FilteredElementCollector(doc);

            var dataStorages =
                collector.OfClass(typeof(DataStorage));

            // Find setting data storage

            foreach (DataStorage dataStorage in dataStorages)
            {
                Entity settingEntity =
                    dataStorage.GetEntity(MyProjectSettingsSchema.GetSchema());

                // If a DataStorage contains
                // setting entity, we found it

                if (!settingEntity.IsValid())
                {
                    continue;
                }

                return(settingEntity);
            }

            return(null);
        }