Add parameter on Family not working in Revit 2023

Add parameter on Family not working in Revit 2023

muaslam
Enthusiast Enthusiast
340件の閲覧回数
4件の返信
メッセージ1/5

Add parameter on Family not working in Revit 2023

muaslam
Enthusiast
Enthusiast

Hello,

I am trying to add a parameter to a family and it works well for Revit versions from 2015-2025 except for Revit 2023.
In Revit 2023 I am getting an exception,

Autodesk.Revit.Exceptions.ArgumentException: 'groupTypeId
Parameter name: The argument does not identify a builtin parameter group.'

Following is my code for this. Previously, I had a single #if (REVIT2023 || REVIT2024 || REVIT2025) but it was not working so I have split REVIT2023 to change it to fix the issue. But I am unable to find a resolution for this.

 

        private bool CreateAndAddSharedParameterToFamilyRFA(string myInformationString, Document familyDocument, FamilyManager familyManager, Family f = null)
            {
            bool isSharedParameterCreatedForMyInfo = false;
            try
                {
                Application app = familyDocument.Application;
                string sOrigSharedParamsFile = app.SharedParametersFilename;
                string sTempSharedParamsFile = Path.GetTempFileName();
                try
                    {
                    Transaction oTransaction = new Transaction(familyDocument, "CREATE_SHARED_PARAMETER_FOR_MY_INFORMATION");
                    try
                        {
                        oTransaction.Start();
                        FamilyParameter parameter = familyManager.get_Parameter(myInformation);
                        if (null == parameter)
                            {
#if (REVIT2024 || REVIT2025)
                            parameter = familyManager.AddParameter(myInformation, SpecTypeId.String.Text, SpecTypeId.String.Text, true);
#elif (REVIT2023)
                            parameter = familyManager.AddParameter(myInformation, SpecTypeId.String.Text, SpecTypeId.String.Text, true);
#else
                            parameter = familyManager.AddParameter(myInformation, BuiltInParameterGroup.PG_DATA, ParameterType.Text, true);
#endif
                            }
                        familyManager.SetDescription(parameter, myInformation);
                        familyManager.SetFormula(parameter, "\"" + myInformationString + "\"");
                        isSharedParameterCreatedForMyInfo = true;
                        }
                    catch (Exception ex)
                        {
                        oTransaction.RollBack();
                        app.SharedParametersFilename = sOrigSharedParamsFile;
                        File.Delete(sTempSharedParamsFile);
                        _logger.Error($"In CreateAndAddSharedParameterToFamilyRFA Fail to create shared parameter for breadcrumbs {myInformation}: {myInformationString} in shared parameter file: {app.SharedParametersFilename} to add parameter to RFAFile: {familyDocument.Title} with error :{ex.Message}");
                        return isSharedParameterCreatedForMyInfo;
                        }

                    oTransaction.Commit();
                    }
                catch (Exception ex)
                    {
                    app.SharedParametersFilename = sOrigSharedParamsFile;
                    File.Delete(sTempSharedParamsFile);
                    _logger.Error($"In CreateAndAddSharedParameterToFamilyRFA Fail to create add breadcrumbs {myInformation}: {myInformationString} in shared parameter file: {app.SharedParametersFilename} to add parameter to RFAFile: {familyDocument.Title} with error :{ex.Message}");
                    return isSharedParameterCreatedForMyInfo;
                    }
                app.SharedParametersFilename = sOrigSharedParamsFile;
                File.Delete(sTempSharedParamsFile);
                }
            catch (Exception ex)
                {
                _logger.Error($"In CreateAndAddSharedParameterToFamilyRFA Fail to create add breadcrumbs {myInformation}: {myInformationString}  to add parameter to RFAFile: {familyDocument.Title} with error :{ex.Message}");
                return isSharedParameterCreatedForMyInfo;
                }
            return isSharedParameterCreatedForMyInfo;
            }

 
Any help in this regards would be appreciated.

Regards,

Umar

0 件のいいね
解決済み
341件の閲覧回数
4件の返信
返信 (4)
メッセージ2/5

jeremy_tammik
Alumni
Alumni

I think you might be able to use PG_DATA in Revit 2023 as well. It is deprecated, but not yet obsolete in that version:

  

  

Search for PG_DATA in the BuiltInParameterGroup enumeration and specify the Revit release to check whether it exists or not. In Revit 2024 and later, it is gone and therefore cannot be used.

    

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
メッセージ3/5

muaslam
Enthusiast
Enthusiast

Hi Jeremy,
Having gone through several possibilities, I am again posting here,


muaslam_0-1735563867440.png

If I try to switch back to PG_DATA as suggested, I am unable to specify the ParameterType since this parameter type is now marked as internal in Revit 2023 API.

While the code in the comments lead me to the same error as the above in the initial question. I need to specify the type of the data to be text as I need to store some text parameter.

Any help on this?


Regards,
Umar

0 件のいいね
メッセージ4/5

ricaun
Advisor
Advisor

I believe the GroupTypeId is not fully implemented in Revit 2023, the BuiltInParameterGroup is not obsolete in version 2023.

 

Just use the AddParameter with the BuiltInParameterGroup, is not obsolete in version 2023.

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

メッセージ5/5

muaslam
Enthusiast
Enthusiast
解決済み

Just to help anyone who lands on this question in future, I have implemented the following to get it working,

 

#elif (REVIT2023)
                            app.SharedParametersFilename = sTempSharedParamsFile;
                            DefinitionFile oDF = app.OpenSharedParameterFile();
                            var oEDCO_ID = new ExternalDefinitionCreationOptions(ComponentsCenterInformation, SpecTypeId.String.Text)
                                {
                                UserModifiable = false,
                                Visible = false,
                                Description = ComponentsCenterInformation
                                };
                            DefinitionGroup oDG = oDF.Groups.Create("CONNECT");
                            Definition oDefId = oDG.Definitions.Create(oEDCO_ID);
                            parameter = familyManager.AddParameter(oDefId as ExternalDefinition, BuiltInParameterGroup.PG_DATA, true);


Thanks for the help @ricaun and @jeremy_tammik 
Regards,

Umar