Units in Area dimension

Hello everyon,

I am using Rhino in my architecture office since 2014 and I have a problem.

In my model view or layout I usually create dimensions in cm but area in square m2.

I draw everything in cm in the model.

The problem is that when I use _DimArea it always show the result in cm2.

Is it possible to change that and display it in square m2 or other units?

Thank you very much for your replies

:slight_smile:

Hello - here is a script you can try - at the moment it is one by one but it could just do them all as well - it will add a second number to DimArea objects in the units of your choice, BUT, it is not ‘live’. If the area changes the second number will not until you tell it to - which is a good reason to make it global - but for now, just to see if it does anything useful - it may not - try this out.

To use the Python script use RunPythonScript, or a macro:

_-RunPythonScript "Full path to py file inside double-quotes"

AreaDimUnit.py (2.0 KB)

-Pascal

Okay Thanks Pascal,

It works pretty great, but is it possible to hide or erase the first number and the quotes () in yellow on the picture?

Thanks a lot for your help

Will it be soon on Rhino 6.xxx?

and is it possible to choose how many numbers behind the , ?

like instead of 26.257 m2 to choose 26.3 m2 ?

Hi Lawrence - as far as I can see I cannot hide/get-rid-of the main number - my attempts to do so result in the formula being lost, so far anyway. I can format the new number however.

@Lawrence_Breitling - this one lets you set the precision -

-Pascal

mmmmm,

seems great !

The problem now is that I can’t run the script when I create a button.

I tried also with NoEcho.

Doesn’t work.

Any idea ?

Thanks!
2JPG|690x388

Paste this in your button:

_-RunPythonScript (
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
import System.Enum as enum


def AreaUnits():
    crntUnits = sc.doc.ModelUnitSystem
    unitsList =  enum.GetValues(Rhino.UnitSystem)
    units = [item.ToString() for item in unitsList][1:10]
    
    def filter_dim_area(rhino_object, geometry, component_index ):
        if geometry.TextFormula.startswith("%<Area"):
            return True
        return False

    while True:
        unitIdx = 1
        if sc.sticky.has_key('UNIT_IDX'):
            unitIdx = sc.sticky['UNIT_IDX']
        go = Rhino.Input.Custom.GetObject()
        
        intPrecision = 2
        
        if sc.sticky.has_key('AREA_PRECISION'):
            intPrecision = sc.sticky['AREA_PRECISION']
        
        go.GeometryFilter = Rhino.DocObjects.ObjectType.Annotation
        go.SetCommandPrompt("Select a DimArea")
        
        go.SetCustomGeometryFilter(filter_dim_area)
        
        opUnits = go.AddOptionList("Units", units, unitIdx)
        opPrecision = Rhino.Input.Custom.OptionInteger(intPrecision)
        
        go.AddOptionInteger("Precision", opPrecision)
        
        rc = go.Get()

        if go.CommandResult()!=Rhino.Commands.Result.Success:
            return go.CommandResult()
            
        if rc==Rhino.Input.GetResult.Object:
            id = go.Object(0).ObjectId 
            break
            
        elif rc==Rhino.Input.GetResult.Option:
            idx = go.OptionIndex()
            if idx == 1:
                unitIdx = go.Option().CurrentListOptionIndex
                sc.sticky['UNIT_IDX'] = unitIdx
                continue
            else:
                intPrecision = opPrecision.CurrentValue
                sc.sticky['AREA_PRECISION']= intPrecision
                continue
                
    geo = rs.coercegeometry(id)
    
    t  =  geo.PlainText.split()
    value = float(t[0])
    f = geo.TextFormula 
    
    targUnits = unitsList[unitIdx+1]
    factor = Rhino.RhinoMath.UnitScale(crntUnits, targUnits)**2
    outputUnits  = Rhino.UI.Localization.UnitSystemName(targUnits, False, True, True)
    
    indices = [i for i, a in enumerate(f) if a == '%']
    strFormat = "{:." + str(intPrecision) + "f}"
    f = f[indices[0]:indices[1]+1]

    newF = f + " (" + strFormat.format(value*factor) + ' ' +outputUnits + '2' ')'
    geo.TextFormula = newF
    sc.doc.Objects.Replace(id, geo)
    
    pass 
AreaUnits()
)

That should work…

Thanks a lot,

works really great and smooth.

By the way M/Ms Wim you don’t know also how to hide the text before and the () ?

Thanks a lot :slight_smile:

Sorry, no. If @pascal can’t do that, I definitely can’t. :sunglasses:

hahaha okay I understand !

thanks a lot by the way !

I get an error on line 2.

Any ideas?

Area_in_M2.py", line 2
import rhinoscriptsyntax as rs
^
SyntaxError: unexpected token ‘import’