Structural Sub Connection Parameters

Structural Sub Connection Parameters

arautio
Advocate Advocate
1,398 Views
4 Replies
Message 1 of 5

Structural Sub Connection Parameters

arautio
Advocate
Advocate

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

Revit Struc Conn Params.jpg

0 Likes
Accepted solutions (1)
1,399 Views
4 Replies
Replies (4)
Message 2 of 5

matthias.deisboeck
Contributor
Contributor

Hello arautio, 

you can not  change the parameters of StructuralConnectionHandlers with the Revit API.

You have to use AdvanceSteel API. Getting the StructuralConnectionHandler there works with this code.

 

 

var steelProperties = SteelElementProperties.GetSteelElementProperties(element);
if (steelProperties != null)
{
     var asDocument = DocumentManager.GetCurrentDocument();
     if (asDocument != null)
     {
         var asDatabase = asDocument.CurrentDatabase;
         if (asDatabase != null)
         {
             var guid = steelProperties.UniqueID;
             var uidDictionary = asDatabase.getUidDictionary();
             var asHandle = uidDictionary.GetHandle(guid);
             var filerObject = FilerObject.GetFilerObjectByHandle(asHandle);

return filerObject; } } }

You can cast the filerObject into an IJoint or UserAutoConstructionObject.

 

From there use 

 

 

using Autodesk.AdvanceSteel.CADAccess;
using Autodesk.AdvanceSteel.ConstructionTypes;
using RvtDwgAddon;

// ...

using var ftr = new FabricationTransaction(doc, false, "Match property", true);
// ....
var filer = joint.Save(); var parameters = filer.GetItems(); // this Dictionary shows parameters and values. filer.WriteItem( <parameterName>, <parameterValue> ) // set parameter, be carefull to use the right type (int, double, ...) joint.Load(filer); joint.Update();

ftr.Commit()

 

 

AdvanceSteel Dlls can be found here

C:\Program Files\Autodesk\Revit 2020\AddIns\SteelConnections\

 

The only downside is to make this work you have to set the OverrideTypeParams of the StructuralConnectionHandler to true. So you can not make different types of one Handler....

 

Best regards

Matthias

 

 

0 Likes
Message 3 of 5

arautio
Advocate
Advocate

Matthias,  Thank you! that put me on the right track.

 

I was finally able to get to the parameters and read them.

I re-write them using the filer.WriteItem, and when I re-populate the parameters list it shows the updated values, so it's working to this point.

 

Problem is at the end, when I try to use joint.Load(filer);   or joint.SaveData(); or joint.UpdateDrivenConstruction();  Revit Crashes to the Desktop when these are un-commented.

I am assuming the only way to save the changes is with one of these lines??

 

Something to do with my transaction line??  I had to change the first bool to true to get it to run.

 

Anyway thanks again!

 

 

public void FramingCopingZeroOffsets2()
{    
    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();
        
    using (FabricationTransaction ftr = new FabricationTransaction(doc, true"FramingCopingZeroOffsets2"true))
    {    
        
        string conname = "Cope";
        
        FilteredElementCollector con = new FilteredElementCollector(doc);
        con.OfCategory(BuiltInCategory.OST_StructSubConnections);
        //con.OfCategory(BuiltInCategory.OST_StructConnections);
        
        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;

        Element elemen = 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
            {    
                elemen = el;
                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 CONNECTION NAME" , srcConn.Name.ToString());
                
                var asDoc = Autodesk.AdvanceSteel.DocumentManagement.DocumentManager.GetCurrentDocument();
                var asData = asDoc.CurrentDatabase;
                SteelElementProperties sprop = SteelElementProperties.GetSteelElementProperties(el);
                Guid guid = sprop.UniqueID;
                var uidDictionary = asData.getUidDictionary();
                var asHandle = uidDictionary.GetHandle(guid);
                FilerObject fob = FilerObject.GetFilerObjectByHandle(asHandle);
                
                IJoint joint = fob as IJoint;
    
                var filer = joint.Save();
                var parameters = filer.GetItems();  // this Dictionary shows parameters and values.
                string parms = parameters.Count.ToString();
                
                //TaskDialog.Show("Revit - Params Count", parms);
                //foreach (var par in parameters)
                //{
                    //TaskDialog.Show("Revit - Params Count", par.Value.ToString());
                    //TaskDialog.Show("Revit - Params Count", par.Key.ToString());
                //}
                
                double pval = 1;
                filer.WriteItem( pval, "InnerFlangeDistance");// set parameter, be carefull to use the right type (int, double, ...)
                filer.WriteItem( pval, "SideFlangeDistance");
                filer.WriteItem( pval, "WebDistance");
                
                //TaskDialog.Show("Revit", joint.Id.ToString());
                    
                //joint.SaveData(); //CRASHES REVIT IF TURNED ON
                //joint.Load(filer);  //CRASHES REVIT IF TURNED ON
                //joint.UpdateDrivenConstruction(); //CRASHES REVIT IF TURNED ON
                //TaskDialog.Show("Revit", "Here");
                }
            }
        
        //doc.Regenerate();
        //t.Commit();    
    }
}

0 Likes
Message 4 of 5

matthias.deisboeck
Contributor
Contributor
Accepted solution

I think the problem is the FabricationTransaction.

In your code you start a readOnly Transaction in an open Revit Transaction.

 

Hope this helps:

 public FabricationTransaction(Document doc, bool isReadOnly, string strName, bool bRevitTransactionAlreadyStarted);

You can find this in the metadata. (Use Go To Definition Command in Visual Studio).

 

Load and then UpdateDrivenConstruction should do the job.

And don't forget to also commit the FabricationTransaction.

 

 

Edit: 

To avoid type-problems I would write.

double pval = 1d;

 

Message 5 of 5

arautio
Advocate
Advocate

That did the trick,  thanks again!!

0 Likes