Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
Use Report, viz(), and dbg() for conditional println and debug visualizations
jnewth
Member, OS Professional Posts: 88 PRO
Earlier this year I wrote a utility called "Report". The one-sentence description is "Conditional debug visualization and println controlled by feature and not by code".
Here's an intro video: https://www.youtube.com/watch?v=Eu7puEa8Oak
You can find the feature and functions here: https://cad.onshape.com/documents/e2576bfe13aaaabd67b0fe1d/v/4322f20d8f97ab12eeab937c/e/e954caf65d5d66b94f8bb90a
Here's how it works:
1. Import the feature Report in to your toolbar.
2. Import the functions dbg() and viz() in to your custom features.
3. When writing code, use dbg() instead of println and use viz() instead of adding debug entities through debug or addDebugEntities functions.
4. When your custom feature call viz() and dbg() functions instead of println() and debug(), the Report feature will enable the console printing and debug visualization for only the viz() and dbg() calls you want to activate, all controlled by keyword.
5. Suppress and unsuppress Report features to enable/disable visualization in your custom feature while your custom feature is being edited:
Note: This is very similar to another reporting tool I wrote a while back. I've renamed that tool "Log" as it's much more focused on mimicking logging tools like log4j but otherwise its behavior is unchanged. If that is a better match for your needs you can read about it here: https://forum.onshape.com/discussion/23476/featurescript-writers-stop-using-println-and-start-using-report-new-featurescript-announcement
Let me know what you think!
Also big thanks to my friend and colleague @Ethan_K for encouraging me to polish up and ship Report.

Comments
@jnewth thanks so much for creating and sharing this. It is proving invaluable in a current project I'm working on (as you know!) which otherwise was full of numerous messy debug and println's…
My surface tweening feature is over 2000 lines of code but most of it is diagnostics as I build the core logic.
I wonder how much of that I could scrape out of there using this.
Derek Van Allen | Engineering Consultant | MeddlerI literally just stumbled upon the other video this morning! Great work!
Ramon Yip | glassboard.com
@Derek_Van_Allen_BD That's kind of you to say. I hope that if you start using Report you won't need to scrape it out — you'll be able to leave (at least some of) it in, and just disable it for your users, while re-enabling it when you have to fix something weird that they've done ;)
There are a few other niceties, for example, viz() only adds visualizations, dbg() only writes to the console. The standard library sometimes does both, a behavior I do not care for.
Anyhow, give it a whirl. I use it constantly now in my own code (first step is always "import Report"). I'm curious if others will find it to be as useful as I do. @GregBrown and I were using it to debug some code he's working on, and I think he saw the value of being able to write all the debug he wanted and being able to selectively enable/disable/reenable as he went.
@jnewth theoretically that script is really meant to be a utility function for other scripts to be built on top of so the diagnostics are really only there while I muddle my way through implementation of higher level math concepts than I should have any business getting myself into. Once the foundation is laid there should be fairly little reason to return to the barest basics.
Derek Van Allen | Engineering Consultant | Meddler