Most of the time, the optimal approach to any API related task/workflow comes out of finding out the best approach of achieving the same using the product user interface (UI) and replicating the same using the API. For example, to change the diameter of an elbow fitting, creating a quick instance of an elbow fitting using Revit UI, shows us that the Nominal Diameter parameter is disabled/greyed out. The Nominal Radius parameter is however enabled and can be modified using the UI.
Taking clues from this, we now know that we should be attempting to modify the nominal radius of the elbow fitting using the API, as shown below:
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.HelloRevit.CS
{
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiApp = commandData.Application;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Transaction trans = new Transaction(uiDoc.Document);
trans.Start("ChangeDia");
// For simplicity, we have pre-selected the Elbow Fitting
foreach (Element elbowElement in uiDoc.Selection.Elements)
{
// Since elbow fitting is of FamilyInstance type,
FamilyInstance famInst = elbowElement as FamilyInstance;
if (null != famInst)
{
// Set the Nominal Radius, since Diameter was disabled
Parameter param = famInst.get_Parameter("Nominal Radius");
param.Set(3 * 0.08333);
}
}
trans.Commit();
return Result.Succeeded;
}
}
}
And the modified elbow fitting with the new radius is now reflected on the UI as well (however non-functional this might appear )