Example #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);
        }
Example #2
0
        private static DataStorage GetStateDataStorage(Autodesk.Revit.DB.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(DSUniqueSchemaLocalState.GetSchema());

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

                var id = settingIdEntity.Get <Guid>("Id");

                if (!id.Equals(ID))
                {
                    continue;
                }

                return(dataStorage);
            }
            return(null);
        }