Exemple #1
0
        public static void WriteState(Autodesk.Revit.DB.Document doc, List <SpeckleStream> state)
        {
            var ds = GetStateDataStorage(doc);

            // TODO: The problem:
            // "Attempt to modify the model outside of transaction."
            // Needs to be wrapped in a Action and sloshed in the queue.
            try
            {
                if (ds == null)
                {
                    ds = DataStorage.Create(doc);
                }
            }
            catch (Exception e)
            {
            }
            Entity speckleStateEntity = new Entity(SpeckleStateSchema.GetSchema());

            var ls = state.Select(stream => JsonConvert.SerializeObject(stream)).ToList();

            speckleStateEntity.Set("streams", ls as IList <string>);

            Entity idEntity = new Entity(DSUniqueSchemaLocalState.GetSchema());

            idEntity.Set("Id", ID);

            ds.SetEntity(idEntity);
            ds.SetEntity(speckleStateEntity);
        }
Exemple #2
0
        private static Entity GetStateEntity(Autodesk.Revit.DB.Document doc)
        {
            FilteredElementCollector collector = new FilteredElementCollector(doc);

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

            foreach (DataStorage dataStorage in dataStorages)
            {
                Entity settingEntity = dataStorage.GetEntity(SpeckleStateSchema.GetSchema());
                if (!settingEntity.IsValid())
                {
                    continue;
                }

                return(settingEntity);
            }
            return(null);
        }