Setting Up NetBeans with Sketchup Intellisense, And Debugging

ruby
debugging
ide
codeeditors

#1

I decided to do a topic on setting up NetBeans for SketchUp/Ruby development with debugging.
Steps are similar for Mac and Windows, but where they differ the steps are included for both.

1. Install NetBeans

a. Download and install Java Platform (JDK)

b. Download and install NetBeans Choose your platform (Mac or Windows)

2. Install Plugins for NetBeans

a. Go to NetBeans Plugins
b. Type ‘Ruby Rails’ in the filter and then download the Plugin.

c. Download 'Path Tools’

d. Install the plugins you just downloaded

  1. Run NetBeans. Select Tools>Plugins
  2. Click the Downloaded tab and then click Add Plugins
  3. Select the files you downloaded including the jar file but not the xml file. (On Mac this is two steps because you can only choose between *.nbm or *.jar, not both)
  4. Install And restart IDE

    e. repeat these steps for the Path Tools plugin you down loaded.
3. Setup code completion, documentation and intellisense.

a. Create a new project > Ruby Application
b. Go to Tools > Options to setup code completion and hints.

c. In your main.rb start coding, create a variable and then verify auto complete is working. In the picture below ‘t’ is a string variable. On the second line after typing the period a list of methods for strings should show.
d. Click the button in the documentation window to locate your ruby stubs.


e. If Path Tools installed correctly press the ‘Explore Path…’ button or navigate to the file location manually.

f. Down load this as a zip and copy the Sketchup folder.
g. Paste the Sketchup folder in the location of your ruby stubs.
Windows

Mac

h. Verify that SketchUp specific auto complete is working.

4a. Setup SketchUp for debugging (Windows)

a. Download the SURubyDebugger.dll for the version of SketchUp you are using. Paste it in the same folder as your Sketchup.exe.
b. Create a shortcut and edit the target to include the commandline arguments for debugging.

4b. Setup SketchUp for debugging (Mac)

a. Download the SURubyDebugger.dylib for the version of SketchUp you are using.
b. add it into the application package in the frameworks folder.


c. create an application shell script to run SketchUp with debugging arguments. (there might be a better way. I’m not very familiar with Mac.)

5. Debug your project

a. Launch SketchUp for debugging using the shortcut set up in step 4. (On Mac A terminal window is opened and for me it asks for my password. I had to enter this before I could continue.) Sketchup will appear frozen or locked up until the debugger is attached. This is normal it’s simply waiting on the debugger.
b. In NetBeans Attach the Debugger.


c. SketchUp should be frozen until the debugger attaches.
d. Open the rb file to debug, and set several break points. (I’ve noticed sometimes the first breakpoint or two won’t be recognized initially.)

e. Make sure any changes to the file are saved.
f. Load the rb. file from the Ruby console in SketchUp. Running the file from NetBeans will run it in your local Ruby (with errors), and not in Sketchup. This is one of the most important details for new users.
g. When a break point is encountered the code will stop executing and SketchUp will be frozen until it continues. NetBeans does not automatically come to the front.
h. Step through code and watch variable values in NetBeans IDE.


i. When finished hit continue and see results in SketchUp.

6. Deploy your project (Added 7-22-17)

I do my main development in a git repository. I place add debug toolbar button in SU to load the file I’m currently working on. However at some point it’s necessary to copy the files to the plugin directory so all the plugin is up to date. This can be done by creating a batch file to copy the files to correct location. This is especially useful when deploying to many computers on a network.

Here are the steps to access you update script from within Netbeans.

a. Right click anywhere in the empty space of an open file, and select Send To>Configure.

b. Click the Add button then set the script name (‘Update’ in this case), last enter the full path to the batch file in both the script field and the area below it. Make sure it is enclosed in double quotes.


c. When you are ready to update your plugins simply right click in the empty space of any file and select Send To>Update.

Here is the batch script I use. Notice that some of the locations receive scrambled files for security.

echo off
echo Copying Files
xcopy /y "C:\Users\User\Documents\SourceTree Projects\Building Creator\RBScripts\Building_Creator\lib\*.rb" "C:\Users\User\Documents\SourceTree Projects\Building Creator\RBScripts\Building_Creator\Deployment\" >nul
echo Encrypting Files
FOR %%I in ("C:\Users\User\Documents\SourceTree Projects\Building Creator\RBScripts\Building_Creator\Deployment\*.rb") DO "C:\Users\User\Documents\SourceTree Projects\Building Creator\RBScripts\Building_Creator\Deployment\Sketchuprubyscramblerwindows.exe" "%%I" >nul 2>nul
move /y "C:\Users\User\Documents\SourceTree Projects\Building Creator\RBScripts\Building_Creator\deployment\*.rbs" "C:\Users\User\Documents\SourceTree Projects\Building Creator\RBScripts\Building_Creator\Deployment\encrypted" >nul
echo Updating Neil-Home (Unencrypted)
xcopy /y "C:\Users\User\Documents\SourceTree Projects\Building Creator\RBScripts\Building_Creator\deployment\*.rb" "%userprofile%\AppData\Roaming\SketchUp\SketchUp 2017\SketchUp\Plugins\Building Creator\" >nul
echo Updating NeilCo (Unencrypted)
xcopy /y "C:\Users\User\Documents\SourceTree Projects\Building Creator\RBScripts\Building_Creator\deployment\*.rb" "\\NEILCO\Users\Server Computer\AppData\Roaming\SketchUp\SketchUp 2017\SketchUp\Plugins\Building Creator\" >nul
echo Updating BCC-Dave (Encrypted)
xcopy /y "C:\Users\User\Documents\SourceTree Projects\Building Creator\RBScripts\Building_Creator\deployment\encrypted\*.rbs" "\\BCC-Dave\Users\Dave Burkholder\AppData\Roaming\SketchUp\SketchUp 2017\SketchUp\Plugins\Building Creator\"  >nul
echo Updating PAINTCOUNTER (Encrypted)
xcopy /y "C:\Users\User\Documents\SourceTree Projects\Building Creator\RBScripts\Building_Creator\deployment\encrypted\*.rbs" "\\PAINTCOUNTER\Users\Paint Counter\AppData\Roaming\SketchUp\SketchUp 2017\SketchUp\Plugins\Building Creator\"  >nul
echo Removing temporary deployment files.
del "C:\Users\User\Documents\SourceTree Projects\Building Creator\RBScripts\Building_Creator\deployment\encrypted\*.rbs" >nul
del "C:\Users\User\Documents\SourceTree Projects\Building Creator\RBScripts\Building_Creator\deployment\*.rb" >nul

I get an error displayed for any computers that are disconnected from the network.

I hope this helps.


Setting configuration IDE RubyMine for SketchUp API
Learning Ruby for SketchUp
The right choice of a Ruby debugger for Sketchup API
How to track BugSplat root cause
#2

Simply click at the end of the method and press Ctrl+Space to see documentation.

My setup steps for Mac were wrong. The .dylib file must go in the frameworks folder of the app contents.
It works on Mac for me.


#3

Also note that the ui.rb file must be edited or it won’t show up in auto complete.

@thomthom https://github.com/SketchUp/ruby-api-stubs/issues/24
https://forums.sketchup.com/t/ruby-code-editor-of-choice/38312/18?u=neil_burkholder


#4

ctrl+space opens Spotlight on my Mac, but based on your telling me there was a keychord I checked the NetBeans shortcuts preferences and found ctrl+shift+space works on mine. Thanks!

I knew that. Forgot to mention it to you. Sorry!

I can connect to the SU debugger, as proved by the fact that I can breakpoint the sample main.rb file in the Project. But so far I can’t get SU to stop at a breakpoint I plant in a pre-existing file within the Plugins, even after explicitly reloading it while SU is running. There must be some subtle detail I still don’t have right.

Aha! Thank for the heads up!


#5

Are you sure it’s running in SketchUp not in your local Ruby? That was one of my biggest hurdles. A simple way to check is to see if a puts or UI.messagebox displays in SketchUp.


#6

The “Hello World” puts appears in the SU Ruby Console, and a UI.messagebox I edited in also opens. So, yes, I’m pretty sure I’m connecting to SU.


#8

Also make sure any changes to the file are saved before loading it from the SU console.


#9

I opened the file in NetBeans using the path to the plugin’s folder then added breakpoints in several places. Then clicked “Save All” (though it’s greyed out - maybe it doesn’t work in this circumstance?). I wonder if the problem is that the file isn’t explicitly included in the Source Files section of the project even though it is open in the editor? How does one add an existing file to a Project after the project is already created? Maybe I need to start a new project?

So many questions and possibilities. So close but not there…


#10

It shouldn’t have to be in your project. Just do File>Open File.

Just drag files into your project folder. Also you can add sources by right clicking your project and clicking Properties.

Did you make sure your file is being loaded? Puts show in ruby console after calling load ‘fullpathto/file.rb’?


#11

I just tried this: using the NetBeans editor I added a puts statement into one of my extension’s files, saved the file via NetBeans, and then restarted SketchUp. When I run the extension, the output of that puts shows in the Ruby Console (which proves I’m hitting the right file), but the breakpoint on the immediately following line does not “take”. There’s got to be some silly detail not in place yet…


#15

For others who might read this, the key to getting debugging working is that the ruby files must be loaded into SketchUp after it is started and connected to the debugger. If you are trying to debug an existing, installed extension you need to completely disable it first so that SketchUp doesn’t load any part of it during startup. Load the ruby using the SketchUp Ruby Console after initiating the debug session and everything works fine.


#16

I’ve been following this thread with interest. Got as far successfully as steps 1,2, and 3a and b.

Downloaded and installed the Plugins recommended, which said it had found and installed 24. The restarted.

But I’ve got stuck at Step 3c and 3d.

I’m not sure what to expect from

What do I have to do to ‘start coding’ to check if autocomplete is working?

And in 3d, I can’t find the ‘Documentation window’. Not in the Window menu.Not on any other menu that I can find. No icons to click at the bottom of the main.rb coding window as appear to be there in the example for step 3d.

I know @slbaumgartner has succeeded. Like him, I’m on a Mac, running El Capitan 10.11.6, SU2017 (and older versions). Have the 8.2 version of NetBeans and the JDK bundled with it.

I’d love to get this working, but don’t understand what I’ve done wrong, or I’m doing wrong, or not seeing, at this point.

Any help welcomed, Thanks in advance, Neil, for setting out the instructions clearly - just not quite clear enough for me at this particular part of the process.


#17

Type some Ruby code into the edit window for main.rb and see what happens. As you type you should see autocomplete suggestions in a popup list, and when you complete a method name you should see a popup documentation window for that method. If you installed both the plugins and the SketchUp stubs, this should work for both plain Ruby and for SketchUp classes and methods.

You can open the documentation popup window later by selecting a keyword or method and pressing ctrl-shift-space. If you precede the first use of a variable with a comment, the doc window will treat this as the documentation of that variable (!)


#18

I thought it wold be something I wasn’t quite doing right - I had just ‘typed a variable…’.

Once I put in the name of an SU ruby class or method, up pops the ‘document window’. So it HAS worked thus far. Onwards, then, to steps 4ff.

Thanks, Steve.


#19

Progress, but stuck again.

I’ve managed to find where and how to open the Automator window shown in Neil’s example, and input a modified version of his example script. My Sketchup.app is renamed to SketchUp 2017 to tell me which version is running.

"/Applications/SketchUp 2017/Sketchup 2017.app/Contents/MacOS/SketchUp" -rdebug "ide port=7000"

I can Run it from that location, and Automator’s output window says ‘Get Specified Finder items completed’ and ‘Running - run shell script’.

While it is running, an new SU icon labelled “Sketchup 2017” starts bouncing in the dock, but won’t open Sketchup when I click on it. I can only Force Quit.

While it is bouncing, I try to run a short piece of debug code in Net Beans:

puts "Hello World" 
mod = Sketchup.active_model

The NetBeans Output window below the main.rb code window says:
Hello World NameError: uninitialized constant Sketchup const_missing at org/jruby/RubyModule.java:2677 (root) at /Users/JohnWMcC/NetBeansProjects/RubyApplication1/lib/main.rb:7
I’ve clearly not ‘got’ something else.

I think I need to save the ,workflow file somehow - I find that it gets saved in an Automator Documents folder buried fairly deep in a long path, and I named it SUdebug.workflow
’~/Library/Mobile Documents/com~apple~Automator/Documents`

I’m really not sure at this point what is supposed to be happening.

Is this a Bash Shell file that should be used to start SU with the -rdebug switch, and the ide port set to 7000?

If so, I can’t see initially how to get it hooked up properly. How does the script get executed by Automator?

Reading on to Step ‘5 Debug your project’ it seems I should save the file somewhere, and run it as shell script. But where’s the 'shortcut created in step 4? that Neil refers to in Step 5?

So I saved to my desktop as SUdebug.sh, and double click it. Up pops a text editor, showing the file contents.

Look on Internet for how to run a shell script on Mac.

Use chmod a+x <yourfilename> to make it executable

then set to run by Terminal. Do that, double click it.

A success message in Terminal window, then bouncing SU icon in dock again, and a SU bugsplat. I saw it briefly buried under numerous other open windows, but couldn’t find it again as I closed them.

Try again from a clear desktop.

This time, before Bugsplat, I see this in Terminal window:

/Users/JohnWMcC/Desktop/SUdebug.sh ; exit;
Johns-iMac:~ JohnWMcC$ /Users/JohnWMcC/Desktop/SUdebug.sh ; exit;
2017-02-08 18:13:22.637 SketchUp[2622:277063] BugSplatFramework: initWithDatabase: defaultExceptionHandler is set
GVA info: Successfully connected to the Intel plugin, offline Gen9 
libc++abi.dylib: terminating with uncaught exception of type boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >: bind: Address already in use
/Users/JohnWMcC/Desktop/SUdebug.sh: line 1:  2622 Abort trap: 6           "/Applications/SketchUp 2017/Sketchup 2017.app/Contents/MacOS/SketchUp" -rdebug "ide port=7000"
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Process completed]

Looks as though it is finding port 7000 already in use from previous failed attempts?

And an open bugsplat window.

The top few lines of the Bugsplatreport say:

Process:               SketchUp [2622]
Path:                  /Applications/SketchUp 2017/Sketchup 2017.app/Contents/MacOS/SketchUp
Identifier:            com.sketchup.SketchUp.2017
Version:               17.2 (17.2.2281)

At this point, I am well out of my depth.

Will try restarting my Mac, and try one more time.


#20

Not a happy computer. On first restart both connected mice were disabled, so I couldn’t click on my username to login. Had to switch off with the power button, and start again from cold.

And on second restart, run the shell script again, with identical result as far as I can tell:

Johns-iMac:~ JohnWMcC$ /Users/JohnWMcC/Desktop/SUdebug.sh ; exit;
2017-02-08 18:13:22.637 SketchUp[2622:277063] BugSplatFramework: initWithDatabase: defaultExceptionHandler is set
GVA info: Successfully connected to the Intel plugin, offline Gen9 
libc++abi.dylib: terminating with uncaught exception of type boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >: bind: Address already in use
/Users/JohnWMcC/Desktop/SUdebug.sh: line 1:  2622 Abort trap: 6           "/Applications/SketchUp 2017/Sketchup 2017.app/Contents/MacOS/SketchUp" -rdebug "ide port=7000"
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Process completed]

Any advice? Is something else already using port 7000? If so, how do I find out what, or how do I change the ide port so both ends know what it has changed to?

Or any other suggestions. I’d really like to get this to work.


#21

When you start SU with the debug option, SU halts and waits for a connection from the debugger. During the wait you see the bouncing icon in the dock, but SU itself will be unresponsive. This is the same for any debugging session in SU, it does not depend on the NetBeans IDE.

You must attach the debugger to SketchUp in NetBeans IDE: Menu item Debug->Attach Debugger. In the resulting popup window, choose Ruby Debugger (ruby-debug-ide) in the selection list at the top and make sure that Host says localhost and Port says 7000 (assuming you launched SU with port=7000. These are the IDE’s defaults, but it pays to verify). The timeout is how long after pressing OK in this dialog before the debugger will quit if it can’t connect to SketchUp.

You can either start SketchUp first and then attach the debugger, or you can tell the IDE to attach the debugger and you have the Timeout interval to get SketchUp started.

PS: I launch SketchUp for debugging using a shell script file that contains:

#! /bin/bash
open "/Applications/SketchUp 2017/SketchUp.app" --args -rdebug "ide port=7000"

I run this in Terminal to start SU. I don’t have much experience with automator, but a lot with UNIX shell scripts!


#22

Finally got something running without errors.

I run the shell command once, and attach the debugger. Then SU starts.

I can now edit a file in NetBeans, save it, load it into Ruby console and it runs. But so far, only runs from Ruby console.

I have a very simple test file:
UI.messagebox "Hello World"

I’ve found the Run File command in the NetBeans menu, but when I run it the output below seems to imply it is NOT connecting to SU.
NameError: uninitialized constant UI const_missing at org/jruby/RubyModule.java:2677 (root) at /Users/JohnWMcC/NetBeansProjects/RubyApplication1/lib/test.rb:5
The terminal output says:
Johns-iMac:~ JohnWMcC$ /Users/JohnWMcC/Desktop/SUdebug.sh ; exit; 2017-02-08 19:09:02.774 SketchUp[1299:58417] BugSplatFramework: initWithDatabase: defaultExceptionHandler is set GVA info: Successfully connected to the Intel plugin, offline Gen9 objc[1299]: Class SKTextPath is implemented in both /Applications/SketchUp 2017/Sketchup 2017.app/Contents/MacOS/SketchUp and /Applications/SketchUp 2017/SketchUp 2017.app/Contents/Frameworks/SketchUpAPI.framework/Versions/A/SketchUpAPI. One of the two will be used. Which one is undefined. objc[1299]: Class HLRExporterBase is implemented in both /Applications/SketchUp 2017/Sketchup 2017.app/Contents/PlugIns/Skp2AcadHlr.plugin/Contents/MacOS/Skp2AcadHlr and /Applications/SketchUp 2017/Sketchup 2017.app/Contents/PlugIns/Skp2AcadSection.plugin/Contents/MacOS/Skp2AcadSection. One of the two will be used. Which one is undefined.
So although it isn’t causing an error, I don’t think it is working either.

I have very little experience of using debuggers, so I may well be missing something completely obvious to a user of them in any other context.

I set a couple of breakpoints in a simple file, saved it, and ran from the Ruby console. The first UI.messagebox pops up on screen (before any breakpoint), but when I Run file again from NetBeans, I still get message 'uninitialized constant UI"

Sorry, I seem to be being dense.


#23

That command is for test running stand-alone apps developed using the IDE. It won’t work with a Ruby file intended to be run in SU. A SU Ruby file is run immediately when you load it from the Ruby Console. When it completes, unless it wires something into the SU menus or toolbars, that’s it. You have to load it again to run it again. If it did wire things in and there are breakpoints in that code, they will be hit when you click the menu or toolbar. Somewhat clunky, but that’s how it is…

The series of warnings you see are issued every time SU starts. They are harmless, just reflecting that the developers put the same named classes into more than one of their dylibs and OS X is telling you about it. SU has had that flaw for years on Mac (I’ve pointed it out before). Normally those messages go into the system logs, so most Mac users are unaware of them. They are showing in the terminal because of the way you launched SU.


#24

I’ll add some clarification to the steps as soon as I get a few minutes.

Sorry I was out of town all day doing a software install. It looks like Steve did a good job answering your questions.

Were you able to get up and running?