Revit .NET API follows the try/catch/finally pattern. Even for a can-not-be-too-simple method like InternalDefinition.SetAllowVaryBetweenGroups, try/catch block has to be always used; otherwise, the whole program logic may be broken due to the failure of the method call.
Another small matter is that the most important parameter related class InternalDefinition is still too simple. It does not has a boolean method like CanAllowVaryInGroups available. If it had, people could have used it quite ofter to check whether possible or necessary to set the property.
Finally, an extension method was worked out this way to save both hundreds of code lines and program reliability.
public static bool AllowVaryInGroups(this InternalDefinition def, RvtDocument doc, bool canVary)
{
try
{
def.SetAllowVaryBetweenGroups(doc, canVary);
return true;
}
catch { return false; }
}
By the way, the original SetAllowVaryBetweenGroups method also returns something but not so clear or useful. Not sure if any programmers had really used it in any way!
// Returns:
// The ids of elements that were updated to align the values between groups.
Another fact is that the method throws out exceptions in various situations even if for those very common ones such as Argument Null and Modification Outside Transaction. The only necessary catch case is the ModificationForbiddenException actually!
Feel free to use the extension method if you like it. Enjoy!