Yes indeed I was able to get it working. Steve was a great help both in this thread and via several PMs…
I actually had it working earlier than I thought, but mistakenly believed that clicking Run in NetBeans should rerun the script once you had first launched from the Ruby console in SU. It doesn’t.
As you may gather, I’m not used to working with an IDE.
I’m still curious where you find the shortcut you implied was created by Automater.
PS. And THANKS for the thread, and the how-to. Without both, I’d never even have tried. Look forward to learning how to use it now.
Is that NetBeans specific? Because that’s not a requirement with RubyMine. One only need to ensure that one set the paths correctly when setting up the remote debugging.
I doubt it is NetBeans-specific, as all debuggers talk to SketchUp through the same interface and when I follow the procedure I gave it works fine. It may well be some difference between my system and Neil’s “older Mac” (e.g. I am running the latest non-beta Sierra), it may have to do with the specific code I was trying to debug (callbacks in a Tool), it may be some picky detail of how I am using NetBeans, or it may be mystic karma. All I can say for sure is that prior to discovering that technique I was getting bizarre results such as when I place a puts statement on the line immediately before a breakpoint, reload the file, and then trigger the extension from a menu item, I get the puts output in the Ruby Console but Ruby does not stop at the breakpoint.
I plan to spend some time today carefully trying things out to see if I can find an explanation…
Not sure I’m going to be able to reproduce Steve’s experience yet - I’m having some difficulty keeping the debugging connection going.
Have had some success, but now the code isn’t breaking and SU Ruby just keeps running (into an error) which I was setting a breakpoint to help analyze.
Will ‘take it from the top’ again and restart SU in debug mode, then reattach from NetBeans.
That’s worked, but why does it detach later? Maybe I clicked the red [ ] stop button left of Continue, by mistake? If so, why wouldn’t it Attach Debugger again?
First a well-deserved thank-you in appreciation for the effort put into creating this post.
Neil, Thanks for the NetBeans installation guide. Very, super-helpful!!!
Steve, Thanks for your clarifying comments and answers. As always, very helpful.
John, Thanks for the detailed questions and coments.
Thomthom, Thanks for the RubyMine mention.
I followed the instructions and got everything to work nicely.
Being able to use a powerful IDE is great in terms of having auto-complete, view definitions, classes, methods; having many ways to quickly navigate the project; having the ability to add break-points and observe variables, etc. I feel the coding benefits are well-worth the effort of installing an IDE and connecting it to Sketchup in a debugging relationship.
However, I have to share a bit of my disappointment after running a few scripts following the described process.
First, being unable to run the script directly from NetBeans and have it execute in Sketchup directly is inconvenient, but not terrible. Having to drop the line load ‘C:.… \RubyProject1-File1.rb’ manually into Sketchup’s ruby console is kind of inefficient but not the end of the world. Maybe a Netbean plugin would solve this inconvenience. I wish I knew how to write one, but I am a novice at Ruby and my only programming experience has been using Visual Basic and a few other proprietary application-specific scripting languages.
Second, and this is the most disappointing of all, I was expecting that if I added break-points in a given section of my script, and individually executed (stepping-into) every line of the code in that section; I would be able to see the individually corresponding results being plotted in the Sketchup screen as every line was individually processed. That is assuming you have multiple monitors, or a large-enough one to see the IDE and Sketchup simultaneously. This would have been very helpful, particularly for novices like me. I have used the same technique in Microsoft’s Excel and it really increases your productivity, as you can instantaneously connect the code to the results on the screen and make the appropriate corrections. Instead, nothing happens in the Sketchup screen until the whole script has finished, no matter break-points, stepping through individual lines or anything. It is just like using Sketchup’s ruby console in that regard. This might be a deranged question, but for wat is worth, … is there a way to observe the results of executing individual lines of code using the stepping function in the IDE (assuming they have a visual manifestation, like and add_face command or executing a transformation) being plotted in the Sketchup screen???
Before I started to learn how to script for Sketchup, I though Sketchup would already have an integrated IDE, kind of like the way Microsoft’s Excel has an integrated visual-basic IDE. I found a plugin called Ruby Code Editor (written by Alexr Schreyer) that looks like an effort in that direction. RCE has features like code completion for Sketchup classes and methods, single-undo to undo all the script changes in one click, etc. However, it does not currently have the ability to insert break-points and run the code line-by-line. It would be interesting to see if a feature like that would allow RCE to reflect the results of executing individual lines of code on the Scketchup screen.
Finally, since we are on the subject of coding efficiently and learning to script for Sketchup, would there ever be a macro-recorder feature in Sketchup, like there is in Autocad, Blender (as a plugin) or MS-Excel?
+1 for this request. When I learned excel I used the record macro feature a lot. I would love to see something like this built into SketchUp. Is it beyond the abilities of an extension (i.e. limitations of the API)? @thomthom, @DanRathbun
There was another post recently raising this request. As I recall, some of the old-timers noted on that topic that the macro recorder idea has been around forever and the SketchUp developers chose to provide the Ruby API instead. There are no “hooks” in the Ruby API to capture keypresses, mouse moves and clicks, Tool invocations, etc. so I don’t think there is any way to implement a macro recorder as a Ruby extension.
Edit: I should clarify that statement. A Tool implemented in Ruby API can capture keystrokes, mouse moves, and clicks while it is active. But as soon as you activate any other Tool, the first one is deactivated or suspended and can no longer track what is happening.
You could try Jim’s Ruby Toolbar. It allows you to select a Ruby file to load and reload it (after edits) by clicking a single button. Not as nice as if NetBeans had a command to do it, but much easier than cut-n-paste in the Ruby Console!
I think that all of NetBeans is programmed in Java. I wondered how plugins are written because I wanted to see if it would be possible to add “folds” in the editor for more kinds of code (as is, it only does modules, classes, and defs - no if statements, code blocks, etc. I suppose it is out there somewhere, but I couldn’t find clear enough documentation to even get started…
I agree that would be very nice. I don’t know the technical explanation, but for whatever reason that isn’t how the hook for the debugger is implemented, so no IDE can overcome it. The view is frozen until the debugger lets SketchUp’s main loop start running again.
Yes, a macro-recorder would make Sketchup scripting accessible to a lot more people. However, like Steve pointed out, it seems like an extension won’t work. It would have to be implemented by the Sketchup development team. Maybe some day.
The API have limited callbacks for usage of native tools. You could probably make some form of macro recorder, but you’d have to use a lot of observers to couple together the info you need.
As for generally capturing keypresses/mouse movements, not supported by the SU API, but via a Ruby C Extension you could hook into native callbacks for this.
First: It should be possible to create a toolbar button in NetBeans that would communicate with a SketchUp extension to tell it to load a file.
Second: It might be possible to send (load) individual lines or blocks of code to be loaded in SketchUp. This would probably come at the expense of being able to see variables in the debugger. For example I’m envisioning a ‘refresh SketchUp’ feature in NetBeans. This would somehow ‘return’ from the current execution, and then from SketchUp automatically load a newly created file with the remaining code.
Ok. This probably really wouldn’t work in real life though. Just musing out loud.
Hmm…This needs someone with more expertise about the Ruby debugger API and how Trimble implemented it for SketchUp. In particular, does the API include a means for the debugger to send arbitrary commands or file-load commands to Ruby, vs purely debugger-related stuff such as tracking file line, managing breakpoints and watchpoints, fetching variable values, etc. For comparison, most Javascript debuggers include a console in which you can type arbitrary JS code for execution. Lacking such a capability in the debugger API, you’d have to build a workaround, e.g. a “listener” extension that would monitor a network connection for instructions, and the programming in NetBeans would require Java/NetBeans expertise. Also, in this case I think the reload command could only work while SU is “free running” (i.e. not stopped by the debugger) because while stopped, no part of SU except the debugger is able to do anything.
I was thinking down the lines of having an extension in SU that would listen for files to load. From Netbeans then, perhaps lines or blocks could be marked to be loaded into SU. Still not a very good solution.
For myself I’m just happy to be able to debug without all the puts.
I would add a button in SU to load a ‘loader.rb’
In the loader.rb I would break everything I wanted to see into smaller defs, then un-comment one line at a time and reload. In this way you would be able to see the results of each part before continuing.
Alternately you could have a text file with a list of files to load. In SU the toolbar button would parse the list and let the user select the file to load.
If I would know how to create extensions in NetBeans I would create a ‘listener’ in SU and then have NetBeans tell it which file to load.