I'm trying to write a Python script that will compare parameters with a directory and calculate the cost

Hello everyone I have created elements in which there is a certain parameter with the name of furniture hooks and a directory in which all the names of furniture hooks and their cost. I am trying to write a script that will match the names of hooks in the elements with directory and, if they match, enter the cost. In short, I want to calculate the cost of hooks in the project, but with my programming skills, I’m not really getting it yet) thank you all!

1 Like

@KamaPulja ,

whats the error message? take in mind use append instead of Add

x = IN[0]
OUT = []

for i in x:
    OUT.append(i)

here I tried to compare the value of the parameter with a list of names of furniture hooks and, if they match, sum up their cost

@KamaPulja the simplest way to do it is to replace the not matching values by 0 since you want the sum of the cost, meaning no need to compare anything, just fetch the parameter values, then get the cost from the dictionary, if the parameter value is not in the dictionary, it will be replaced by the default value of 0, then get the sum for the total cost:

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
element = IN[0]
dictionary = IN[1]
names = []
price = []
for el in element:
	par = el.GetParameterValueByName("Comments")
	value = dictionary.get(par,0.0)
	names.append(par)
	price.append(value)
OUT = names, price, sum(price)

2 Likes

Thank you very much, my friend. Everything works fine :smiley: :+1:

1 Like