Demonstration: Enhanced Debugger FeatureScript

deDev0
deDev0 Member Posts: 5 ✭

Yes! The debugger can actually be smooth to use. And with this little trick, you can surgically Debug!

Essentially this involves incorporating the → 'arrow' syntax, and a standard use of Lambdas to bypass the ever abundant "context". Some other functions for println, and colored Debug are also included.

https://cad.onshape.com/documents/1b537493cc24dea3fbea7e56/w/22ee6367e145bb6e2d9b5052/e/d18fee2f2b526d12bc7c0f50

Here are the snippets for easy access. Though the actual document is fully commented.

var c is Context = context;
var clrs = [DebugColor.RED, DebugColor.GREEN, DebugColor.BLUE, DebugColor.CYAN, DebugColor.MAGENTA, DebugColor.YELLOW, DebugColor.ORANGE]; // DebugColor.BLACK

var d = s => { c -> debug(s); return s; };
var dc = (s, clr is DebugColor) => { c -> debug(s, clr); return s; };

var p = (arr is array) => println(arr -> foldArray((a, b) => { return a ~ "\n" ~ toString(b); }));
var pl = (s is string) => println("-=-=-=-=-=-=-=-" ~ (s != "" ? " [" ~ s ~ "] -" : "" ) ~ "=-=-=-=-=-=-=-");

Comments

  • Konst_Sh
    Konst_Sh Member Posts: 170 PRO

    Nice to meet same arrow syntax abuser as myself 😅

    Using for long time an overload of debug function which takes value as first argument and context as second one and returns value.

    export function debugReturn(value, context is Context)

    {

    debug(context, value);

    return value;

    }

    CADSharp - Onshape custom programming services + Onshape mechanical design services