I was just wondering if anyone knows if the “special” parameters in structural connections are possible to set/get with the Revit API? Or does possibly the Structural connection addin have its own API accessible in one way or the other? I couldn’t find any with my sparse API knowledge.
Looks like they are stored in Autodesk.Revit.DB.ExtensibleStorage, and they can be accessed like shown in this sample from the SDK called GenericStructuralConnection:
/// <summary>
/// Match properties for detailed structural connections.
/// </summary>
/// <param name="activeDoc">The active document.</param>
/// <param name="message">Set message on failure.</param>
/// <returns>Returns the status of the operation.</returns>
public static Result MatchPropertiesDetailedStructuralConnection(UIDocument activeDoc, ref string message)
{
Result ret = Result.Succeeded;
// Prompt to select a structural connection
StructuralConnectionHandler srcConn = StructuralConnectionSelectionUtils.SelectConnection(activeDoc);
StructuralConnectionHandler destConn = StructuralConnectionSelectionUtils.SelectConnection(activeDoc);
if (srcConn != null && destConn != null)
{
using (Transaction tran = new Transaction(activeDoc.Document, "Match properties"))
{
tran.Start();
// Do the properties match.
Schema masterSchema = GetSchema(activeDoc.Document, srcConn);
Entity masterEnt = srcConn.GetEntity(masterSchema);
// You could also access and modify the connection parameters.
IList<Field> fields = masterSchema.ListFields();
foreach (Field field in fields)
{
if (field.ValueType == typeof(string))
{
IList<string> parameters = masterEnt.Get<IList<string>>(field);
foreach (string str in parameters)
{
// Do something.
}
}
}
destConn.SetEntity(masterEnt);
TransactionStatus ts = tran.Commit();
if (ts != TransactionStatus.Committed)
{
message = "Failed to commit the current transaction !";
ret = Result.Failed;
}
}
}
else
{
message = "There must be two connections selected !";
ret = Result.Failed;
}
return ret;
}
You need this as well:
/// <summary>
/// Get the Extensible storage schema
/// </summary>
private static Schema GetSchema(Document doc, StructuralConnectionHandler connection)
{
Schema schema = null;
Guid guid = GetConnectionHandlerTypeGuid(connection, doc);
if (guid != null && guid != Guid.Empty)
schema = Schema.ListSchemas().Where(x => x.GUID == guid).FirstOrDefault();
return schema;
}
/// <summary>
/// Get the unique identifier of the structural steel connection type
/// </summary>
/// <param name="conn">structural connection</param>
/// <param name="doc">current document</param>
/// <returns>returns the unique identifier of the input connection type</returns>
private static Guid GetConnectionHandlerTypeGuid(StructuralConnectionHandler conn, Document doc)
{
if (conn == null || doc == null)
return Guid.Empty;
ElementId typeId = conn.GetTypeId();
if (typeId == ElementId.InvalidElementId)
return Guid.Empty;
StructuralConnectionHandlerType connType = (StructuralConnectionHandlerType)doc.GetElement(typeId);
if (connType == null || connType.ConnectionGuid == null)
return Guid.Empty;
return connType.ConnectionGuid;
}
Einar what are this two sets of code? Ready script for node? Could you give a pro tip for dummies how to use them in dynamo? I’m ready to sell my wife, children and kidney to get it
Jostein is 100% right - steel connections in Revit are useless witthout API access
The code is taken from a Revit Add-in sample which can be compiled and run as a commamd from the ribbon. It is possible to rewrite it to python, and it can be simplified a lot.
Hi there, In my c# project StructuralConnectionSelectionUtils function isn’t recognized. Should be due to the references. I saw in the python code that you’ve imported ‘RevitNodes’ and ‘RevitServices’ referances.
I couldn’t find those references. Where are those references stored so I can include them in my project? Can you please help? Thank you!
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 43, in
Exception: The input argument “schema” of function Autodesk::Revit::Proxy::DB::ElementProxy::GetEntity or one item in the collection is null at line 1287 of file d:\ship\2019_px64\source\revit\revitdbapi\gensrc\APIElementProxy.cpp.
Parameter name: schema
I select the connection element in Revit and I can retrieve the guid, but the problem is Schema.Lookup function returns null. I’ve tried it on other connection types as well. They all return null.
I have the same problem. I tried both dynamo and Revit API with visual studio addin but no luck.
Every time, program throws error like yours. Did you find any solution?
One workaround is to wrap the detailed/parameteric connection in a custom one and update in “Edit Custom Connection Type” mode. When you hit finish all the connections of that type is updated.
I’m not completely sure that addresses the same problem, but the Revit SDK samples do in fact include a small sample that shows how to read and update detailed parameters for a steel connection in Revit; you can find it here: