Here is an issue trying to access the binding map of a family document that just re-arose as a new ADN support case.
It took me a while (thank you, Google) to discover that I had actually already answered the very same issue in the past in the Revit API forum discussion thread cannot get binding map of a family document error 2014.
Therefore, I think it is best for both you and me if I promote it to a blog post here and now to ensure it gets found more easily in future:
Question: My add-in adds a shared parameter to a family document. It has been working perfectly for years now, ever since 2009, in fact. In Revit 2014, however, it fails and throws an exception saying "Cannot get BindingMap of a family document."
Simply accessing the Document.ParameterBindings property causes this error.
What is the problem, please?
Above all, how can I fix it?
Answer: The possibility to add a shared parameter via the binding map was removed for families in Revit 2014.
The reason for this is that you can use an overload of the FamilyManager.AddParameter method instead.
In your code, you are setting up a shared parameter definition, creating a category set, and adding a shared parameter binding using code that only applies to the project environment, not in the family context.
In a family document, you can simply use the appropriate overload of the AddParameter method to do all these things for you in one single fell swoop.
The Revit 2014 API help file RevitAPI.chm entry on the Document.ParameterBindings property explicitly states that it throws an Autodesk.Revit.Exceptions.InvalidOperationException when the document is a family document.
Sorry that this affects your existing code.
The modification to fix the error should be easy.
Just remove the part of the code that accesses the binding map and tries to bind the parameter to the family document, call the AddParameter overload to add a shared parameter and achieve all the required steps for you automatically, including setting up a category set and an instance binding, and all should be well.
Dear Jeremy
On 11 Feb-2014
http://thebuildingcoder.typepad.com/blog/geometry/
Element elem = doc.GetElement( ref1 );
FamilyInstance fi = elem as FamilyInstance;
LocationCurve lc = fi.Location as LocationCurve;
uidoc.Selection.Elements.Clear();
ElementArray startarray = lc
.get_ElementsAtJoin( 0 );
this code give element that joint to beam but not give result for pipe and duct and its associated fitting such as elbow and tee. please suggest me , what i do to get joint element to Elbow or tee or Duct.
Posted by: Manish | March 27, 2014 at 03:16
Jeremy,
Thanks for the help, removing the binding made it possible, but has brought up another issue. It is saving the changes in the family level, not the project level. If the user makes another change, say adding another shared parameters, it will add the change to the family itself but not the family within the project. I am assuming what happens is the first time we place the family it updates the parameters first and inserts the family but without binding it any changes after the model is placed does not update. We are trying to resolve this, but any tips would be appreciated.
Thanks,
Brad
Posted by: Brad | March 29, 2014 at 10:10
Dear Brad,
Thank you for the appreciation. I am glad it helped.
It sounds like you need to force Revit to reload the family.
It may refuse to do so if it is under the impression that nothing relevant changed.
In that case, you may need to force the reloading even more, e.g. by deleting the existing instances in the project, including its symbols and the family definition itself.
Cheers, Jeremy.
Posted by: Jeremy Tammik | April 10, 2014 at 06:49