Page 1 of 2 12 LastLast
Results 1 to 10 of 14
Like Tree4Likes

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

  1.    #1
    Member
    Join Date
    February 22, 2013
    Posts
    288
    Current Local Time
    10:45 PM

    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
    clr.AddReference('ProtoGeometry')
    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.    #2
    Member johnp's Avatar
    Join Date
    March 24, 2015
    Posts
    138
    Current Local Time
    08:45 PM
    I don't think print is going to work in Dynamo, but I could be wrong.

    This seems to work,
    Code:
    import clr
    clr.AddReference('ProtoGeometry')
    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.    #3
    Member
    Join Date
    February 22, 2013
    Posts
    288
    Current Local Time
    10:45 PM
    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.
    josephpeel likes this.

  4.    #4
    Member
    Join Date
    February 22, 2013
    Posts
    288
    Current Local Time
    10:45 PM
    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?


    Attached Thumbnails Attached Thumbnails Attempting my first Python Node, need some basic help-dynamo-breaker-sizing.jpg  
    Last edited by Necro99; December 5th, 2018 at 04:46 PM.

  5.    #5
    Member johnp's Avatar
    Join Date
    March 24, 2015
    Posts
    138
    Current Local Time
    08:45 PM
    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
    clr.AddReference('ProtoGeometry')
    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.    #6
    Member
    Join Date
    February 22, 2013
    Posts
    288
    Current Local Time
    10:45 PM
    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!


    johnp and josephpeel like this.

  7.    #7
    Member johnp's Avatar
    Join Date
    March 24, 2015
    Posts
    138
    Current Local Time
    08:45 PM
    Quote Originally Posted by Necro99 View Post
    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.
    josephpeel likes this.

  8.    #8
    Forum Addict josephpeel's Avatar
    Join Date
    May 3, 2012
    Posts
    1,369
    Current Local Time
    04:45 AM
    Quote Originally Posted by Necro99 View Post
    .. 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.    #9
    Member Bjorn_K's Avatar
    Join Date
    April 8, 2011
    Location
    Rotterdam, Netherlands
    Posts
    260
    Current Local Time
    04:45 AM
    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.

    Attempting my first Python Node, need some basic help-rounding.png

    Sorry if I misunderstood the original problem.
    Last edited by Bjorn_K; December 6th, 2018 at 02:42 PM.

  10.    #10
    Member
    Join Date
    February 22, 2013
    Posts
    288
    Current Local Time
    10:45 PM
    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 LastLast

Similar Threads

  1. Revit Error When Attempting to make view title multi-line
    By katewood1989 in forum Architecture and General Revit Questions
    Replies: 3
    Last Post: July 18th, 2018, 04:22 PM
  2. Replies: 8
    Last Post: April 30th, 2018, 05:00 PM
  3. Amateur attempting to create family title blocks
    By Branston in forum Architecture - Family Creation
    Replies: 3
    Last Post: January 31st, 2017, 12:21 AM
  4. Basic Rain Screen for a Basic Revit User
    By tyarndt94 in forum Architecture and General Revit Questions
    Replies: 8
    Last Post: October 22nd, 2016, 01:37 AM
  5. attempting a waffle slab
    By stl4310 in forum Architecture and General Revit Questions
    Replies: 7
    Last Post: January 20th, 2012, 06:00 PM

Posting Permissions

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