DimArea macro in Python script


I am hoping to get some guidance for developing this script. The goal is to create a surface attached with a DimArea text. I am not sure what I’m missing but there are two issues so far:

  1. Selprev doesn’t select the newly created surface (it selects the surface if I run the macro directly from the macro editor)
  2. Once it selects the surface it then asks for Text Position. I would like the text to be centered on the surface so I thought moving the “dimArea” would be the way forward. Is there a better way to do this?
import rhinoscriptsyntax as rs

srf = rs.AddPlaneSurface(rs.WorldXYPlane(), 5, 5)
dimArea = rs.Command("_Dimarea _Type=_Text _Pause _Selprev")
#moveDimArea = rs.MoveObject(dimArea, rs.SurfaceAreaCentroid(srf))

Thanks in advance!

Something like this maybe?

import rhinoscriptsyntax as rs

srf = rs.AddPlaneSurface(rs.WorldXYPlane(), 5, 5)

area = rs.SurfaceArea(srf)
if area:
    cen = rs.SurfaceAreaCentroid(srf)
    if cen:
        text = round(area[0],2)
        text = str(text)
        rs.AddTextDot("Surface Area: " + text, cen[0])
        print "The surface area is: " + text

1 Like

Hello - something like -

import rhinoscriptsyntax as rs

srf = rs.AddPlaneSurface(rs.WorldXYPlane(), 50, 50)

rc = rs.Command("_DimArea _Type=_Text SelId " + str(srf) + ' 0,0,0 ' ) 

if rc:
    dimArea = rs.LastCreatedObjects()[0]
    pt = rs.BoundingBox(dimArea)[0]#<<< the lower left pt in the bounding box
    rs.MoveObject(dimArea, rs.SurfaceAreaCentroid(srf)[0]-pt)

i.e. use the id of the created surface to select it in the DimArea command. Note when you go out to a Rhino command the result is not an object id or ids as when you create the object from a script function - you need to get ‘LastCreatedObjects()’ , always a list, and in this case the first and only object in the list, hence the [0].



Thank you @DanBayn, this definitely works in terms of displaying the surface area but it doesn’t update the value like Dimarea does when scaling the surface.

Thank you @pascal, this is spot on! Exactly what I was looking for.