I wrote a script in C# to go through and optimize fabrication part lengths in Revit and am very interested in what Dynamo has to offer. I’ve tried with no success moving what I have in C# to a custom Dynamo node. I hoping some python coders here can help me move what I have into python. Here is what I have in C#. Thanks in advance.
Document doc = commandData.Application.ActiveUIDocument.Document;
UIDocument uidoc = commandData.Application.ActiveUIDocument;
ICollection<ElementId> collection = col.WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_FabricationParts).ToElementIds();
if (collection.Count > 0)
ISet<ElementId> selIds = newHashSet<ElementId>();
foreach (ElementId id in collection)
using (Transaction tr = newTransaction(doc, “Optimize Straights”))
// optimize lengths method will take a set of elements and any fabrication straight parts
// within this set that have been optimized will be returned.
ISet<ElementId> affectedPartIds = FabricationPart.OptimizeLengths(doc, selIds);
if (affectedPartIds.Count ==