Extract RFA files from document using Revit api

Extract RFA files from document using Revit api

bharathkumarp
Observer Observer
1,066 Views
4 Replies
Message 1 of 5

Extract RFA files from document using Revit api

bharathkumarp
Observer
Observer

Hi there,

 

i am trying to get RFA file from current document, but i am getting this error :

Autodesk.Revit.Exceptions.InvalidOperationException: 'The document is currently modifiable! Close the transaction before calling EditFamily.'

But i am not started any transaction in code.

I used the above code in external event.

 

code : 

FilteredElementCollector collector = new FilteredElementCollector(doc);
ICollection<Element> plantElements = collector.OfCategory(BuiltInCategory.OST_Planting).ToElements();

foreach (var element in plantElements)
{
Family fam = null;
if (element is FamilyInstance)
{
familyName = (element as FamilyInstance).Symbol.FamilyName;
objectName = (element as FamilyInstance).Symbol.Name;
fam = (element as FamilyInstance).Symbol.Family;
}
if (element is FamilySymbol)
{
familyName = (element as FamilySymbol).FamilyName;
objectName = (element as FamilySymbol).Name;
fam = (element as FamilySymbol).Family;
}

Document familyEditorDocument = fam.Document.EditFamily(fam);
familyEditorDocument.SaveAs(@"D:\" + fam.Name + ".rfa");
familyEditorDocument.Close();

 

this part of code available inside the External event.

 

Any help is appreciated.

 

Regards,

Bharath

 

0 Likes
1,067 Views
4 Replies
Replies (4)
Message 2 of 5

scgq425
Advocate
Advocate

Dear bharathkumar: 

  if u want to save as thr family document , you can use function Family.SaveAs() .  In  u code , like to saveas the docuemnt of familyDoc , so throw the exception .

LanHui Xu 徐兰辉
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog
LinkedIn
Revit/CAD Development | Steel Product Manager

EESignature

0 Likes
Message 3 of 5

bharathkumarp
Observer
Observer

Hi ,

Thanks of you reply.
I am not quite understand your answer.
Can you please give me any example ? if possible.

0 Likes
Message 4 of 5

moturi.magati.george
Autodesk
Autodesk

Hi @bharathkumarp,

This might be a good place to start since the question has come up multiple times on this forum.
https://forums.autodesk.com/t5/revit-api-forum/how-to-save-family-to-a-new-file/m-p/12162514#M73339


  Moturi George,     Developer Advocacy and Support,  ADN Open
Message 5 of 5

Kennan.Chen
Advocate
Advocate

I have a code snippet to test the functionality of "Revit.Async," which can serve as an example of saving a "Family" as an RFA file.

 

You can find the code here:

Revit.Async/TestCommand/SaveFamilyCommand.cs at master · KennanChan/Revit.Async (github.com)

0 Likes