Getting Started with Sketchup's SDK
-
Hello,
What I want to do is to get started with the C++ part of Sketchup. Basically I'm trying to interact with a Sketchup drawing using an external program.
Sketchup has the console feature, which is pretty close to what I want to do, but not exactly. I would like to be able to send lines of code to that Console feature in real-time.
I took a look at the page http://www.sketchup.com/intl/en/developer/su-api/index.html and it gives a few examples of C++ code, which I'm familiar with in a classroom setting.
But, what I'm looking for is a bit of advice on how to get started.
In order to use the SDK, I need some sort of compiler, but where do I put all the include files? What compiler is acceptable? Do I have to use a Microsoft's Visual Studio?
Basically what I'm asking the forum is for an outline of how to get started. Download Sketchup... get a copy of software "x"... put include files in location "X"...
Let's say I just want to send a set of data to create an edge in Sketchup from a DOS command line, what should the command line read so that I'm in the right place to do it? By this I mean you wouldn't have it say C:>notepad, or something like that. What should it read?
Any help would be appreciated.
-
Still not sure what you want to do. You use the Ruby API to interact with a model which is open in SketchUp. You would use the SDK to interact with a .skp file on disc.
-
@jim said:
Still not sure what you want to do. You use the Ruby API to interact with a model which is open in SketchUp. You would use the SDK to interact with a .skp file on disc.
What if I want an outside program controlling an open Sketchup model in real time? How do I go about it?
I understand I'd use some of the code in the SDK website, but what else do I need?
Which compiler?
Where does the compiled C++ file go?
Which .dll files do I need?Basically I'm looking for a simple outline of what's needed to get a Sketchup model modified in real time from an outside program. Not a plugin, but an independent program doing the controlling. It would be an .exe.
I'm more familiar with C++ than Ruby, but I could use it too.
Let me ask you this: How would you go about having an outside program control a Sketchup model, while the model is open?
I'm looking for something a bit more detailed than saying, "use the Ruby API". Thanks in advanced for any help.
-
The C API only let you read and write SKP files at this time. It doesn't let you interact with the live model.
Only the Ruby API interacts with the live model. What you could do is create a Ruby C Extension - and use that to bridge the communication between your application and the SketchUp Ruby API.
We are about to release a GitHub project with a Hello World example of a Ruby C++ Extension. Though it's not fully complete yet. You can keep an eye on our GitHub account: https://github.com/SketchUp/
Can you elaborate on what kind of tasks you're planning on performing with this?
-
@tt_su said:
The C API only let you read and write SKP files at this time. It doesn't let you interact with the live model.
Only the Ruby API interacts with the live model. What you could do is create a Ruby C Extension - and use that to bridge the communication between your application and the SketchUp Ruby API.
We are about to release a GitHub project with a Hello World example of a Ruby C++ Extension. Though it's not fully complete yet. You can keep an eye on our GitHub account: https://github.com/SketchUp/
Can you elaborate on what kind of tasks you're planning on performing with this?
Thomas Thomassen from Trondheim...
What I want to do is have some real-time feedback from a CNC machine so the user can see the path of a tool-cutter. Also, I want to convert Sketchup data into a tool path and create a file which gets sent to the machine.
Yeah, I know there is a lot of CNC software out there, but it costs $4,000 a copy sometimes. The cheap stuff wouldn't give me 100% control, as you are confined to straight lines, holes, etc.
Also, it would be kind of fun, as it would open the doors to a lot of hobbyists that want some easy-to-make visuals that represent things in the real world. I know a lot of users of SU do it for architectural purposes, but this would be for visual representation of the real-world. Like, say you have a greenhouse, and you want a screen on your computer to show temperature data. With a real-time plugin, you would be able to have a visual representations of the various thermocouples spread out inside the greenhouse.
Yes, I know there is software out there that does this not in Sketchup, (Wonderware for example), but it costs thousands of dollars a copy. That's not going to be any good for a guy that just wants to keep track of his greenhouse temps.
I'm not 100% partial to C++, I've been delving into Ruby programming just now. If using straight Ruby is easier, then I'm going to go that route.
I guess I'm looking for a tutorial on the basics of how to get a Ruby API to do a real-time interaction with Sketchup. Or, maybe just an outline of what I need to do. Which one of the API instructions can be used to send instructions to Sketchup?
Maybe I'm not asking the right question. Basically, let's say you have a program running in Ruby, and it is getting position data from a CNC machine constantly updated. How would you display that data on Sketchup in real-time?
Thanks for your help.
-
@ellipser said:
I'm not 100% partial to C++, I've been delving into Ruby programming just now. If using straight Ruby is easier, then I'm going to go that route.
If you make a Ruby C++ Extension you can do most things in C++. The Ruby API doesn't have any methods for communicating with other applications, so using a Ruby C Extension is probably the route to go for the communication bridge between your applications.
However, when interacting with the live model you will need to call the SketchUp Ruby API.@ellipser said:
I guess I'm looking for a tutorial on the basics of how to get a Ruby API to do a real-time interaction with Sketchup. Or, maybe just an outline of what I need to do. Which one of the API instructions can be used to send instructions to Sketchup?
@ellipser said:
Maybe I'm not asking the right question. Basically, let's say you have a program running in Ruby, and it is getting position data from a CNC machine constantly updated. How would you display that data on Sketchup in real-time?
As I mentioned, there is no API methods to send instructions from another application to SketchUp. You use the SketchUp Ruby API to interact with the live model, but you need to device your own way of communicating from your application to SketchUp - that's where Ruby C Extensions comes into play.
Once you have established communication you make calls to the
Entities
class which let you add entities and transform them.
http://www.sketchup.com/intl/en/developer/docs/ourdoc/entities.php#add_faceIf you plan on releasing this plugin for public distribution I would recommend that you check out the Extension Warehouse guidelines. They describe a brief outline of things to be aware of to avoid your SketchUp plugin to not clash with other plugins:
http://extensions.sketchup.com/developerFor more detailed information regarding distribution of plugins:
http://www.thomthom.net/thoughts/2012/01/golden-rules-of-sketchup-plugin-development/
http://www.thomthom.net/thoughts/2013/02/sketchup-plugin-checklist/ -
Hi Ellipser,
You can do so, but it is not easy.
Currently, as tt_su said, there is no real time inter-program API of SketchUp.
What you can do is:
Create a C or C++ extension, lets call it ApiBridge, and load ApiBridge in a ruby file that loaded by SketchUp.
In ApiBridge you need to- implement a C/C++ API wrapper to the Ruby API your self,
- maintain a communication to another program within a new thread.
Then you can do real time interaction with SketchUp through the ApiBridge.
For example, you can send/receive message/data to/from ApiBridge to do/get stuff to/from the SketchUp model.
-
@icehuli said:
Hi Ellipser,
You can do so, but it is not easy.
Currently, as tt_su said, there is no real time inter-program API of SketchUp.
What you can do is:
Create a C or C++ extension, lets call it ApiBridge, and load ApiBridge in a ruby file that loaded by SketchUp.
In ApiBridge you need to- implement a C/C++ API wrapper to the Ruby API your self,
- maintain a communication to another program within a new thread.
Then you can do real time interaction with SketchUp through the ApiBridge.
For example, you can send/receive message/data to/from ApiBridge to do/get stuff to/from the SketchUp model.
Thanks for your reply. If I understand this right, a C++ extension is something that would go inside a Ruby file. I guess I'd have to look up the syntax for writing a C++ file that goes inside a Ruby file.
Then, well, would you be so kind as to explain what an API wrapper is? API means "Application Programming Interface", so I'm guessing a wrapper would be the method that you use to grab data from another file?
This is going to take a while for me. I'm going to have to become an expert Ruby user first if you call this not easy and you are experienced.
Isn't there some way to "cheat"? I mean the command line is already there in Ruby console, all I'd have to do is find someway of accessing that command line from an external program. I'm wondering if there is some sort of command-line prompt that could be used.
-
There was a plugin to produce Gcode started, but the author needs someone else to pick up the project:
Model2GCode - who would like to continue? -
Advertisement