Hey Jacob- I’ve moved over to Galloway now - trying to do some light development to export and reimport line weights for Revit. Wanted to make a node but am quickly heading towards an addin.
I have the base code and am trying to create a zero touch node to put out but I keep getting FUNCITON as output in Revit 2025 Dynamo. Tried numerous castings, etc. but no dice.
If I shared the project on GIT - would anyone have any suggestions on how to get the nodes to output a flat list? Or have zero touch been retired by Dynamo and Autodesk Revit?
Even peeling though the sites above - and looking for previous design script references for 25… I cannot find anything to cast it to an actual flat list.
and the codes/refs:
using Autodesk.DesignScript.Runtime;
using Autodesk.Revit.DB;
using RevitServices.Persistence;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace RonAllen_Lib.LineWeights
{
public static class LineWeightNodes
{
/// <summary>
/// Exports line weights as a list of strings (e.g., "1,1,0.1").
/// </summary>
/// <param name="doc">Revit document (optional; uses current document if null).</param>
/// <returns>List of formatted strings: "Scale,Index,Value".</returns>
[IsVisibleInDynamoLibrary(true)]
public static List<string> ExportLineWeights(Document doc)
{
if (doc == null)
doc = DocumentManager.Instance.CurrentDBDocument;
var lwData = GetLineWeights(doc);
var result = lwData.Select(lw => $"{lw.Scale},{lw.Index},{lw.Value}").ToList();
return result;
}
/// <summary>
/// Imports line weights from a flat list of strings (e.g., "1,1,0.1").
/// </summary>
/// <param name="doc">Revit document (optional; uses current document if null).</param>
/// <param name="lineWeightData">List of strings to import.</param>
[IsVisibleInDynamoLibrary(true)]
public static void ImportLineWeights(Document doc, List<string> lineWeightData)
{
if (doc == null)
doc = DocumentManager.Instance.CurrentDBDocument;
if (lineWeightData == null || lineWeightData.Count == 0)
throw new ArgumentException("Line weight data list is empty.");
var settings = doc.Settings;
var lwField = typeof(Settings).GetField("m_lineWeightsTable", BindingFlags.NonPublic | BindingFlags.Instance);
var lwTable = lwField.GetValue(settings);
var setMethod = lwTable.GetType().GetMethod("SetLineWeight", BindingFlags.NonPublic | BindingFlags.Instance);
using (Transaction trans = new Transaction(doc, "Import Line Weights from List"))
{
trans.Start();
foreach (var line in lineWeightData)
{
if (line.StartsWith("ScaleIndex")) continue;
var parts = line.Split(',');
int scale = int.Parse(parts[0]);
int index = int.Parse(parts[1]);
int value = int.Parse(parts[2]);
setMethod.Invoke(lwTable, new object[] { index, scale, value });
}
trans.Commit();
}
}
/// <summary>
/// Helper method to extract line weights from document.
/// </summary>
/// <param name="doc">Revit document.</param>
/// <returns>List of (Scale, Index, Value) tuples.</returns>
private static List<(int Scale, int Index, object Value)> GetLineWeights(Document doc)
{
var settings = doc.Settings;
var lwField = typeof(Settings).GetField("m_lineWeightsTable", BindingFlags.NonPublic | BindingFlags.Instance);
var lwTable = lwField.GetValue(settings);
var getMethod = lwTable.GetType().GetMethod("GetLineWeight", BindingFlags.NonPublic | BindingFlags.Instance);
var result = new List<(int Scale, int Index, object Value)>();
for (int scale = 1; scale <= 16; scale++)
{
for (int index = 1; index <= 16; index++)
{
var lwValue = getMethod.Invoke(lwTable, new object[] { index, scale });
result.Add((scale, index, lwValue));
}
}
return result;
}
}
}