Family Instance Parameters

Family Instance Parameters

Anonymous
Not applicable
3,432 Views
5 Replies
Message 1 of 6

Family Instance Parameters

Anonymous
Not applicable

Hello,

 

I am having problems with setting a value to a FamilyInstance parameter.

 

I added a new parameter to a family with FamilyManager.AddParameter (with the isInstance bool set to true). From what I understand, this means this parameter is unique to each instance now.

 

I now want to set a value to this parameter (will be a different value for each instance). I don't think I can do this with FamilyManager.Set(), since I cannot provide the exact instance to set the value to. How can I do this?

 

Can I convert my FamilyInstance object to an Element object and then use the Set() method?

 

Thank you in advance.

 

P.S. I'm using Revit 2019

0 Likes
3,433 Views
5 Replies
Replies (5)
Message 2 of 6

architect.bim
Collaborator
Collaborator

Hi!

In family editor you can only set default value for instance parameter. If you really need this use Set method of FamilyManager class.

If you want to set parameter values of real instances placed in Revit model first you need to load your family to a project, place intances. And then collect them with FilteredElementCollector. For each of them get Parameter object with LookupParameter method or Parameter property. And then set parameter's value.


Maxim Stepannikov | Architect, BIM Manager, Instructor
0 Likes
Message 3 of 6

Anonymous
Not applicable

Thank you for replying!

 

Just to clear things up:

  • Use the FamilyInstance to get the family document using EditFamily method of the main document.
  • Get the FamilyManager from the family document 
  • Start a transaction on the family document
  • Add the parameter to the family using AddParameter method FamilyManager
  • Commit the transaction

Since EditFamily creates a copy of the family, at this point do I reload the family document using the LoadFamily() method of family document?

0 Likes
Message 4 of 6

architect.bim
Collaborator
Collaborator

Actually EditFamily does not create a copy. It simply opens family as a separate document. But you are right: after you change the opened family you need to reload it back to the project with LoadFamily method. Consider that not all overloads of this method are able to reload the same family into the source document. You should use particulary this one.


Maxim Stepannikov | Architect, BIM Manager, Instructor
0 Likes
Message 5 of 6

Anonymous
Not applicable

Hi, 

 

Sorry to bother you again, but I have another issue.

 

Here is what I've done:

  • Get a selection of elements from the document (I filter out elements that are not family instances)
  • Get a HashSet of families that don't have the parameter
  • Loop over the HashSet of unique families and add the parameter to them

However, at this point I get an error: The shared parameter 'XXXX' is already in use.

 

Is this error caused by the family already having this parameter? Since I'm using a HashSet, I should only have unique families. I've also tried checking if the parameter exists in the family, while I'm in the loop, but I still have this error.

 

Thanks in advance.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0 Likes
Message 6 of 6

Anonymous
Not applicable

Managed to solve this problem. Turns out you have to load the family into the document before you add the parameter to a different family.

 

I do have another problem tho:

 

I'm trying to get the room that an element is located in. I'm trying to use the document GetRoomAtPoint method, however, the method keeps returning null.

 

What is causing this error? And is there any other way of accessing the room the element is located in?

 

Thanks in advance.

0 Likes