GetElement returning null for a MaterialNode.MaterialId

GetElement returning null for a MaterialNode.MaterialId

pfk
Enthusiast Enthusiast
807 Views
11 Replies
Message 1 of 12

GetElement returning null for a MaterialNode.MaterialId

pfk
Enthusiast
Enthusiast

Hi

 

I have a plugin which works fine in Revit2020 to Revit 2024.  After upgrading to DotNet8 and recompiling for Revit 2025, I have the issue where GetElement is returning null for a MaterialNode.MaterialId.

 

For context, this code is running in an IExportContext class.

 

        public void OnMaterial(MaterialNode node)
        {
            try
            {
                if (node.MaterialId != ElementId.InvalidElementId)
                {
                    Element element = m_document.GetElement(node.MaterialId);                    
                    // ERROR - element is null in Revit 2025

 

How do I get this working in Revit 2025 please?

 

Thanks

 

Paul

0 Likes
808 Views
11 Replies
Replies (11)
Message 2 of 12

Moustafa_K
Collaborator
Collaborator

my best guess towards this, you are exporting a linked element that has a material. with that said, material Id is part of the linked project, which is likely correct to be null. see if that trigger something. 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 3 of 12

pfk
Enthusiast
Enthusiast

Thanks Moustafa

 

Yes, that is probably the issue.  In that case, how do you get the material from the linked element please?

 

Thanks

 

Paul

 

 

0 Likes
Message 4 of 12

Moustafa_K
Collaborator
Collaborator

you can use the method OnLinkBegin, and extract which document that is currently being exported. store this document in a variable, and then use it in the OnMaterial Method. it is better that when you are done, use OnLinkEnd Method to set the document variable, you just created, as null, 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 5 of 12

pfk
Enthusiast
Enthusiast

I am already doing that...

 

 

        public RenderNodeAction OnLinkBegin(LinkNode node)
        {
            try
            {

                // We can get more information about the family instance and 
                ElementId symbolId = node.SymbolId;
                m_document = node.GetDocument();
                m_DocumentStack.Push(m_document);
                                m_TransformationStack.Push(m_TransformationStack.Peek().Multiply(node.GetTransform()));
            }
            catch (Exception ex)
            {
                // do something
            }
            
            return RenderNodeAction.Proceed;

        }

        public void OnLinkEnd(LinkNode node)
        {
            m_TransformationStack.Pop();
            m_document = m_DocumentStack.Pop();
        }

 

The file causing issues is the demo architecture file (Snowdon Towers)

 

Thanks

 

Paul

 

0 Likes
Message 6 of 12

pfk
Enthusiast
Enthusiast

Does anyone have any answers for this please?

 

Thanks

 

Paul

0 Likes
Message 7 of 12

jeremy_tammik
Alumni
Alumni

I asked the development team for you.

   

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

pfk
Enthusiast
Enthusiast

Thanks @jeremy_tammik .  I cannot log into that Slack link, so if a response could be posted on this forum thread, that would be awesome.

 

Paul

0 Likes
Message 9 of 12

jeremy_tammik
Alumni
Alumni

Yup. That is an internal link to help me keep track of it for you.

  

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

jeremy_tammik
Alumni
Alumni

The development team discussed this and reply: Maybe the material element is not found due to some sort of a common cause? If this is indeed caused just by upgrading to Revit 2025, then it could be a regression. If the material is from a link, is it possible this code needs to get the linked document and then do a GetElement() on the linked document? I don't know why it would have changed in 2025 though. We are not aware of any issues, though. We have implemented improvements in the internal development version when importing linked files to Revit to check materials with duplicated names, but they have not been integrated into the released version. As a first step, I suggest to open the linked file separately and check if the material with the specific ID really exists there.

   

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

pfk
Enthusiast
Enthusiast

Thanks @jeremy_tammik .  The file producing this issue is the demo architecture file (Snowdon Towers) - so it is a file that your dev team have access to.  It is happening with Revit 2024 too.

 

Paul

0 Likes
Message 12 of 12

jeremy_tammik
Alumni
Alumni

Thank you for clarifying,. I passed it on.

   

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