Debugging of Macros
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Debugging of Macros
Hello,
is it possible to debug a macro (not a workbench) with FreeCAD? I use Linux, so I can't use Visual Studio.
It would be OK, if it is only possible about the command line (GUI would be nicer, but I will stay alive ).
Thanks in advance!
is it possible to debug a macro (not a workbench) with FreeCAD? I use Linux, so I can't use Visual Studio.
It would be OK, if it is only possible about the command line (GUI would be nicer, but I will stay alive ).
Thanks in advance!
Re: Debugging of Macros
What kind of debugging do you expect?
Often printing manual debug traces in the console is enough.
Often printing manual debug traces in the console is enough.
Re: Debugging of Macros
What do you mean by "debug"? There is no standard interpretation for this word. It basically means "test that everything is okay, and that there are no errors (bugs)".
So, yes, you can debug any macro, just by looking at the code, and testing each line in sequence until you find a problem.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Re: Debugging of Macros
With "debugging" I mean things like stepping, stop points, etc.
Of course, you can do a lot with console logging, but for bigger projects, it is a bit uncomfortable, so I asked.
usbhub
Of course, you can do a lot with console logging, but for bigger projects, it is a bit uncomfortable, so I asked.
usbhub
Re: Debugging of Macros
Sorry to hijack this thread, but I was about to ask the same question.
I get an error, but can't seem to set a break point so I and step through the code to inspect variables and objects.
Is there a separate workbench for this? Or is it all guess work?
I get an error, but can't seem to set a break point so I and step through the code to inspect variables and objects.
Is there a separate workbench for this? Or is it all guess work?
Re: Debugging of Macros
An option is the program Winpdb. Just search for it in the forum to get some details how to use it.
Re: Debugging of Macros
See this thread: Python workbenches debugging.
There is no difference between a workbench and a macro, it's the same thing essentially, it's Python code.
You should develop your code in such a way that is easy to test, using small functions and classes, so that it is obvious where the errors are, and you don't have to inspect every single variable and so on.
For example, I dislike the way many macros are programmed because they use a lot of global variables. Creating classes and modifying the attributes of a class instance would be much better than using a hundred global variables.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Re: Debugging of Macros
Thanks Vox, great post you sent us to - I'll be checking out 'pdbpp'.
The program I have trouble with only has 35 lines and I know exactly where the problem is - I just don't know why.
The program I have trouble with only has 35 lines and I know exactly where the problem is - I just don't know why.
Re: Debugging of Macros
@vocx would you mind finding examples illustrating your point of good coding standards and vice-versa ?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Re: Debugging of Macros
Well, that's just general good Python knowledge. Make things small and readable. For example, no more than 3 levels of indentation is good practice. If you need more levels, then encapsulate the inner levels into a function, and call that function.
In the Doxygen page I placed relevant documents for the reader. This write up by Moult summarizes many good programming practices; good for both C++ and Python that we use in FreeCAD.
carlopav wrote: ↑Sat Aug 10, 2019 9:05 pm Any advice on codeformatting Yorik?
I did find very useful this article by @Moult https://sevenstrokes.net/learn-how-write-good-code .
Maybe it is off topic... But it was really helpful to me.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.