HELP: How get the "StringValue" of shared parameter?

HELP: How get the "StringValue" of shared parameter?

Anonymous
Not applicable
1,159 Views
3 Replies
Message 1 of 4

HELP: How get the "StringValue" of shared parameter?

Anonymous
Not applicable

Hello everyone:

 

How can getting of a Element the value the properties and shared parameters efficiently?.

 

See image:

 

parameter_shared.png

 

I am using the following code, but not works because the result is "none".

 

Parameter gymCategoria = fi.LookupParameter("Categoria GyM");

TaskDialog.Show("GYM-BIM", "Collector = " + ParameterToString(gymCategoria));

/// <summary>
/// Helper function: return a string form of a given parameter.
/// </summary>
        public static string ParameterToString(Parameter param)
        {
            string val = "none";

            if (param == null)
            {
                return val;
            }

            // To get to the parameter value, we need to pause it depending on its storage type 

            switch (param.StorageType)
            {
                case StorageType.Double:
                    double dVal = param.AsDouble() * 0.3048;
                    val = dVal.ToString();
                    break;
                case StorageType.Integer:
                    int iVal = param.AsInteger();
                    val = iVal.ToString();
                    break;
                case StorageType.String:
                    string sVal = param.AsString();
                    val = sVal;
                    break;
                case StorageType.ElementId:
                    ElementId idVal = param.AsElementId();
                    val = idVal.IntegerValue.ToString();
                    break;
                case StorageType.None:
                    break;
            }
            return val;
        }

 

Thanks.

0 Likes
1,160 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

It looks like you are dealing with a type parameter in this situation.

 

As such, you need to retrieve the parameter from the FamilySymbol, and not from the FamilyInstance.

 

If you change 

Parameter gymCategoria = fi.LookupParameter("Categoria GyM");

to

Parameter gymCategoria = fi.Symbol.LookupParameter("Categoria GyM");

then you should be able to correctly read its value.

0 Likes
Message 3 of 4

Anonymous
Not applicable

I executed the change but does not work :(.

Keeps coming "none"

 

parameter_shared2.png

 

Heré the code complete:

 

public void GenerateFormworkToElements(string category)
        {
            SubTransaction createFormwork = new SubTransaction(m_revit.ActiveUIDocument.Document);
            try
            {
                createFormwork.Start();                

                FilteredElementCollector collector = new FilteredElementCollector(m_revit.ActiveUIDocument.Document).OfClass(typeof(FamilyInstance));

                if (category == "Structural Columns")
                {

                    int i = 0;
                    foreach (FamilyInstance fi in collector)
                    {

                        if (fi.StructuralType == StructuralType.Column)
                        {

                            //Get parameter "Tipo de Altura"                          
                            Parameter tipoAltura = fi.LookupParameter("Tipo de Altura");

                            //Get parameter "H" Height
                            Parameter  height = fi.LookupParameter("H");

                            //Get parameter "Encofrado"
                            Parameter encofrado = fi.LookupParameter("Encofrado");

                            //Get parameter "GyM Categoría"
                            Parameter gymCategoria = fi.Symbol.LookupParameter("Categoria GyM");
                            
                            TaskDialog.Show("GYM-BIM", "Collector = " + fi.Name
                                            + "\nContador = " + i
                                            + "\nId =" + fi.Id
                                + "\nCategory = " + ParameterToString(gymCategoria)
                                + "\nHeight = " + ParameterToString(height)
                                + "\nTipo Altura = " + ParameterToString(tipoAltura)
                                + "\nEncofrado = " + ParameterToString(encofrado)
                                            );
                            if (i == 5)
                            {

                                break;
                            }
                            //}
                            i++;
                        }
                    }

                    TaskDialog.Show("GYM-BIM", "Collector Total = " + i);
                }

                createFormwork.Commit();
            }
            catch (Exception ex)
            {
                TaskDialog.Show("GenerateFormworkToElements", "Error = " + ex.Message);
                createFormwork.RollBack();
            }

        }

        /// <summary>
        /// Helper function: return a string form of a given parameter.
        /// </summary>
        public static string ParameterToString(Parameter param)
        {
            string val = "none";

            if (param == null)
            {
                return val;
            }

            // To get to the parameter value, we need to pause it depending on its storage type 

            switch (param.StorageType)
            {
                case StorageType.Double:
                    double dVal = param.AsDouble() * 0.3048;
                    val = dVal.ToString();
                    break;
                case StorageType.Integer:
                    int iVal = param.AsInteger();
                    val = iVal.ToString();
                    break;
                case StorageType.String:
                    string sVal = param.AsString();
                    val = sVal;
                    break;
                case StorageType.ElementId:
                    ElementId idVal = param.AsElementId();
                    val = idVal.IntegerValue.ToString();
                    break;
                case StorageType.None:
                    break;
            }
            return val;
        }

 

Thanks very much for your help.

 

David

0 Likes
Message 4 of 4

Anonymous
Not applicable

Can you find the GUID of the parameter from your shared parameters file, and then attempt to lookup the parameter using

Parameter gymCategoria = fi.get_Parameter(new Guid("GUIDVALUEFROMSHAREDPARAMFILE"));

For some reason, the parameter isn't being found when you are looking it up by name.  I don't see any other issues with the code.

 

I don't believe that it's possible for a shared parameter to have a StorageType of None.

 

However, to be sure that the error is happening when trying to lookup the parameter, can you change

case StorageType.None:
    break;

to

case StorageType.None:
val = "StorageTypeNone"; break;

 

0 Likes