Donate Now Goal amount for this year: 3000 USD, Received: 1207 USD (40%)

Page 1 of 2 12 LastLast
Results 1 to 10 of 13
Like Tree7Likes

Thread: Debugging Python

  1. #1
    Moderator DaveP's Avatar
    Join Date
    January 10, 2011
    Location
    St Paul, MN
    Posts
    2,949
    Current Local Time
    07:18 AM

    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.

  2. #2
    Junior Member TomekTomek's Avatar
    Join Date
    May 20, 2016
    Posts
    18
    Current Local Time
    12:18 PM
    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 27th, 2018 at 09:45 AM.

  3. #3
    Moderator cellophane's Avatar
    Join Date
    August 9, 2011
    Location
    Louisville, KY
    Posts
    6,104
    Current Local Time
    08:18 AM
    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
    Last edited by cellophane; February 27th, 2018 at 02:42 PM.

  4. #4
    Moderator DaveP's Avatar
    Join Date
    January 10, 2011
    Location
    St Paul, MN
    Posts
    2,949
    Current Local Time
    07:18 AM
    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 Attached Files
    Last edited by DaveP; February 27th, 2018 at 05:56 PM. Reason: changed "FirstIndexOf" to "FirstItem"

  5. #5
    Member
    Join Date
    March 21, 2013
    Location
    Phoenix, AZ
    Posts
    275
    Current Local Time
    05:18 AM
    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.
    josephpeel and amoursol like this.

  6. #6
    Moderator DaveP's Avatar
    Join Date
    January 10, 2011
    Location
    St Paul, MN
    Posts
    2,949
    Current Local Time
    07:18 AM
    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.

  7. #7
    Member
    Join Date
    March 21, 2013
    Location
    Phoenix, AZ
    Posts
    275
    Current Local Time
    05:18 AM
    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 Thumbnails Attached Thumbnails Debugging Python-rgb-materials.png   Debugging Python-rgb-materials-python.png  
    Attached Files Attached Files

  8. #8
    Forum Addict josephpeel's Avatar
    Join Date
    May 3, 2012
    Posts
    1,396
    Current Local Time
    02:18 PM
    "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 Thumbnails Attached Thumbnails Debugging Python-dynamo-v-c.jpg  

  9. #9
    Moderator DaveP's Avatar
    Join Date
    January 10, 2011
    Location
    St Paul, MN
    Posts
    2,949
    Current Local Time
    07:18 AM
    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.

  10. #10
    Member
    Join Date
    March 21, 2013
    Location
    Phoenix, AZ
    Posts
    275
    Current Local Time
    05:18 AM
    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.

Page 1 of 2 12 LastLast

Similar Threads

  1. Alive in the Lab: Debugging Artificial Intelligence
    By Alive in the Lab in forum Blog Feeds
    Replies: 0
    Last Post: December 12th, 2017, 12:15 PM
  2. Need help debugging a script
    By dtp81390 in forum Dynamo BIM
    Replies: 0
    Last Post: April 28th, 2017, 04:00 PM
  3. Replies: 0
    Last Post: September 4th, 2014, 09:15 AM
  4. Replies: 0
    Last Post: May 28th, 2013, 09:15 AM
  5. debugging build error
    By Alex Cunningham in forum Third party Add-Ins, API and R&D
    Replies: 7
    Last Post: June 13th, 2011, 11:41 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
  •