Revit API

Reply
Valued Contributor
Paulio
Posts: 82
Registered: ‎06-26-2008
Message 1 of 4 (346 Views)
Accepted Solution

Cannot Get Bindingmap of a family Document Error 2014

346 Views, 3 Replies
07-03-2013 01:12 AM

I have an addin that, amongst other things, adds and sets a custom ID parameter to family files.

This has been working fine in 2012 and 2013 but now I'm trying it in 2014 I'm getting the above error.

 

            Dim bin As Autodesk.Revit.DB.Binding = m_app.Create.NewTypeBinding(catSet)            
            If Not m_doc.ParameterBindings.Insert(def, bin) Then ' ERROR HERE

m_doc is my family document

def is my parameter definition

catSet is a category set containing the category that I'm trying to add the parameter to.

 

I'll admit that I'm no Revit API expert so I may be going about this the wrong way but as I've said, it seems to work OK for 2012 and 2013. Is there something else I need to do for 2014?

 

Thanks in advance.

 

Paul

Here is the summary of the resolution of the associated ADN case 08576310 [Error creating parameter in family]:

Jeremy says: 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.

The modification to your existing code should be simple.

Paul replies: I have successfully resolved the issue now based upon your latest message.

It turns out that I just needed to remove the part that tried to bind the parameter to the family document. I only needed to create the definition if it didn’t exist and then use that when adding the parameter to the family.

Best regards,

Jeremy

ADN Support Specialist
jeremytammik
Posts: 564
Registered: ‎08-20-2007
Message 2 of 4 (320 Views)

Re: Cannot Get Bindingmap of a family Document Error 2014

07-15-2013 08:26 AM in reply to: Paulio

Dear Paul,

Thank you for your query.

I implemented the attached sample application and can reproduce the issue you describe.

In a newly created empty family document based on the Generic Model template, it reports the following:

Info: Inside CreateIDParameter function. Cat is: Walls
Info: Opened Shared Parameters file
Info: sharedFile is Autodesk.Revit.DB.DefinitionFile
Info: Got Group
Info: Got CADSID def
A first chance exception of type 'Autodesk.Revit.Exceptions.InvalidOperationException' occurred in RevitAPI.dll
Cannot get the BindingMap of a family document.

Here is the complete source code:

  Public Function CreateIDParameter( _
    ByVal doc As Document,
    ByVal cat As Category) As Boolean
    Debug.WriteLine(String.Format("Info: Inside CreateIDParameter function. Cat is: {0}", IIf(cat Is Nothing, "NOTHING", cat.Name)))
    Dim app As Application = doc.Application
    Dim sharedFile As DefinitionFile
    Try
      sharedFile = app.OpenSharedParameterFile()
      Debug.WriteLine("Info: Opened Shared Parameters file")
    Catch ex As Exception
      Return False
    End Try
    Debug.WriteLine(String.Format("Info: sharedFile is {0}", IIf(sharedFile Is Nothing, "NOTHING", sharedFile)))
    Dim grp As DefinitionGroup = sharedFile.Groups.Item("IDENTIFIER")
    If grp Is Nothing Then
      grp = sharedFile.Groups.Create("IDENTIFIER")
      Debug.WriteLine("Info: Created group IDENTIFIER")
    End If
    Debug.WriteLine("Info: Got Group")
    If grp Is Nothing Then Return False
    Dim def As Definition = grp.Definitions.Item("CADSID")
    If def Is Nothing Then
      def = grp.Definitions.Create("CADSID", ParameterType.Text, False)
      Debug.WriteLine("Info: Created CADSID def")
    End If
    Debug.WriteLine("Info: Got CADSID def")
    If def Is Nothing Then Return False
    Dim catSet As CategorySet = app.Create.NewCategorySet()
    catSet.Insert(cat)
    Dim bin As Binding = Nothing
    Dim bindings As BindingMap
    Dim res As Boolean = Nothing
    Try
      bin = app.Create.NewTypeBinding(catSet)
      bindings = doc.ParameterBindings
      res = doc.ParameterBindings.Insert(def, bin) 'ERROR OCCURS HERE
    Catch ex As Exception
      Debug.WriteLine(ex.Message)
      Return False
    End Try
    Return True
  End Function

  Public Function Execute(
    ByVal commandData As ExternalCommandData,
    ByRef message As String,
    ByVal elements As ElementSet) _
  As Result Implements IExternalCommand.Execute

    Dim uiapp As UIApplication = commandData.Application
    Dim uidoc As UIDocument = uiapp.ActiveUIDocument
    Dim app As Application = uiapp.Application
    Dim doc As Document = uidoc.Document
    Dim cat As Category = doc.Settings.Categories.Item(BuiltInCategory.OST_Walls)

    CreateIDParameter(doc, cat)

    Return Result.Succeeded
  End Function

I also attached it together with the Visual Studio solution and add-in manifest to this message in _08576310.zip.

I searched for other reports of this error and could not find any, so I do rather suspect that you are doing something unusual here.

Are you sure that it makes sense to create a shared parameter for a family document?

The error message looks to me as if the API is intentionally restricting you from doing what you do.

A couple of other similar restrictions were introduced in Revit 2014 which broke other applications as well. They were all doing dirty deeds, and now that is prevented.

You should probably discuss with a product usage expert what exactly you are trying to achieve, and see how you should implement that optimally manually before trying to automate it.

It looks to me as if the workflow you were using in the past is not following Revit best practices.

I hope this helps.

Best regards,


Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

ADN Support Specialist
jeremytammik
Posts: 564
Registered: ‎08-20-2007
Message 3 of 4 (289 Views)

Re: Cannot Get Bindingmap of a family Document Error 2014

08-15-2013 06:39 AM in reply to: jeremytammik

Here is the summary of the resolution of the associated ADN case 08576310 [Error creating parameter in family]:

Jeremy says: 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.

The modification to your existing code should be simple.

Paul replies: I have successfully resolved the issue now based upon your latest message.

It turns out that I just needed to remove the part that tried to bind the parameter to the family document. I only needed to create the definition if it didn’t exist and then use that when adding the parameter to the family.

Best regards,

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

ADN Support Specialist
jeremytammik
Posts: 564
Registered: ‎08-20-2007
Message 4 of 4 (142 Views)

Re: Cannot Get Bindingmap of a family Document Error 2014

03-26-2014 07:21 AM in reply to: jeremytammik

By the way, this issue came up again, so I promoted it to a blog post on The Building Coder:

 

http://thebuildingcoder.typepad.com/blog/2014/03/cannot-get-bindingmap-of-a-family-document.html



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.