Goal amount for this year: 2500 USD, Received: 1627 USD (65%)

# Thread: Attempting my first Python Node, need some basic help

1. ## Attempting my first Python Node, need some basic help

I'm trying to make a Dynamo script that will, among other things, take an electrical circuit's current in amps and spit out a breaker size. I need to do a nested if statement and it would be a bear to construct graphically with nodes. If this were a Revit Family, I'd type a long but simple nested conditional formula like this into the "Circuit Breaker Rating" parameter, something like:

if(Apparent Current < 15, 15, if(Apparent Current < 20, 20, if(Apparent Current <25, 25...)) ... on up to 150 amps.

How would I accomplish this in a Python Node? Here's what I've got so far but Dynamo is giving me the error "IrongPythonEvaluator.EvaluateIronPythonScript operation failed. undindent does not match any outer indentation level." I'm sure I'm making some basic syntax mistakes here and I'm hoping that someone can help me out.

import clr
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

if IN < 15:
b = 15
print(b)
else:
if IN < 20:
b = 20
print(b)
else:
if IN < 25:
b = 25
print(b)
else:
if IN < 30:
b = 30
print(b)

#Assign your output to the OUT variable.
OUT = b

Any help would be appreciated! I have a rare slow day at work today and would love to get this Dynamo graph working!

2. I don't think print is going to work in Dynamo, but I could be wrong.

This seems to work,
Code:
```import clr
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.
result = []
input = IN[0]

if input < 15:
result = 15
elif input < 20:
result = 20
elif input < 25:
result = 25
elif input < 30:
result = 30

#Assign your output to the OUT variable.
OUT = result```
I am betting there are better ways to do it as well, but those are beyond me.

3. Exactly what I needed! Thank you!

I'm a mechanical guy but I recently discovered that my electrical coworkers have been spending a lot of time on manual data entry in their panel schedules: wire sizing, breaker sizing, load names, they've been entering all of this stuff in manually for years and I've never known. So I've started creating this Dynamo script that will fill it all out for them.

4. One more question...

Okay, so I have my crude script written and it works, on up to to 500 amps. But now I want it to work on every object in a list input. I want to feed it the Apparent Current of every circuit in the model and have it spit out a list of breaker sizes. I wish there was a "lacing" option for this Python script node.

It seems like this script only wants a single input and not a list. Is there something I have to write into the Python script to get it to accept a list input?

5. To work with a list you need to iterate over it with a "for" statement. Along with this comes the need to append to the output. The modified code below should help.

Code:
```import clr
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.
result = []
input = IN[0]

for i in input:
if i < 15:
result.append(15)
elif i < 20:
result.append(20)
elif i < 25:
result.append(25)
elif i < 30:
result.append(30)

#Assign your output to the OUT variable.
OUT = result```

6. Thank you! I'll file this away for the future.

What I ended up doing (before I saw your reply) was to create a custom node with the nested if statement contained in a code block. The code block can't be laced but a custom node can!

7. Originally Posted by Necro99
Thank you! I'll file this away for the future.

What I ended up doing (before I saw your reply) was to create a custom node with the nested if statement contained in a code block. The code block can't be laced but a custom node can!

Very nice! The first time I used lists I did that as well.

8. Originally Posted by Necro99
.. my electrical coworkers have been spending a lot of time on manual data entry
Exactly my experience too! They say things like "Revit doesnt have much to offer for electrical, you can only model cable trays" but electrical systems are so much more logical in their structure and data than mechanical. Even using none of the electrical calcs in Revit and only Types and parameters, it would be so much better for handling their design information...
Im deliberately avoiding Electrical as I have enough to do with Mechanical, waiting for one of theirs to show an interest or learn dynamo...

9. All the kudo's for solving it in Python, but as you are describing your problem it's a rounding problem, right? Round up to 15, and then up to the nearest 5.

Sorry if I misunderstood the original problem.

10. It's trickier than that, because US standard breaker sizes are 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 110, 125, 150, 175, 200, 225, 250, 300, 350, 400, 450, 500, 600, 700, 800, 1000, 1200, 1600, 2000, 2500, 3000, 4000, 5000, and 6000.

Page 1 of 2 12 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•