Hello everyone,
I’m trying to set the routing preferences for a new cable tray type in Revit 2022 using the Revit API. By "new," I mean that the type has just been created and does not yet have any routing preferences set — no elbows, tees, etc. I’m attempting to do this by following the same approach used for creating routing preferences for pipes, which works perfectly fine in that case, but the same approach does not seem to work with cable trays.
Specifically, it seems that the RoutingPreferenceManager object for the cable tray is null. Below is a code snippet and a screenshot from RevitLookup for reference.
Has anyone encountered this issue when trying to set routing preferences for cable trays? Or is this limitation related to the Revit API itself, meaning it’s impossible to set cable tray routing preferences via API without using the UI?
Any help or insight would be greatly appreciated!
Thank you in advance!
var trayType = (trayList.FirstOrDefault(x => (x as CableTrayType).FamilyName == "Кабельный лоток с соединительными деталями")) as CableTrayType;
var newCableTrayType = elementType.Duplicate(_userSettings.TrayTypeName);
using (Transaction transaction = new Transaction(doc, "Routing Preference"))
{
transaction.Start();
RoutingPreferenceManager routeManager = newCableTrayType.RoutingPreferenceManager;
routeManager.PreferredJunctionType = PreferredJunctionType.Tee;
int initRuleCount = routeManager.GetNumberOfRules(RoutingPreferenceRuleGroupType.Junctions);
for (int i = 0; i != initRuleCount; ++i)
{
routeManager.RemoveRule(RoutingPreferenceRuleGroupType.Junctions, 0);
}
symbol = tapFam.Document.GetElement(id) as FamilySymbol;
if ((!symbol.IsActive) && (symbol != null))
{
symbol.Activate();
doc.Regenerate();
}
RoutingPreferenceRule newRule = new RoutingPreferenceRule(symbol.Id, "Round Takeoff");
routeManager.AddRule(RoutingPreferenceRuleGroupType.Junctions, newRule);
transaction.Commit();
}
