Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 4165

Trying to expand the Easu_cut script with area

$
0
0

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|attachment](upload://sCaN4tst8jxtq0qYLt029esolbg.py) (17.6 KB)

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 4165

Latest Images

Trending Articles



Latest Images