Im considering modeling a few things and making a light duty engine that moves something on three linear axis. I’d like to send the program a speed for each vector and then have the program reply back with some sort of feedback.
Is there already some sort of web or local tcp communication built in to the api that I could achieve this with.
The animations will be minimal so I think going to unity may be overkill for my project and we haven’t decided on getting a license with sketchup yet.
To clarify I am wanting to send and transmit data to and from sketchup to another program. Basically I’m trying to make a virtual mock-up of a physical system that is controlled by another system. And I’d like to use that system to send and receive data to a simulation in sketchup.
Should the communication be bi-directional? Sketchup’s ruby api is able to do http-requests and other tcp-ip based requests. Thus, initializing communication FROM sketchup TO a service is pretty straight forward. On the other hand, running a server in Sketchup to allow incoming connections is do-able, but more difficult.
SketchUp’s Ruby API is designed to be used from within SketchUp. Ruby commands (and thus actions in SketchUp) can be triggered at load time, from the Ruby Console, from UI callbacks (menu items, toolbar buttons), from htmldialog callbacks, from (entity) observers but not from another application.
SketchUp can trigger actions, but actions in SketchUp cannot be triggered from outside (you would need to build a mechanism to make SketchUp listen to incoming messages).
If your extension is supposed to be used with a dialog anyways, you could make use of the HtmlDialog’s networking (ajax calls, websockets) to connect to your application in a completely cross-platform way, and then forward the incoming messages to Ruby callbacks.
As far as I remember, Ruby sockets may not properly work. You could use the Sketchup::Http methods to send requests. With long-running requests you can listen to events from outside (the external application does not immediately send a response but waits until it wants to trigger an action in SketchUp).
By writing a Ruby C extension (platform-specific) you can establish communication with outside. That’s what custom drivers do (SpaceNavigator). I think @thomthom connected to external sensors (Arduino/Raspberry?), but I could not find such code in his Github projects.
Important is that Ruby runs single-threaded within SketchUp’s single application thread. That means whatever solution you find must be non-blocking.