- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to access the parameters of a structural sub connection. When using the cope tool from the Steel menu, it creates a connection that is really a subconnection, and I would like to automate zeroing out the coping offset values in these subconnections project wide.
I can access the connections in my project but the code for getting the schema are not working, prolly cause its really a subconnection. I am unsure, can anyone assist please?
public void FramingCopingZeroOffsets()
{
UIDocument uidoc = this.ActiveUIDocument;
Document doc = uidoc.Document;
Autodesk.Revit.DB.View activev = doc.ActiveView;
using (Autodesk.Revit.DB.Transaction t = new Autodesk.Revit.DB.Transaction(doc, "FramingCopingZeroOffsets"))
{
t.Start();
string conname = "Cope";
FilteredElementCollector con = new FilteredElementCollector(doc);
con.OfCategory(BuiltInCategory.OST_StructSubConnections);
var cons = from element in con where element.Name.Contains(conname) select element;
List<Element> conslist = cons.ToList();
string ename = "";
string eid = "";
string etid = "";
string info = "";
StructuralConnectionHandler srcConn = null;
foreach (Element el in conslist)
{
// Weed out types from instances
try
{
StructuralConnectionHandlerType scht = el as StructuralConnectionHandlerType;
etid = scht.Id.ToString();
ename = el.Name.ToString();
eid = el.Id.ToString();
info = ename + " et= " + etid + " e= " + eid;
TaskDialog.Show("Revit try", info);
}
catch
{
ElementId typeid = el.GetTypeId();
Element typeelem = doc.GetElement(typeid);
StructuralConnectionHandlerType scht = typeelem as StructuralConnectionHandlerType;
etid = scht.Id.ToString();
ename = el.Name.ToString();
eid = el.Id.ToString();
info = ename + " et= " + etid + " e= " + eid;
TaskDialog.Show("Revit catch", info);
srcConn = el as StructuralConnectionHandler;
TaskDialog.Show("Revit coname" , srcConn.Name.ToString());
Schema masterSchema = GetSchema(doc, srcConn);
Entity masterEnt = srcConn.GetEntity(masterSchema);
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)
{
// Modify the Params
TaskDialog.Show("Revit " , str);
}
}
}
}
}
//TaskDialog.Show("Revit list", conslist.Count.ToString());
doc.Regenerate();
t.Commit();
}
}
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;
}
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;
}
A screenshot of the UI equivalent situation
Solved! Go to Solution.