Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

why “Modify parameters” returns null for newly created Structural Connection?

arvind.maurya37
Contributor

why “Modify parameters” returns null for newly created Structural Connection?

arvind.maurya37
Contributor
Contributor

Using Revit API 2019 and Advance Steel API 2019

I have simple task to connect a beam and column with the Structural Connection (Clip angle) and update its Modify Parameters.

I am able to create a connection between beam and column with Structural Connection (Clip angle) but when i go to modify the Parameters of newly created Structural Connection it gives null

below code to create a connection and modify it

    StructuralConnectionHandler structuralConnectionHandler = null;
        using (Transaction transaction = new Transaction(uidoc.Document, "Create detailed structural connection"))
        {
                    List<ElementId> elemIds = new List<ElementId>();
                    // retrive element from document

                    foreach (int id in selectedIDs)                   
                        elemIds.Add(doc.GetElement(new ElementId(id)).Id);

                    // The type is from the SteelConnectionsData.xml file.
                    StructuralConnectionHandlerType connectionType = StructuralConnectionHandlerType.Create(uidoc.Document, "usclipangle", new Guid("A42C5CE5-91C5-47E4-B445-D053E5BD66DB"), "usclipangle");

                    if (elemIds.Count() > 0 && connectionType != null)
                    {
                        //using (SubTransaction subTransaction = new SubTransaction(uidoc.Document))
                        //{
                        //    subTransaction.Start();
                            structuralConnectionHandler = StructuralConnectionHandler.Create(uidoc.Document, elemIds, connectionType.Id);
                        //    subTransaction.Commit();
                        //}
                        uidoc.Document.Regenerate();
                    }
                    else
                    {
                        message = "There is no element selected!";
                        ret = Result.Failed;
                    }
             TransactionStatus ts = transaction.Commit();
    }   

       // uidoc.Document.Save();  // tried to save document automatically but gives wired exception eg. Autodesk.Internal Exception

        bool modifyParameters = true// would be setting its value while debug.
        if (modifyParameters)
        {
            // Start detailed steel modeling transaction
            using (FabricationTransaction trans = new FabricationTransaction(doc, true, "Update connection parameters"))
            {
                AdvSteel.FilerObject filerObject = Functions.GetFilerObject(uidoc.Document, new Reference(structuralConnectionHandler));

        //filerObject object is null always
            // this piece of code works independently
                if (null == filerObject || !(filerObject is UserAutoConstructionObject))
                    return  Result.Failed; 

                UserAutoConstructionObject asConnection = (UserAutoConstructionObject)filerObject;

                //read connection parameters
                IFiler connectionFiler = asConnection.Save();

                if (connectionFiler != null)
                {
                    //I choose to modify thickess of the base plate
                    connectionFiler.WriteItem(Convert.ToDouble(50.0), "BaseThickness"); //units must be milimmeters; 
                    asConnection.Load(connectionFiler); //update connection parameters
                    asConnection.Update();
                    //
                    //if the connection parameters are modified, than we have to set this flag to true,
                    //meaning that this connection has different parameters than it's connection type.


                    // not avaliabe in revit 2019
                    //rvtConnection.OverrideTypeParams = true;


                    // not avaliabe in revit 2019
                    /// trans.Commit();
                }
            }

        }

Tried So far:

Tried to commit in sub-transaction.

Tried to save the document after commit.

went through below link

Revit Dynamo: revit-api-access-to-structural-connection-parameters

Autodesk Revit API: accessing-detailed-parameters-in-a-structural-steel-connection

Any help or hint would be appreciated!

0 Likes
Reply
Accepted solutions (1)
2,218 Views
18 Replies
Replies (18)

RPTHOMAS108
Mentor
Mentor

I don't see where the main transaction is started does not follow pattern below:

 

 using (Transaction Tx = new Transaction(D, "Name"))
            {
                if (Tx.Start() == TransactionStatus.Started)
                {
                    //Something that warrants transaction here
                    Tx.Commit();
                }
            }
 

This may not be the reason and you should have got Transaction not started exception when you tried to commit it.

 

You don't need to call Regenerate as this should be internally called after a Transaction/SubTranaction. Saving the document just saves to file so wouldn't help prevent the null.

0 Likes

arvind.maurya37
Contributor
Contributor

I just missed to start transaction in the sample code but in real one it is there.

       StructuralConnectionHandler structuralConnectionHandler = null;
        using (Transaction transaction = new Transaction(uidoc.Document, "Create detailed structural connection"))
        {
                    transaction.Start();
                    List<ElementId> elemIds = new List<ElementId>();
                    // retrive element from document

                    foreach (int id in selectedIDs)                   
                        elemIds.Add(doc.GetElement(new ElementId(id)).Id);

                    // The type is from the SteelConnectionsData.xml file.
                    StructuralConnectionHandlerType connectionType = StructuralConnectionHandlerType.Create(uidoc.Document, "usclipangle", new Guid("A42C5CE5-91C5-47E4-B445-D053E5BD66DB"), "usclipangle");

                    if (elemIds.Count() > 0 && connectionType != null)
                    {
                        //using (SubTransaction subTransaction = new SubTransaction(uidoc.Document))
                        //{
                        //    subTransaction.Start();
                            structuralConnectionHandler = StructuralConnectionHandler.Create(uidoc.Document, elemIds, connectionType.Id);
                        //    subTransaction.Commit();
                        //}
                        uidoc.Document.Regenerate();
                    }
                    else
                    {
                        message = "There is no element selected!";
                        ret = Result.Failed;
                    }
             TransactionStatus ts = transaction.Commit();
    }   

       // uidoc.Document.Save();  // tried to save document automatically but gives wired exception eg. Autodesk.Internal Exception

        bool modifyParameters = true// would be setting its value while debug.
        if (modifyParameters)
        {
            // Start detailed steel modeling transaction
            using (FabricationTransaction trans = new FabricationTransaction(doc, true, "Update connection parameters"))
            {
                AdvSteel.FilerObject filerObject = Functions.GetFilerObject(uidoc.Document, new Reference(structuralConnectionHandler));

        //filerObject object is null always
            // this piece of code works independently
                if (null == filerObject || !(filerObject is UserAutoConstructionObject))
                    return  Result.Failed; 

                UserAutoConstructionObject asConnection = (UserAutoConstructionObject)filerObject;

                //read connection parameters
                IFiler connectionFiler = asConnection.Save();

                if (connectionFiler != null)
                {
                    //I choose to modify thickess of the base plate
                    connectionFiler.WriteItem(Convert.ToDouble(50.0), "BaseThickness"); //units must be milimmeters; 
                    asConnection.Load(connectionFiler); //update connection parameters
                    asConnection.Update();
                    //
                    //if the connection parameters are modified, than we have to set this flag to true,
                    //meaning that this connection has different parameters than it's connection type.


                    // not avaliabe in revit 2019
                    //rvtConnection.OverrideTypeParams = true;


                    // not avaliabe in revit 2019
                    /// trans.Commit();
                }
            }

        }
0 Likes

Anonymous
Not applicable

Hi Arvind,

 

Do you get resolution for this stuff. I am also facing same issue. If Yes please let me know as well.

 

Thanks,

Freelizer

 

0 Likes

arvind.maurya37
Contributor
Contributor

Hi @Anonymous 

I just upgraded to Revit API  2020 from 2019

over there it is working fine.

 

0 Likes

LucasJonnedeJong
Enthusiast
Enthusiast

Hey @arvind.maurya37 

 

Any chance you can share with me your references and "using" lines?  My GetFilerObject keeps returning null.

 

Thanks!

0 Likes

LucasJonnedeJong
Enthusiast
Enthusiast

I got it working in a Revit Addin, but I am trying to get it working inside of a Dynamo Zero-Touch-Node. Any reason why my GetFilerObject returns null inside a Zero-Touch-Node? Any help is greatly appreciated
@jeremy_tammik maybe?

0 Likes

LucasJonnedeJong
Enthusiast
Enthusiast

 

Here is my code for those who would not mind to have a quick glance at it, mostly (if not all) copied from the sdk sample.  Anyone, please?

using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using RevitServices.Persistence;
using RevitServices.Transactions;
using Revit.Elements;
using System.Collections.Generic;
//using Element = Autodesk.Revit.DB.Element;
//using Element = Revit.Elements.Element;
using System;
using System.Linq;
using System.Diagnostics;
using Autodesk.Revit.UI.Selection;
using Autodesk.AdvanceSteel.CADAccess;
using Autodesk.AdvanceSteel.Geometry;
using Autodesk.AdvanceSteel.Modelling;
using RvtDwgAddon;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI;
using Autodesk.AdvanceSteel.ConstructionTypes;
using Autodesk.AdvanceSteel.DocumentManagement;
using DocumentManager = Autodesk.AdvanceSteel.DocumentManagement.DocumentManager;
using Autodesk.Revit.DB.Steel;

namespace ZeroTouchNodes
{
    public class SteelConnectionParameters
    {
        private SteelConnectionParameters() { }

        public static string Get(Revit.Elements.Element element, string param)
        {
            
            Autodesk.Revit.DB.Document doc = RevitServices.Persistence.DocumentManager.Instance.CurrentDBDocument;
            
            Autodesk.Revit.DB.Element elem = element.InternalElement;
            StructuralConnectionHandler SteelConnection = elem as StructuralConnectionHandler;
            Reference eRef = new Reference(SteelConnection);
            //FilerObject filerObj = null;
            Autodesk.AdvanceSteel.DocumentManagement.Document curDocAS = DocumentManager.GetCurrentDocument();
            OpenDatabase currentDatabase = curDocAS.CurrentDatabase;
            Guid guid = SteelElementProperties.GetFabricationUniqueID(doc, eRef);
            string asHandle = currentDatabase.getUidDictionary().GetHandle(guid);


            FilerObject filerObj = FilerObject.GetFilerObjectByHandle(asHandle);  //keeps returning null

            UserAutoConstructionObject asConnection = (UserAutoConstructionObject)filerObj;
            IFiler connectionFiler = asConnection.Save();
            object paramvalue = connectionFiler.ReadItem(param);
                
            
            return paramvalue.ToString();
        }
    }
}
0 Likes

jeremy_tammik
Autodesk
Autodesk

Can you isolate the problem and create a complete minimal reproducible case for the development team to analyse? 

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

Are you on Revit 2022 or an earlier version?

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

jeremy_tammik
Autodesk
Autodesk

I went ahead and asked the development team for you... let's wait and see what they suggest first.

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

vlad_pavel
Autodesk
Autodesk

you should create a fabrication transaction in order to open a steel object 

 

using (FabricationTransaction trans = new FabricationTransaction(doc, false, "Test"))
{
     FilerObject filerObj = FilerObject.GetFilerObjectByHandle(asHandle);
.....
}

You can more examples on how to use it in the samples from the Revit SDK packages.

0 Likes

LucasJonnedeJong
Enthusiast
Enthusiast

Thank you @vlad_pavel 

I had just last night come accross a comment of someone saying this, and have made some progress since.  Unfortunately I am encountering new problems:

When I set the readonly bool to 'true' 

new FabricationTransaction(doc, true, "Test")

I can now extract the parameter values.    So that is a win for now.  Then of course I want to edit the parameters also, like it was done in the SDK sample. 
When I leave the boolean on 'true' and try to write, load and update the UserAutoConstructionObject, Revit crashes.

When I set it to 'false' I get the error message that I can not start a new transaction.  I feel like when I solve that issue, I made it to the finish.  Pleas advise!

 

Below the code that gives me the error.  Please remember this is not in an external command, but in a zero-touch-node:

 

using Autodesk.Revit.DB;
using System;
using Autodesk.AdvanceSteel.CADAccess;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI;
using Autodesk.AdvanceSteel.DocumentManagement;
using DocumentManager = Autodesk.AdvanceSteel.DocumentManagement.DocumentManager;
using Autodesk.Revit.DB.Steel;
using RvtDwgAddon;
using Autodesk.AdvanceSteel.ConstructionTypes;

namespace ZeroTouchNodes
{
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
    [Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
    public class SteelConnectionParameters // : IExternalCommand
    {
        private SteelConnectionParameters() { }
        public static double Get(Revit.Elements.Element element, string param)
        {

            Autodesk.Revit.DB.Document doc = RevitServices.Persistence.DocumentManager.Instance.CurrentDBDocument;
            object paramvalue = null;

            using (FabricationTransaction trans = new FabricationTransaction(doc, false, "Update connection parameters"))
            {
                Autodesk.Revit.DB.Element elem = element.InternalElement;
                StructuralConnectionHandler SteelConnection = elem as StructuralConnectionHandler;
                Reference eRef = new Reference(SteelConnection);

                FilerObject filerObj = null;
                Autodesk.AdvanceSteel.DocumentManagement.Document curDocAS = DocumentManager.GetCurrentDocument();
                OpenDatabase currentDatabase = curDocAS.CurrentDatabase;
                Guid guid = SteelElementProperties.GetFabricationUniqueID(doc, eRef);
                string asHandle = currentDatabase.getUidDictionary().GetHandle(guid); 
                
                StructuralConnectionHandler rvtConnection = (StructuralConnectionHandler)elem;
                
                
                filerObj = FilerObject.GetFilerObjectByHandle(asHandle);  //keeps returning null

                UserAutoConstructionObject asConnection = (UserAutoConstructionObject)filerObj;
                IFiler connectionFiler = asConnection.Save();
                paramvalue = connectionFiler.ReadItem(param);
                connectionFiler.WriteItem(Convert.ToDouble(100.0), "BaseThickness");
                asConnection.Load(connectionFiler); //update connection parameters
                asConnection.Update();

                rvtConnection.OverrideTypeParams = true;

                trans.Commit(); 
            }

            return (double)paramvalue;
        }




    }
}

lucasdejongPTZ3P_0-1629812390524.png

 

 

0 Likes

vlad_pavel
Autodesk
Autodesk
Accepted solution

Looks like In dynamo for Revit there are special mechanisms that handle the revit&steel transactions. In zero touch nodes with advance steel API you should use DocContext class from AdvanceSteelServices.dll from [Revit.exe path]\Addins\DynamoForRevit\Revit\nodes\steel-pkg\bin\ . For revit pure API you should use RevitServices.Transactions.TransactionManager.Instance.EnsureInTransaction from RevitServices.dll.

 

So, for steel transactions in dynamo for Revit please replace

 

using(FabricationTransaction trans = new Fabrication...)

{

   trans.commit()

 

with

using (var ctx = new Dynamo.Applications.AdvanceSteel.Services.DocContext())

{

}

 

 

LucasJonnedeJong
Enthusiast
Enthusiast

@vlad_pavel I am so happy, you made my day!  It worked perfectly! 

 

I want to mark your answer as Solution, but I don't think I am authorized to (at least I cannot find a way).  Can someone else please? (@jeremy_tammik maybe?)

 

Now, I have one more question:    How did you gain this knowledge?   Did you figure it out?   Is there a course I can take?  A book I should read?  A website I should be aware of?

Thanks a thousand!

0 Likes

jeremy_tammik
Autodesk
Autodesk

I accepted Vlad's answer as a solution for you.

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open

jeremy_tammik
Autodesk
Autodesk

Rather belatedly, to answer your other question,  Vlad is an Autodesk employee, and his title is Sr. Principal Engineer in the AEC Design-BID-Buildings department; hence, I assume he is privy to sources inaccessible to mere mortals like you and me 🙂

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

vlad_pavel
Autodesk
Autodesk

The code of Dynamo-Revit is open source and there I've found how to use the transactions in zero touch nodes. For example this class creates a Wall: https://github.com/DynamoDS/DynamoRevit/blob/master/src/Libraries/RevitNodes/Elements/Wall.cs . Unfortunately we don't have yet any official documentation for this feature

0 Likes

jeremy_tammik
Autodesk
Autodesk

Cool! Thank you very much for clarifying. That helps others to discover more undocumented features and answer their own questions. Better teach a man to fish than to feed him, isn't it?

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

jeremy_tammik
Autodesk
Autodesk

Thank you for the fruitful discussion! Edited and preserved for posterity on the blog:

 

https://thebuildingcoder.typepad.com/blog/2021/09/view-sheet-from-view-and-select-all-on-level.html#...

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open