Announcement

Collapse
No announcement yet.

I need to round the Area value to 2 digits

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    I need to round the Area value to 2 digits

    Hi
    I need to round the Area value to 2 digits. It always comes as 3 digits. We use m² as unit. How to do this in this code(the line in red):

    Code:
    namespace RoomComments
    {
        [Transaction(TransactionMode.Automatic)]
        class SetRoomComments : IExternalCommand
        {
    
            public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
            {
                UIApplication app = commandData.Application;
                UIDocument uidoc = app.ActiveUIDocument;
                Document doc = uidoc.Document;
    
                List<Element> rooms = new List<Element>();
                List<Element> areas = new List<Element>();
    
                FilteredElementCollector collector = new FilteredElementCollector(uidoc.Document);
                collector.OfCategory(BuiltInCategory.OST_Rooms);
                rooms.AddRange(collector);
    
    
                FilteredElementCollector Acollector = new FilteredElementCollector(uidoc.Document);
                Acollector.OfCategory(BuiltInCategory.OST_Areas);
                areas.AddRange(Acollector);
    
                string m_AV = null;
    
                try
                {
                    foreach (Room m_room in rooms)
                    {
                        Parameter p = m_room.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS);
                        string m_roomnumber = m_room.Number;
    
                        foreach (Area m_area in areas)
                        {
                            string m_areanumber = m_area.Number;
                            [COLOR="#B22222"]string m_areavalue = m_area.get_Parameter(BuiltInParameter.ROOM_AREA).AsValueString();[/COLOR]
    
                            if (m_roomnumber == m_areanumber)
                            {
                                m_AV = m_areavalue.TrimEnd('m','²');
                            }
                        } 
                        p.Set(m_AV);
                    }
                    return Result.Succeeded;
                }
                catch
                {
                    return Result.Failed;
                }
            }
        }
    }
    best regards
    Last edited by funkys; July 17, 2011, 02:02 PM.

    #2
    Why do you try to assign area and number to strings? Parameter.AsValueString() returns the string representation of the value as it would be displayed in the project. It is therefore completely depending on the project. If you insist in using this function, you would have to change the project settings accordingly. But this will be completely unreliable code.
    I would assign room number to integer and area to double using AsInteger() or AsDouble(). I then would convert to string only if really needed using double.ToString(“F2”) for instance. But this is only one of possible solutions
    My point is that in my opinion you lose flexibility and introduce instability if you code like in your example using just strings. But maybe I totally misunderstand the code.
    Last edited by dalmore; July 17, 2011, 02:55 PM. Reason: now i understand better
    [email protected]

    http://4revit.com

    Comment


      #3
      Parameter.AsValueString() always return the area with 3 digits no matter what the project settings are. That's the problem.

      Comment


        #4
        Well it seems no one knows why .asValueString() returns with 3 digits. Then I'll just convert square foot to square meters.

        Code:
                public static double SqFootToSqMm(double area)
                {
                    return area * 0.09290304;
                }

        Comment

        Related Topics

        Collapse

        Working...
        X
        😀
        🥰
        🤢
        😎
        😡
        👍
        👎