Set DataStorage Entity

Set DataStorage Entity

AGGilliam
Collaborator Collaborator
1,691 Views
1 Reply
Message 1 of 2

Set DataStorage Entity

AGGilliam
Collaborator
Collaborator

I'm just now exploring Revit's Extensible Storage and I decided to try creating a DataStorage element to store some project data. I can create the DataStorage element and the Entity just fine, but when I try applying the entity the DocumentCreatedEvent closes without committing the transaction. There shouldn't be an issue doing this in the event I'm using, right?

 

I'll paste some of my code below, but just as a reference I used Victor's "Effortless Extensible Storage" that Jeremy talks about here. (So if the code I pasted looks good, I probably broke something else).

 

using (Transaction t = new Transaction(doc, "Create data storage"))
            {
                t.Start();

                DataStorage dsProjectData = DataStorage.Create(doc);
                ProjectData entProjectData = new ProjectData();
                entProjectData.Author = Environment.UserName;
                entProjectData.DateCreated = DateTime.Now;
                entProjectData.RoomCount = 0;
                dsProjectData.SetEntity(entProjectData);

                t.Commit();
            }

[Schema("FB0EE2DE-06EB-4A0E-8C76-11B906F40B16", "Project Data")]
    public class ProjectData : IRevitEntity
    {
        #region Creation Info
        /// <summary>
        /// The user who created the project
        /// </summary>
        [Field]
        public string Author { get; set; }

        /// <summary>
        /// The date the project was created
        /// </summary>
        [Field]
        public DateTime DateCreated { get; set; }
        #endregion

        /// <summary>
        /// Total number of rooms in the project
        /// </summary>
        [Field]
        public int RoomCount { get; set; }
    }
0 Likes
Accepted solutions (1)
1,692 Views
1 Reply
Reply (1)
Message 2 of 2

AGGilliam
Collaborator
Collaborator
Accepted solution

Continued debugging and finally figured it out. It seems that the name of the schema can't have spaces in it. I also included a DateTime parameter without really thinking about it, which wasn't supported by the system Victor created. After fixing both of those, the code works just fine.

0 Likes