RevitAPI: FamilyManager.Set – InvalidOperationException and get members from AssemblyInstance

中文链接

By Aaron Lu

Q: Would you please confirm it is not allowed to set value family parameter if there is no type?

In Family Editor, when calling FamillyManager.Set(FamilyParameter), it will throw InvalidOperationException: There is no current type

the code looks like this:

var para = RevitDoc.FamilyManager.AddParameter("Length", BuiltInParameterGroup.INVALID, ParameterType.Length, false);
RevitDoc.FamilyManager.Set(para, 123.1);

It allows us to create “parameter” without any types, but not able to set value of parameters, because it should be meanless to set a parameter which is not belong to any type.

So, we should check if FamilyManager.CurrentType is null or not before calling “.Set” method.

if (familyMgr.CurrentType == null)
familyMgr.NewType("A new type");
var para = familyMgr.AddParameter("Length", BuiltInParameterGroup.INVALID, ParameterType.Length, false);
RevitDoc.FamilyManager.Set(para, 123.1);

Q: How to get elements which are part of a selected assembly?

As you may have already tried that RevitLookup did not show useful information of parts in an assembly you selected, but when you look at the methods of AssemblyInstance, you will see a set of methods related with its parts:

  • ICollection GetMemberIds();
  • void AddMemberIds(ICollection memberIds);
  • void RemoveMemberIds(ICollection memberIds);
  • void SetMemberIds(ICollection memberIds);

those methods allows to:

  • Get members of the assembly
  • Add more members into the assembly
  • Remove a set of members
  • Set a list of elements as its members

so easy now, use GetMemberIds()


Comments

One response to “RevitAPI: FamilyManager.Set – InvalidOperationException and get members from AssemblyInstance”

  1. I’d like to thank the author for writing such an insightful and informative blog post about revit family operations that is not just useful to the readers but also revealing.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading