Hello!
We are developing a solution that uploads Revit Family files to DMS server. First we added a few shared parameters that have the information of DMS record to our families.
if (doc.IsFamilyDocument) { Family f = doc.OwnerFamily; FamilyManager manager = doc.FamilyManager;
//Check if parameters have already been added to Family and it's Symbols.
//If not then adding parameters using Transaction. if (manager.get_Parameter("DMS_DOCNUMBER") == null) { using (Transaction trans = new Transaction(doc, "PARAM_SET")) { trans.Start(); manager.AddParameter("DMS_DOCNUMBER", BuiltInParameterGroup.PG_IDENTITY_DATA, ParameterType.Text, true); manager.AddParameter("DMS_DOCVERSION", BuiltInParameterGroup.PG_IDENTITY_DATA, ParameterType.Text, true); manager.AddParameter("DMS_DOCTYPE", BuiltInParameterGroup.PG_IDENTITY_DATA, ParameterType.Text, true); manager.AddParameter("DMS_DOCPART", BuiltInParameterGroup.PG_IDENTITY_DATA, ParameterType.Text, true); trans.Commit(); } }
//Create FamilyParameter reference objects after parameters have been added or checked if added FamilyParameter docnr = manager.get_Parameter("DMS_DOCNUMBER"); FamilyParameter docvers = manager.get_Parameter("DMS_DOCVERSION"); FamilyParameter doctype = manager.get_Parameter("DMS_DOCTYPE"); FamilyParameter docpart = manager.get_Parameter("DMS_DOCPART");
//Setting parameter values for every Symbol in the family foreach (FamilyType ft in manager.Types) { if (!MaterialHasDocument(ft, manager)) { DocumentObj docObj = CreateDMSDocument("RVT"); using (Transaction trans = new Transaction(doc, "SET_PARAM")) { trans.Start(); manager.CurrentType = ft; manager.Set(docnr, docObj.docNumber); manager.Set(docvers, docObj.docVersion); manager.Set(doctype, docObj.docType); manager.Set(docpart, docObj.docPart); trans.Commit(); }
//This is where we upload the .rfa file
//MANY MANY ERRORS UploadOriginal(docObj, f, doc); } } } else { TaskDialog.Show("Info", "Family view not open."); }
Everything works as it should up until UploadOriginal method call.
string path = Path.GetTempPath(); string name = family.Name; string fName = name + ".rfa"; string fPath = path + fName;
//Revit throws an error on this line saying that Family is not editable
//What could cause this mayhem?
//To upload .rfa Family file I need to save it as a file first and that's what I try to do until mighty ERROR occurs Document famDoc = doc.EditFamily(family); famDoc.SaveAs(fPath); famDoc.Close(false); //application related code following...
What could be the reason of this error? How could I fix it? Must it be overwritten like a baus (BOSS)?
Solved! Go to Solution.
Solved by jeremytammik. Go to Solution.
Dear Raunoveb,
I implemented an add-in to update fonts in loaded families yesterday.
For some of the loaded families, EditFamily threw that same exception saying "Family is not editable".
I added an exception handler to skip them:
try { r1.FamilyDocument = doc.EditFamily( f ); } catch( Autodesk.Revit.Exceptions.ArgumentException ex ) { r1.Skipped = true; results.Add( r1 ); Debug.Print( "Family '{0}': {1}", f.Name, ex.Message ); continue; }
Here is an excerpt of the add-in log; the families marked 'skipped' are the ones I mean:
I simply assumed that is normal.
Cheers,
Jeremy
p.s. cool video 🙂
I managed to skip those families by simply adding if(family.IsEditable) block around the code. Unfortunately for us these families we try to process must be processed so we can't just skip them.
I've had 2 ideas that could explain those errors:
I have danced around this problem for 3 days and have ran out of ideas. Any help "unlocking" these families would be greatly appreciated.
Dear Raunoveb,
Thank you very much for pointing out the IsEditable predicate. I successfully replaced my exception handler by simply checking that instead.
Regarding your locked families, have you tried ensuring that absolutely no other documents are open, only the one and only family that you are trying to modify?
Cheers,
Jeremy
Thanks for your comment about any other open documents. I suddenly realized that in my main program I already had FamilyDocument open. When I used UploadOriginal() method I gave doc as an input and then tried:
var famDoc = doc.EditFamily(family); famDoc.SaveAs(path); famDoc.Close(false);
That created another Family Document instance of the same family and that's why it threw this "Family not editable" exception. I changed it to:
doc.SaveAs(path); //Can't close it since I have this family view open in Revit and API
//doesn't have permission to close visibly open documents in Revit. //doc.Close(false);
However now I've got problems with getting the Family.Name value from doc.OwnerFamily.Name. It always returns "" and all the files saved look like this "/folder/.rfa", when they should look something like this "/folder/NightLamp.rfa"
Dear Raunoveb,
Cool.
Progress.
How about using the document title instead of the family name?
Cheers,
Jeremy
Using doc.Title did the trick. However it's weird that OwnerFamily.Name returned blank response.
Thanks for everything. And since your second answer provided most help regarding to the main question I'll mark that one as a solution.
Dear Raunoveb,
Cooler still.
That was a quick solution.
Thank you for marking the solution and for the interesting discussion.
Cheers,
Jeremy
Dear Raunoveb,
I published another discussion on modifying, saving and reloading families on The Building Coder today:
http://thebuildingcoder.typepad.com/blog/2014/09/modifying-saving-and-reloading-families.html
Since this thread is related to that, I summarised it there as well.
Cheers,
Jeremy
Can't find what you're looking for? Ask the community or share your knowledge.