Revit 2024 upgrade BuiltInParameterGroup.PG_MATERIALS

Revit 2024 upgrade BuiltInParameterGroup.PG_MATERIALS

Dale.Bartlett
Collaborator Collaborator
2,253 Views
5 Replies
Message 1 of 6

Revit 2024 upgrade BuiltInParameterGroup.PG_MATERIALS

Dale.Bartlett
Collaborator
Collaborator

Upgrading to Revit 2024. This has me stumped for the moment. I have a check for: BuiltInParameterGroup.PG_MATERIALS. What would this be in 2024?




______________
Yes, I'm Satoshi.
0 Likes
2,254 Views
5 Replies
Replies (5)
Message 2 of 6

jeremy_tammik
Alumni
Alumni

Please search for BuiltInParameterGroup in the Revit 2024 API news:

  

https://thebuildingcoder.typepad.com/blog/2023/04/whats-new-in-the-revit-2024-api.html

  

I just did, and I see a number of deprecated methods using it listed with their new replacement methods. That might provide a good starting point for understanding what has changed, and why, and how it might be handled.

  

Don't worry, we'll get this nailed. It might help if you provide a bit more context of what specifically you are trying to achieve, and how.

    

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 6

Dale.Bartlett
Collaborator
Collaborator

Hi Jeremy, Thanks for the response. I checked all the usual sources first, but without specific luck. https://www.revitapidocs.com/ only goes to 2023, and ChatGPT apologised:

"I apologize for any confusion, but as an AI language model, I don't have access to the specific details or updates regarding software APIs beyond my knowledge cutoff in September 2021. Therefore, I'm not familiar with the Revit 2024 API or its changes."

 

The code I am updating is from an old Autodesk sample:

Get Material - Example
// http://knowledge.autodesk.com/support/revit-products/getting-started/caas/CloudHelp/cloudhelp/2015/E... (link now dead)
// Getting an element material from a parameter
public void GetMaterial(RvtDoc document, FamilyInstance familyInstance)

 

What I have come up with is as follows. Warning is removed, but I am not sure of the correctness:

R2019, R2020, R2021:
if (def.ParameterGroup == BuiltInParameterGroup.PG_MATERIALS && def.ParameterType == ParameterType.Material)
R2022, R2023:
if (def.ParameterGroup == BuiltInParameterGroup.PG_MATERIALS && def.GetDataType() == SpecTypeId.Reference.Material)

R2024+
if (def.GetGroupTypeId() == GroupTypeId.Materials && def.GetDataType() == SpecTypeId.Reference.Material)

 

Could you cast an eye over my conversion please?




______________
Yes, I'm Satoshi.
Message 4 of 6

KEVIN_W_MAK_WSP
Participant
Participant

Hi Dale,

 

Try this: GroupTypeId.Materials. I have to change all "PG_xyz..." to "GroupTypeId.<GROUP>". It works for me. Good luck!

Kevin

Message 5 of 6

Dale.Bartlett
Collaborator
Collaborator

Thanks Kevin for the reply. I am not quite sure how your suggestion is implemented. Is it possible for you to provide one complete sample line? Apologies if it should be obvious. 




______________
Yes, I'm Satoshi.
0 Likes
Message 6 of 6

KEVIN_W_MAK_WSP
Participant
Participant

Hi Dale,

 

Hope you had a great weekend! For example, I create a list of shared parameters to be added to a family in the family manager by doing this:

 

// Prior to Revit 2024

public class MySharedParameter
{
#if REVIT2018 || REVIT2019 || REVIT2020 || REVIT2021 || REVIT2022 || REVIT2023
public string Name;
public BuiltInParameterGroup Group;
public bool IsInstance;


public MySharedParameter(string parameterName, BuiltInParameterGroup parameterGroup, bool isInstance)
{
Name = parameterName;
Group = parameterGroup;
IsInstance = isInstance;
}

// In Revit 2024
#elif REVIT2024
public string Name;
public ForgeTypeId Group;
public bool IsInstance;


public MySharedParameter(string parameterName, ForgeTypeId parameterGroup, bool isInstance)
{
Name = parameterName;
Group = parameterGroup;
IsInstance = isInstance;
}
#endif
}


// create a list of parameters to be added in Revit 2023
parameterList.Add(new MySharedParameter("Cable1", BuiltInParameterGroup.PG_DATA, true));
parameterList.Add(new MySharedParameter("Cable2", BuiltInParameterGroup.PG_DATA, true));

// in Revit 2024, it becomes:
parameterList.Add(new MySharedParameter("Cable1", GroupTypeId.IdentityData, true));
parameterList.Add(new MySharedParameter("Cable2", GroupTypeId.IdentityData, true));

 

// The actual line adding the shared parameters to family (no change in this line because the data type in my shared parameter list actually changed, I need to simplify the whole thing).

famMan.AddParameter(ed, parameterToBeAdded.Group, parameterToBeAdded.IsInstance);

Hope that makes sense.

 

Kevin

0 Likes