This is the code I came up with:
public void UpdateLeaders()
{
UIDocument uidoc = this.ActiveUIDocument;
Document doc = uidoc.Document;
// create a collection of all the Arrowhead types
ElementId id = new ElementId(BuiltInParameter.ALL_MODEL_FAMILY_NAME);
ParameterValueProvider provider = new ParameterValueProvider(id);
FilterStringRuleEvaluator evaluator = new FilterStringEquals();
FilterRule rule = new FilterStringRule(provider, evaluator, "Arrowhead", false);
ElementParameterFilter filter = new ElementParameterFilter(rule);
FilteredElementCollector collector2 = new FilteredElementCollector(doc).OfClass(typeof(ElementType)).WherePasses(filter);
ElementId arrowheadId = null;
// loop through the collection of Arrowhead types and get the Id of a specific one
foreach(ElementId eid in collector2.ToElementIds())
{
if(doc.GetElement(eid).Name == "Arrow Filled 30 Degree") //change the name to the arrowhead type you want to use
{
arrowheadId = eid;
}
}
// create a collection of all families
List<Family> families = new List<Family>(new FilteredElementCollector(doc).OfClass(typeof(Family)).Cast<Family>());
using(Transaction t = new Transaction(doc, "Update Leaders"))
{
t.Start();
// loop through all families and get their types
foreach(Family f in families)
{
FamilySymbolSet symbols = f.Symbols;
List<FamilySymbol> symbols2 = new List<FamilySymbol>(symbols.Cast<FamilySymbol>());
// loop through the family types and try switching the parameter Leader Arrowhead to the one chosen above
// if the type doesn't have this parameter it will skip to the next family type
foreach(FamilySymbol fs in symbols2)
{
try
{
fs.get_Parameter(BuiltInParameter.LEADER_ARROWHEAD).Set(arrowheadId);
}
catch
{
}
}
}
t.Commit();
}
}
Could we do the same with Font?
ReplyDeleteI've been on may projects where the client standard font is not Arial. This would save a heck of a lot of time.
Justin, I'll see if I can come up with a macro to do fonts.
ReplyDeleteThat would be great Troy.
ReplyDeleteLook forward to your findings.
Hi, Thank you for the code. Mai I ask how to insert to macro i'm trying but there's always an error
ReplyDeleteThanx very much to this code. But may ask why theres always an error when i insert to macro
ReplyDeleteYou need te load the richt package's in de head of your code
ReplyDeleteusing System;
using System.Collections.Generic;
using System.Collections;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Data;
using System.ComponentModel;
using System.Collections.ObjectModel;
Hi
ReplyDeleteI tried to use this and create a macro in Revit 2015, but it complains about some old stuff.
I have no idea of how to change the macro to get it to work with 2015-version.
Are you in the mood for some macro update?
:-)
Ulf, the only obsolete code in the macro is the following line:
ReplyDeleteFamilySymbolSet symbols = f.Symbols;
But it will still run in 2015. It will need to be fixed for 2016 as that will no longer work.
How can we find the Tags that have nothing assigned only?
ReplyDeleteHi,
ReplyDeleteThanks for sharing macro its great. Can we use this macro to change font? Do you have any macro that can change font also.
hi , Thanks for sharing this code but how to definition for "ActiveUIDocument" ?
ReplyDeleteHi , Thanks for sharing this macro code but how to definition for 'ActiveUIDocument' ?
ReplyDelete