Announcement

Collapse
No announcement yet.

Debugging Python

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Debugging Python

    Is there any good way to debug a Python node?
    I've got one that works if I pass a single value, but if I pass a list, it fails.
    Without any debugging tools, I can't tell where it fails. All I get is "null" as output.
    Dave Plumb
    BWBR Architects; St Paul, MN

    CADsplaining: When a BIM rookie tells you how you should have done something.

    #2
    Is there any try statement? Try to remove it or post your code here. try in Python is used to handle errors and the code you are using is probably bad written.
    Last edited by TomekTomek; February 27, 2018, 09:45 AM.

    Comment


      #3
      Is there an warning on the Python node? Those will usually tell you what line caused the failure. There are also some debuggers online but I doubt they support the Dynamo/Revit workflow. I just tried with a small snip I have and got an error dealing with importing CLR and an error with the [IN] variable :crazy:
      Last edited by cellophane; February 27, 2018, 02:42 PM.
      Revit for newbies - A starting point for RFO


      chad
      BEER: Better, Efficient, Elegant, Repeatable.

      Comment


        #4
        It's a little bit complicated (of course) but I've stripped it down as much as I can with the attached files
        I made one Dynamo graph that calls a custom node. In the custom node is the Python.
        It reads an Excel file that has one column for a Department Name, and another column with text that specifics and RGB value.
        The graph distills the Excel file,
        The custom node puts it all back together
        The Python creates a Material, names it, and assigns the colors.
        If I add a "FirstItem" to everything, the Python builds a single material as expected, but it fails when I try to pass in lists.
        I'm comfortable in Visual Basic, but I have no idea what I'm doing in Python. Just stealing examples and (trying to) tweak them.
        I've added a boatload of Watch nodes to try to make it more obvious what I'm doing.
        Attached Files
        Last edited by DaveP; February 27, 2018, 05:56 PM. Reason: changed "FirstIndexOf" to "FirstItem"
        Dave Plumb
        BWBR Architects; St Paul, MN

        CADsplaining: When a BIM rookie tells you how you should have done something.

        Comment


          #5
          This post just made me realize that the lack of robust python debugging has probably forced me to keep my python scripts short and functionally simplistic. I found I was breaking the Python nodes into smaller functions so that I could plug in watches to debug. Now I try to use Python only for instances where the API isn't implemented in Dynamo yet or where I need to force looping / evaluation. To me, it's much easier to not have to troubleshoot Python while working out a graph. I'm not a Python expert, but I don't see what your script is doing that can't be done with regular nodes.
          Chris Ellersick

          Comment


            #6
            I see a lot of "GetMaterial" nodes, but I didn't find any "CreateMaterial" nodes
            My larger graph is heavily stolen from Kyle Martin's Space Planning post.
            But his graph assumes the Materials are already in the project.
            I wanted to create the Materials based on the RGB values in the spreadsheet.
            For that, I found this post by catexis
            https://forum.dynamobim.com/t/create...ynamo-how/4365
            That's where I got the Python code from.
            Dave Plumb
            BWBR Architects; St Paul, MN

            CADsplaining: When a BIM rookie tells you how you should have done something.

            Comment


              #7
              Ah. I see my error - I assumed that the green plus next to ByName meant it created a new material by name (it does not - it selects from the current doc).

              So, I would move the material creation part to Python. This script / graph seems to be working in that it creates materials in the doc based on a list of names. You can pipe those to other nodes that set the properties of the materials, and then assign it by setting the element's Material parameter.

              Also, I think the inputs on your Make RGB Materials.dyf should look something like "red:int[]=0" (defining "red" as an integer array with default value of 0).
              Attached Files
              Chris Ellersick

              Comment


                #8
                "breaking the Python nodes into smaller functions"

                Exactly
                Code a single function and re-use it in any node combination you can think of..
                This is personally why I much prefer Dynamo to programming languages.

                Attached Files
                "One must imagine Sisyphus happy." Albert Camus - "The innovator has for enemies all those who have done well under the old conditions, and lukewarm defenders in those who may ​do well under the new." Nicolo Machiavelli -"Things that are too complex are not useful, Things that are useful are simple." Mikhail Kalashnikov

                Comment


                  #9
                  Chris, I've gotta admit, I think I'm even more confused now.
                  My Python script DOES create the Material (or at least tries to)
                  AFAICT, it works pretty much like the one you uploaded, except mine also assigns the colors and the Patterns.
                  Aslo, my Make RGB Materials.dyf DOES have Red[] : int=0 , etc as inputs.
                  In the file I uploaded above, I did not indent the lines under the "for" statement.
                  Changed that, and moved the TransactionManager lines outside the "for", but it still doesn't work.
                  Again, if I had some debug tools, I could figure out where it's failing, but now all I get is "null" as an end result.
                  Dave Plumb
                  BWBR Architects; St Paul, MN

                  CADsplaining: When a BIM rookie tells you how you should have done something.

                  Comment


                    #10
                    I guess my suggestion was to move the other assignment statements outside of the python, and then either 1)use nodes to finish your assignments, or 2)move them back in one by one until you find what is breaking the script. You have a python script within a custom node, so you are 2 steps away from seeing your debugging results (exit python node, exit custom node), making the process more time consuming. My suggestion was essentially move your troubleshooting into the "dynamic" part of the graph, where you can debug in automatic mode.

                    Also, on the input variable declaration, what I noticed was that the "Red", Green", and "Blue" are showing with the teal-green text color because when they are capitalized they are properties of a Color (Color.Red, Color.Green, Color.Blue). "red", "green", and "blue" are not reserved words and can be used as variable names. Also, I believe the array declaration ("[]") needs to apply to the datatype of variable you are declaring (int, float, string, etc), not the variable itself (red, green, blue). When I change your input node strings to be "red:int[]=0", Dynamo gives me the appropriate tooltip on mouseover (indicating it's getting what it's expecting). This link explains the datatypes better: http://designscript.io/DesignScript_user_manual_0.1.pdf

                    I don't think anyone is "holding out" on giving you debugging tools - I don't think they exist in this context. With the python node, it's sort of all-or-nothing. If the python node is erroring out, it should turn yellow and provide basic debugging info you can use to help trace the error(s). To further debug, you have to get values passed to the OUT variable to see anything on the output of the python node.
                    Chris Ellersick

                    Comment

                    Related Topics

                    Collapse

                    Working...
                    X