Looking for advice to get Ruby installed & VSCode configured on Windows 10

Yes the options look fine.

Thanks Dan, I seem to be getting somewhere now; Ruby 2.7.7 is installed and the gem install rubocop-sketchup command worked from the Command Prompt with Ruby.

However, when I try to use the bundle install command in the same Command Prompt, it returns “could not locate Gemfile”. I’ve no idea what that is so I’m not sure what I need to do next.

The “could not locate Gemfile” message would indicate that the command caused the attempt to install a gem, in order to complete the command.

I guess that any bundle command requires that the bundler gem be installed.

For basic information on gems …

Morning Dan,

I didn’t see any instruction on either the aforementioned GitHub page or the RuboCop SketchUp page that explicitly stated how Bundler was to be installed. I did do some research and found that the RubyMine documentation states that " As a rule, the installed Ruby interpreter comes with Bundler installed." I may have misinterpreted this to mean that when you install Ruby, Bundler automatically gets installed with it. I have since found the gem install bundler command, however, before I use that, perhaps I should explain where I am at and ultimately what I am looking for.

As mentioned above, most of my coding experience is writing Macro’s with VBA in my daily CAD software (although, I have written the occasional small Desktop App in C#/VB.Net with Visual Studio). This has the same built-in IDE that you find in Microsoft Office applications (Excel, Word etc…) but with a reference to the Software developers VBA API. With that I have access to the IDE within my CAD software where I can write code, then debug it (as it is statically typed, it will highlight any incorrect variable declarations etc…) and if successful, it will then interact with the open model of the active session. It doesn’t have true Intellisense like in Visual Studio, but it does give some tooltips for methods etc… . In addition to this, I found and installed a separate Code Formatter for which the sole purpose I use it, is to indent the code to predefined settings making for better readability.

In short, I’m hoping that with VSCode, I will be able to hopefully:

  1. Write code that I can debug and interact with an active open session of SketchUp.
  2. Utilize true Intellisense that will aid my learning and writing of Ruby providing on-the-fly tooltips as I type.

As I am completely new to Ruby, I don’t even know if the VSCode Project for SketchUp Extension Development will provide the above or not, nor do I know if I truly need RuboCop / Bundler etc… because I don’t know their purposes. As a beginner, I accept the task of learning the language will be difficult in itself, but the absence of a complete detailed step-by-step guide from download to completion of installed, to provide all necessary steps to enable someone to be ready to code, is frustrating in itself. I at least expected this crucial knowledge to be at https://developer.sketchup.com of all places, but it’s simply devoid of that kind of kind of vital information.

For a simple start you can copy ‘n’ paste code into the Ruby Console (Extensions → Developer → Ruby Console). Notepad, Notepad++, or VS Code will be fine for writing code.

Otherwise, if you want to create an extension you generally need a registration file (e.g., “MyExtension.rb”) and a main file (e.g., “Main.rb”). The registration file goes into your Plugins folder (C:\Users\username\AppData\Roaming\SketchUp\SketchUp 2023\SketchUp\Plugins) and the Main.rb goes into a folder that you will create (with the same name as your extension, e.g., “MyExtension”).

Dan has provided examples. Here’s one: [Template] for Basic SketchUp Extension - Developers / Ruby API - SketchUp Community

Or,

[Template] Multi-File, Multi-Class with SharedConstants Mixin - Developers / Ruby API - SketchUp Community

If you just want to test and keep scripts, you can also use the Toolbar Editor extension to save and run scripts.

1 Like

Welcome to SketchUp where everything is “sketchy” … including the documentation.

As James said above, you do not need a full-blown IDE to code for SketchUp. I myself do not use one. I use Notepad++. I’ve never myself found it necessary to step through code with the debugger. (But I’m weird. I have a very good memory and find that Ruby’s exception messages are adequate to track down the cause of most errors I make.)

Learn the basics first. Crawl before you walk, walk before run, etc.

Yes, it can. You need to copy the debugger into SketchUp’s binary directory and I believe install the Ruby plugin into VSCode. For the Intellisense you need to have the SketchUp Ruby API stubs where the IDE can access them.

Rubocop is a “syntax nanny” that examines Ruby code and displays warnings for poor practice, etc.
(I don’t use it myself.) I suppose that bundler is needed to install it.

Along with this there is a SketchUp specific extension to Rubocop that checks SketchUp API specific coding syntax and rules.

I think this may have been packaged as a gem and made available on the RubyGems server.

BUT, the use of Rubocop to check your code is done OUTSIDE SketchUp’s Ruby in a standalone Ruby installation. Usually fired from a command prompt.

Again, you do not absolutely need this “nanny” feature to get started learning and coding Ruby.

Since this is a task that does not run within SketchUp nor within your IDE, you can skip this for now. (Later on, you might be able to set up an IDE task that fires the cop “nanny” from inside the IDE. But it still will run outside it in a system level Ruby process.)

Ruby was designed to be very human readable. But syntax convention can play a large role.

Ruby uses 2 space indents as a convention. It is important when pasting nested code into the forum when you need help. Larger idents with many nestings can force readers to use horizontal scrolling just to read your snippets. This does not make people happy. Try to keep line widths to 80 characters or less.

In you editor (whatever you choose) you should set it to replace TAB characters with two SPACE characters. Otherwise, when you go to paste something in a forum for help, most forums will display TABs at 8 spaces.


I think that VSCode is a much watered-down free edition of VS. It is likely that you can do anything that VSCode can do in VS if you have it. The main difference might be that VSCode loads quicker?

The main thing you need to get into your mind is that SketchUp coding is usually event driven code.

Yes, the simplest kind of code can be a macro-like task fired by the event when the user clicks a toolbar button or a menu item. Coders usually start with this.

Next, they often graduate to context commands using the UI.add_context_menu_handler registration method.

Creating interactive tools and extensions that react to model modifications using observers are more advanced.

2 Likes

Hi James,

Thanks for the links, I’ll take a look at them when I get a chance.
I’m not so fussed about the console, my interest lies more in eventually writing an extension and having the IDE (VSCode or Visual Studio) be made ‘SketchUp aware’ and to avoid something like below:

  1. Write some code
  2. Save the file
  3. Open up SketchUp and manually start the Extension etc…

Ideally, I want SketchUp already open on 1 screen and the IDE on another, and have it interact directly with that open SU session.

That would be ideal! I’m not sure if that is possible (but I’m sure there are more efficient workflows than mine). Maybe @DanRathbun could fill us in. Is copy/paste to the Ruby Console most efficient with snippets and toolbars? With Html Dialogs it seems files are copied to temp folders at startup and can’t be changed ‘on the fly’ so restarting is the required. Is it possible to step through code while SU is running?

I usually have VS Code open, edit, save, and restart SU after changes. I do this dozens of times a day, so any improvement there would be welcome.

In VS Code I have Ruby and VSCode Ruby extensions installed. HTML and javascript extensions would probably be useful. I’ve read the instructions that you mentioned… that’s why I chimed in to mention some simpler ways to get started.

Best of luck.

1 Like

Nothing wrong with that, if that’s what you’re comfortable with. I’ve simply gotten use to doing it so that I can see exactly if the code is behaving as expected, or to track down where it’s going wrong.

The first thing I did was take a look at the large list of resources that you have compiled and I have been reading through the ‘Automatic SketchUp’ book. I’m not sure how relevant it is these days, as it is clearly dated, however, aside from the many mistakes that weren’t caught by the proof-reading process, it’s been a useful insight into some of concepts and syntax.

[quote=“DanRathbun, post:9, topic:242410”]
You need to copy the debugger into SketchUp’s binary directory and I believe install the Ruby plugin into VSCode. For the Intellisense you need to have the SketchUp Ruby API stubs where the IDE can access them.
[/quote]Sounds good, I’ll investigate both of those.

I probably won’t bother with it then, prefer to start ‘vanilla’ and consider it later once am I more familiar with Ruby.

I have noticed that, but with it not being statically typed, it’s taking some getting used to how terse its often written. Here’s an example showing my VBA IDE, notice 2 things:
l7O3Gh8xHL

  1. The code is written with no whitespace other than where the IDE needs it. The indenting process can be applied to a single function, an entire module, or every part of the project, applying the same consistent formatting which makes it visually pleasing on the eye. It would indent to additional levels if there were conditionals (If statements, For/Next loops etc…) even if they are nested. It obviously creates consistency and saves a lot of manual typing.
  2. I’ve no need to debug the code as I already know there are no syntax or other errors, due to how basic the procedure is. All it does is draw a Square and when you see me press the Green ‘play button’, you can immediately see the square being drawn in the view window adjacent. This is the style of coding interaction I am hoping that can be achieved with SketchUp.

I appreciate the replies, hopefully I’ll soon be in a position to start learning properly

I use @ene_su plugin ( Eneroth Script Runner) which lets you to throw your ruby file to sketchup viewport in order to run the code, so you only have to save in VS Code and throw your file to SketchUp.

If you change your html file you only have to run again your ruby code to read html file again (not neccesary restart SketchUp), almost for most of my plugins…

This can help you too:

2 Likes

Thanks for the tip. Installed.

Was also considering this one: On-Demand Ruby / Extension Loader | SketchUp Extension Warehouse

I’ve been stuck on an vue.js problem forever so fear adding anything new to the mix at the moment :slight_smile:

1 Like

Afternoon Dan, I’ve not had much chance to get back to this until now. As I couldn’t find any info on using Visual Studio for development, I’ve just gone with VSCode instead. I’ve been following the instructions on page you linked and installed the Ruby and Ruby Solargraph extensions. Next, I installed the Yard Gem, however, when I attempt to install the Solargraph Gem, I get this error.

Do you have any idea what’s wrong?

It turns out, not installing the DevKit version is the reason for the Solargraph Gem installation failure above, so I’ve installed that version of Ruby and I had no error this time round.
One thing that is a little disconcerting, after running the final command in the gems section of the article yard gems sketchup-api-stubs nothing happens in the Command Window, so I’m unsure if it was successful or not. Is this expected behaviour?

YARD is a Ruby documentation generator. Running it from the command line would produce local API documentation (HTML pages.) I have no idea why you would want to do this. You can use the online API documentation.

Because it’s explicitly listed in the instructions listed here

Explanation for running the yard command

yard Executable : File: Getting Started Guide — Documentation for yard (0.9.34) (rubydoc.info)

Yeah, there’s a lot going on in that page which is way above my level of understanding at this stage. I can see from the page that the command I used yard gems sketchup-api-stubs should have built a YARD index for gems (whatever that means). I’m not sure whether its actually important that I understand any of that at this stage, however, all I really am interested in is, did the command actually do anything, because there is no indication in the CMD window that it did.

So I think I have followed all the instructions to configure VSCode, however, I don’t believe it’s providing SketchUp-specific Intellisense and I’m now trying to decipher why not. It seems that the behaviour that I’m seeing in these images is the same that I see in my VSCode.

Did you have a look at this?

And this issue is still open …