Hello everyone, I wrote a small file Api Ruby, with which I create a pillar, setting the two
measurements at the base of the pillar, side along the x-axis and y and the height, all by entering the measurements
inputbox… in creating the face for the “pushpull”, the first point equals pt1 [0, 0, 0]
origin of the X, Y, Z axes … I would like the pillar object to remain momentarily attached
cursor and subsequently inserted on screen at a precise point at the click of the mouse insertion,
I hope I have explained myself… Possibly? What should I write to the Ruby file, for this insertion wait
pillar object… Thank you.
Thanks for the answer, I’ve already tried watching " model.place.component",
but I understood very little, if he was kind enough to show me with practical example
using my ruby file, it would be great…Thank you
Greetings Thomas. I feel like a fan talking to my idol here.
Small follow up question to place_component method.
It returns Sketchup::Model instead of the ComponentInstance. Seems reasonable since repeat argument could be set to true and it would return something like an array OR ComponentInstance.
Therefore, how would you grab a handle to the ComponentInstance (assuming repeat set to false).
Should I go with Sketchup.active_model.entities[-1] or is there something more intuitive.
1. Since you must have a reference to the component definition, you can take an array snapshot of it’s instances collection before and then subtract it from the array afterward.
before = cdef.instances
# Wait some time because place_component returns immediately.
new_instances = cdef.instances - before
But the main problem is knowing when the placing has been completed (as place_component is non-blocking and returns immediately.)
This is the reason why it just returns the model object - ie the method call returns immediately and does not wait for the user to place any instances.
Changing how it works now is not possible. But adding a sister method that does wait and retrun an array of placed instances is an option.
A better approach is likely to use a temporary definition observer …
# inside your plugin module ...
def onComponentInstanceAdded(definition, instance)
@instance = instance
@instance = nil
# Set up a timer to check for the new instance and remove observer
# if the timeout is reached (ie, user canceled the placement.)
@timeout = 10.0
@elapsed = 0
@tid = UI.start_timer(1.0,true) do
@elapsed += 1.0
elsif @elapsed > @timeout
# Attach this module as temporary observer:
# Place the instance with the MoveTool:
# Do something with @instance
end # plugin module
You might also watch the toolstack. The PlaceComponent tool will change to the MoveTool at some point.
There are a bunch of open API Issues regarding placing components with the API(s) …