- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all-
I'm writing some code that will write to a DataStorage object that is connected to a Family Document that is attaching a GUID. When I attempt to write to the DataStorage object connected to the Document during a Saved/Saved As event, Revit API returns a transaction completed outside of a Transaction. k. cool. I attempt to create a transaction with a using, and the API tells me I cannot start a transaction during the Saved/Saved As events.
So, this leads me to think that I need to raise this method after the Saved/Saved As events are completed. Is all of that true? I would think that I would be able to write to the document in the Saved/Saved As events, because this is post the Save, so the document should be ready to receive some action.
Exception is being thrown at that last try catch. fyi
public void SetFieldAsGUID(Document doc, string fieldName, Guid value)
{
if (Entity == null)
return;
DataStorage dataStorage = GetDataStorage(doc);
Entity ent;
if (dataStorage == null)
{
//ent = SetDataStorage(doc);
if (doc.IsModifiable)
System.Diagnostics.Debug.WriteLine("document is modifiable");
if (doc.IsReadOnly)
System.Diagnostics.Debug.WriteLine("document is readonly");
ent = new Entity(IDSchema);
}
else
ent = new Entity(IDSchema);
Field field = IDSchema.GetField(fieldName);
ent.Set(field, value);
try
{
dataStorage.SetEntity(ent);
}
catch (Autodesk.Revit.Exceptions.ModificationOutsideTransactionException ex) { TaskDialog.Show("Modification Outside Transaction", ex.Message); }
}
Solved! Go to Solution.