Automating the multiplication using python

Embodied carbon analysis.v1.dyn (34.3 KB)
Hi, I’m trying to make the embodied carbon calculation using dynamo. So I extract the volume of the elements, multiply it by the density, and then again with the embodied carbon factor. That will give me the embodied carbon kgCO2. I have 3 questions.

  1. Could I automate the multiplication process using python? Like use python to prompt the user to give the density and embodied carbon coefficient then does the multiplication after that.
  2. Could I also extract the volume using python?
  3. The values I get are in a long list, how can I add up all the values on my list?

Thank you!

All of those things are possible in python but also just with nodes. You can use Data-Shapes package to create a custom UI for prompting inputs and then let Dynamo do the rest. Everything else is just a couple nodes to apply your math and then sum the values (Math.Sum) for a total.

Try building your custom UI and see if that gets you what you want. Then we can look at wrapping everything else up.

I installed Data-Shapes, why does it only say colour? and how do I build a custom UI? also for the Math.sum shows error, am I using it wrong?
Screenshot 2024-04-18 223055
image

Make sure it installed properly. Check your versions and try closing and reopening Revit.

What does the warning from Math.Sum say? Do you have nulls or other non-numbers in your list?

Hi @efyhm2 ,

You probably have empty values in your list. Use List.RemoveIfNot with a System.Double text in a string node as type.

Hi again, there was an empty value and I have dealt with that. The Math.sum works great thank you very much.
I’m trying to use python to code the calculation part, mine does not work. Could I get some help with this?

python code

When you get the Data-Shapes package working here is an exmaple with Dynie to help you.

Hi @efyhm2 ,

The python code seems correct, however you’ve specified an IN[0], IN[1] and IN[2] but in your screenshot you only have data feeding into the IN[0] input, using the + on the python node can you add more inputs.

One other thing to notice is that this python script assumes your inputs are three numbers, e.g. 5, 10 and 15. This python script won’t work with 3 lists inputs (IN[0], IN[1] and IN[2] respectively) or lists with sublists.

If I can I always prefer to use nodes or a codeblock with some designscript it in, like the following:


Designscript in codeblocks already iterate over each item and assuming your three lists all have the same amounts of items and sublists this should work.

density * embodied_carbon_factor * volume;
1 Like

This works great!! Thank you so much!! :heart:

1 Like