Sketchup and ruby
-
I want to perform a onclick action on a sketchup object to connect to a Mysql database.
I developed a Ruby class to create sketchup objects.
And now I want to perform an onclick action on this sketchup objects. When I Mouseclick on a sketchup object ,an onclick action will be initialized and will automatically connect to the database.
Is this possible with Sketchup and ruby?If so, what are the necessary ruby classes and methods for this event?Thank you.
-
I've moved this into the developer's forum as it'll get more appropriate attention here.
You need to make a 'Tool' class - see the API - there are various 'onClick' methods and you use a 'pickhelper' to make a test for the user clicking on the object.
https://developers.google.com/sketchup/docs/ourdoc/tool#onLButtonDown
https://developers.google.com/sketchup/docs/ourdoc/pickhelper#picked_element
The way you define the command associated with the class tells Sketchup it's a 'Tool', and you get lots of premade methods to use that are no available in 'plain' class or module... -
Depending on what you're trying to do, you might want to look at the SelectionObserver class. You can use a SelectionObserver to perform actions based on what is selected, regardless of what tool is currently being used.
-
If the object's 'collection' is a group or a component-instance you can set attributes for that - like an 'id' code.
You can also attach the same 'id' attribute to any entity, so you could also 'label' each individual part too by iterating through the objects.entities ...
See
https://developers.google.com/sketchup/docs/ourdoc/entity
Set the 'id' with
entity.set_attribute("Sachi", "id", 1234567890)
later to get an object's 'id' your pickhelper method can return the group/instance and retrieve its 'id' using
entity.get_attribute("Sachi", "id", 0)
-
Thank you very much TIG and kwalkerman. I have tried some simple codes.And the tool interface and pickhelper will be just fine for the task.
But now it raised a problem. I want to select a whole sketchup entities object, as one object. So that when I click anywhere on that object (like a house or a building), the same data record will be retrieved from the database.
The database contains a record for each house.Do you have any idea about this? Thank you
Advertisement