Reading Wrong Type Parameters Values

Anonymous

Reading Wrong Type Parameters Values

Anonymous
Not applicable

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)t.AsDouble(fp))
                      + " (double)";

                    break;

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

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

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

            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!

0 Likes
Reply
Accepted solutions (1)
2,454 Views
3 Replies
Replies (3)

BenoitE&A
Collaborator
Collaborator

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
www.etudesetautomates.com/

jeremytammik
Autodesk
Autodesk
Accepted solution

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:

 

http://thebuildingcoder.typepad.com/blog/2009/11/family-parameter-value.html

 

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:

 

http://thebuildingcoder.typepad.com/blog/2011/03/internal-imperial-units.html

 

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:

 

http://www.revitapidocs.com/2018.1/9cc2c0ea-f59f-9d76-ce19-ae7eede03bbd.htm

 

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:

 

http://www.revitapidocs.com/2018.1/89d89465-897f-4105-b935-27edf67aab3e.htm

 

http://www.revitapidocs.com/2018.1/128dd879-fea8-5d7b-1eb2-d64f87753990.htm

 

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:

 

http://thebuildingcoder.typepad.com/blog/units

 

Cheers,

 

Jeremy



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

Anonymous
Not applicable

@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. 

0 Likes