Reading what is sent to the console?
-
Hi,
Is it possible to track what it is being sent to the console by other extensions via "puts" and "print"?
I've read a bit about $stdout, but don't really understand how all this works in Sketchup.Thanks,
jbb -
@jiminy-billy-bob said:
Hi,
Is it possible to track what it is being sent to the console by other extensions via "puts" and "print"?
I've read a bit about $stdout, but don't really understand how all this works in Sketchup.Thanks,
jbbYes. it is possible, though it involves "monkey patching" the definitions of the output functions you want to intercept. Monkey patching is generally deprecated because it can destabilize Ruby and other plugins in hard-to-predict ways. I note that since you want to intercept output from other plugins, this is very different from building your own private modifications.
In a nutshell (deliberately not code so as not to encourage the inexperienced to try it), you define an alias for the existing method then define a new method with the same name as the original that routes the arguments to your trap and then invokes the original so that the data gets to the console. I would not mess around with SketchUp's Console or $stdout, as they are already tweaked to make everything work.
Out of curiosity, why do you want to snoop other plugins' output?
Steve
-
Actually, since I posted I found another way to do what I want.
But thanks for your answer, that's interesting.So I guess that's how the custom ruby consoles do it?
Advertisement