Trying to expand the Easy_cut script with area

I’m trying to add two measurements /surface area and boundingbox area)to the Easy_Cut Python script, but I get a formatting error "ValueError: Unknown format code ‘f’ for object of type ‘str’ "…I may have to add stuff to the second sq bracket in the return, but what…?

Any ideas as to how I fix this?..
anders

Here are the critical snippets:

###added code
    actArea=g.AreaMassProperties.Compute(face) # Calculate actual surface area
    bbArea=width * length # calculate bounding box area
###end of added code
###return [[length,width,thickness], [xVec,yVec,faceNor]]
    return [[length,width,thickness,actArea,bbArea], [xVec,yVec,faceNor]] ###ActArea & bbArea has been added 
    ### Do I need to add something in the second square bracket as well?

class attr:
    def __init__(self, name, isEditable, isOn, valType, exportPos):
        self.name = name
        self.isEditable = isEditable
        self.isOn = isOn
        self.valType = valType
        self.exportPos = exportPos

ATTRS = (attr("ID#",True,True,int,1), #Converted from N to ID#
attr("Name",True,True,str,0), #Where does it come from...manually entered in user texts?
attr("Length",False,True,int,2),
attr("Width",False,True,int,3),
attr("Thickness",False,True,int,4),
attr("Texture",True,True,str,-1), 
attr("actArea",True,True,str,6), #changed to actural area calculated above
attr("bbArea",True,True,str,7), #changed to boundingbox area calculated above
attr("Edge_L",True,True,str,8),
attr("Edge_W",True,True,str,9),
attr("Layer",False,True,str,10),
attr("Comment",True,True,str,11)
)

and here:

 self.dims, self.lcs = computeDims(self.obj)

    self.Length = format(self.dims[0],'.' + str(DIM_PRECISION) + 'f')
    self.Width = format(self.dims[1],'.' + str(DIM_PRECISION) + 'f')
    self.Thickness = format(self.dims[2],'.' + str(DIM_PRECISION) + 'f')
    self.Area = format(self.dims[3],'.' + str(DIM_PRECISION) + 'f') # I've added the actual area....and get a formatting error when I run the script (ValueError: Unknown format code 'f' for object of type 'str')
    self.bbArea= format(self.dims[4], '.' + str(DIM_PRECISION) + 'f') # I've added the boundingbox area


Here is the entire py script:
20240527_panel-schedule maker based on easy_cut speccmd.py (17.6 KB)

I don’t know who writes code like this… but essentially this is what is trying to be achieved here:

my_float = 1.23456
template1 = f"my number is {my_float:.2f}"
# yields: "my number is 1.23" 
template2 = f"my number is {my_float:.4f}"
# yields: "my number is 1.2345" 

It seems the script is formatting a template, to format a string, in the end with different precision… So you need to provide an integer

'.' + str(accuracy_as_int) + 'f' # -> e.g. 2 to get .2f

Thanks @TomTom , I’m beginning to think that that is not the core of my problem.
It just shows my lack of Python knowledge.

I think problem is further up i the script where I create and add my two new parameters…actArea and bbArea…I just don’t know what to do about it… :wink:

anders

I don’t understand why I can’t get this to work ( I’m only learning Python, so I know why, but I’d like to understand and make it work):

In the ComputeDims() definition in the beginning of the script it calculates the size of various surfaces, finds the largest and drops it into the face variable. for non rectangular surfaces this does not reflect the real area

def computeDims(obj):

objRef = Rhino.DocObjects.ObjRef(obj)
brep = objRef.Geometry()    
edges = list(brep.Edges)
edges.sort(key=lambda edge: edge.GetLength(), reverse=True)
edge = edges[0]
adFaces = list(edge.AdjacentFaces())
faces = list(brep.Faces)
adFaces = [faces[i] for i in adFaces]
adFaces.sort(key=lambda face:face.GetSurfaceSize()[1]*face.GetSurfaceSize()[2],reverse=True)
face = adFaces[0]

In the same definition I want to calculate the actual area of the surface with:
actArea = g.AreaMassProperties.Compute(face)

but it won’t work and when i Print ActArea I get til in the terminal, not the area:
<Rhino.Geometry.AreaMassProperties object at 0x0000000000000092 [Rhino.Geometry.AreaMassProperties]>

Any thoughts or suggestions?

thanks
anders

Maybe rs.SurfaceArea(face) if the better function to use, but when I drop it in, I get a format error again (this time that the 'f' code does not apply to strings).

I apologize for stumbling around and asking dump questions, but I really want to learn how to make it work and in the process learn to use Python in Rhino

thanks

I figured it out…I just needed an extra step because rs.SurfaceArea() returns both the area and some other stuff (absolute error bound), so I had to select the first entry in the list ( the area)

setArea = rs.SurfaceArea(face)
actArea = setArea[0]

I hope this helps someone else and thank you for your help