Routing Preference with API - no UI

Routing Preference with API - no UI

Anonymous
Not applicable
1,535 Views
2 Replies
Message 1 of 3

Routing Preference with API - no UI

Anonymous
Not applicable

Can someone provide me with a clear cut code example of how to set routing preferences using the API only, nothing within the UI? I have googled it, I have looked in the docs, I have looked in the BuildingCoder blog. I have not found anything that works yet. I just need a working code example for C# and revit 2020. 

 

Thanks in advance.

0 Likes
Accepted solutions (1)
1,536 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Accepted solution

For anyone having this trouble, I solved it myself.

 

using (Transaction transaction = new Transaction(doc, "Routing Preference"))
            {
                transaction.Start();

                RoutingPreferenceManager routePrefManager = ductType.RoutingPreferenceManager;
                routePrefManager.PreferredJunctionType = PreferredJunctionType.Tap;

                int initRuleCount = routePrefManager.GetNumberOfRules(RoutingPreferenceRuleGroupType.Junctions);

                for (int i = 0; i != initRuleCount; ++i)
                {
                    routePrefManager.RemoveRule(RoutingPreferenceRuleGroupType.Junctions, 0);
                }
                
                Family tapFam = null;
                FamilySymbol symbol = null;
                string path =
                    @"C:\ProgramData\Autodesk\RVT 2020\Libraries\US Imperial\Duct\Fittings\Round\Taps\Round Takeoff.rfa";
                doc.LoadFamily(path, out tapFam);

                ISet<ElementId> familySymbolIds = tapFam.GetFamilySymbolIds();
                ElementId id = familySymbolIds.ElementAt(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");
                routePrefManager.AddRule(RoutingPreferenceRuleGroupType.Junctions, newRule);

                transaction.Commit();
                
            }
Message 3 of 3

Andrej.Licanin
Advocate
Advocate

Thank you Anon

0 Likes