Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Reading Wrong Type Parameters Values

Message 1 of 4
1698 Views, 3 Replies

Reading Wrong Type Parameters Values

I've developed a family browser, where I can search and find families and can read their additional information. However, the value I'm reading for type parameter is different from one shows in the Revit 2017. Below is the screenshot of property window of my application and Revit 2017. Here the value displays for Dimension's Depth is different from one I can see in the Revit.





parameter error.PNG



Here is the code behind:



        static string FamilyParamValueString(FamilyType t, FamilyParameter fp, Document doc)
            string value = t.AsValueString(fp);

            switch (fp.StorageType)
                case StorageType.Double:
                    value = Util.RealString(
                      + " (double)";


                case StorageType.ElementId:
                    ElementId id = t.AsElementId(fp);
                    Element e = doc.GetElement(id);
                    value = id.IntegerValue.ToString() + " ("
                      + Util.ElementDescription(e) + ")";

                case StorageType.Integer:
                    value = t.AsInteger(fp).ToString()
                      + " (int)";

                case StorageType.String:
                    value = "'" + t.AsString(fp)
                      + "' (string)";

            return value;


here's how I'm calling the FamilyParamValueString method.



  foreach (FamilyType familytype in mgr.Types)

                string name = familytype.Name;
                MultiValueDictionary<string, Tuple<string, string>> Parameters = new MultiValueDictionary<string, Tuple<string, string>>();

                foreach (string key in keys)
                    FamilyParameter fp = fps[key];
                    var definition = fp.Definition;
                    string ParameterGroupid = LabelUtils.GetLabelFor(definition.ParameterGroup);

                    if (familytype.HasValue(fp))
                        // Reading type's parameter value
                        string value = FamilyParamValueString(familytype, fp, doc);

                        //store parameter information along with its group
                        Parameters.Add(ParameterGroupid, new Tuple<string, string>(key, value));







Please guide me, how I can able to read exactly the same values as it displays in the Revit type's properties. Thank you for support!

Message 2 of 4
in reply to: imaliasad

Just a question:

Do you work in metric units?

What the API shows you is Imperial units (feet, etc...)...

Could be an explanation...


Benoit FAVRE
CEO of etudes & automates
Message 3 of 4
in reply to: imaliasad

Dear Ali,


Thank you for bringing this question here in addition to our discussion in the comments on The Building Coder article on Family Parameter Value:


As said, the Revit API will always return exactly what you have in the Revit database, unmodified.


In the database, all lengths are stored in imperial units:


That cannot be changed.


You can easily convert them to any unit you wish yourself, and the Revit API provides support for that as well, e.g. via the ConvertFromInternalUnits method:


Actually, the AsValueString method also sometimes returns what the user sees, and not the internal database value. All the other accessors, such as AsDouble and its siblings, return the raw database values. I mostly avoid using AsValueString for this very reason.


To see convert values to other units and to determine what units are displayed in the Revit user interface, please refer to the Units and UnitUtils classes:


The Units class represents a document's default settings for formatting numbers with units as strings.


UnitUtils helps convert a value from one display unit to another, such as square feet to square meters.


For more information on unit handling, please refer to The Building Coder category on that topic:





Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 4 of 4
in reply to: jeremytammik

@jeremytammik Thanks again for elaborating it. I'm struggling with technical inputs, as my background is in software development, I don't know much about how Revit works internally. However, as per our discussion, at least I know the values I'm getting from API is in Imperial Units. Now, I could work on converting imperial units to metric units.

The solution that was shared i.e UnitUtils class seems interesting, I tried it and again got stuck with the Enum  [DisplayUnitType ] value because I can see a lot of types to select for conversion and i'm not sure which type to select. See the below image


error code.png





Would appreciate if you could explain how a non-technical person like me can use the convert method to see exact parameter's values as it is being displayed in the Revit 2017. Thank you so much for your kind input. 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th

Rail Community