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

Python - Sum Of List Of Values (Converted To Model Units)

$
0
0

Hello,

I’ve made this python script that converts values from specified units to desired units and it’s working as expected with the exception of the S output.

I would like this output to return the Sum of the R list results.

I realize this is a pretty basic question but I can’t figure it out or find a working example of how to achieve this. (Python newbie, sorry)

Thanks for your help & guidance!

Script:

V = float(V)
C = [C]

conversion_functions = {
    "in_ft": lambda V: V / 12,
    "ft_in": lambda V: V * 12,
    "m_ft": lambda V: V / 0.3048,
    "cm_ft": lambda V: V / 30.48,
    "cm_in": lambda V: V / 2.54,
    "mm_ft": lambda V: V / 0.0328084,
    "ft_m": lambda V: V * 0.3048,
    "ft_cm": lambda V: V * 30.48,
    "ft_mm": lambda V: V * 304.8,
    "in_m": lambda V: V * 0.0254,
    "in_cm": lambda V: V * 2.54,
    "in_mm": lambda V: V * 25.4,
}

Results = []

for i in C:
    if i in conversion_functions:
        R = conversion_functions[i](V)
        Results.append(R)
        print Results
    else:
        R = V

S = sum(Results)

Graph Space:

8 posts - 4 participants

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles