How to make a component-placer tool?
-
I need to write a simple plugin that will allow a user to place a pre-defined object in the same way they can place one from the Components panel.
So, user clicks my menu item, my component appears on their cursor, they decide where to place it, click, and then it's in the model. I'll want to do some behind-the-scenes processing before and after, naturally.
Can someone give me advice on this? I've never made Tool's before... is that what I need here?
-
Hmm, I suppose I could distribute a component library with my plugin and allow users to use the built-in component panel. I could observe the definition so that I can hook into when it's placed, but I won't know when they BEGIN to place it.
It seems to me that writing a custom tool for this would be difficult. Someone please tell me I wouldn't have to use onMouseMove to make the component follow the cursor while being placed!
-
Model.place_component
http://code.google.com/intl/no/apis/sketchup/docs/ourdoc/model.html#place_component -
...or...
entities.add_instance(definition, transformation)
? -
@tig said:
...or...
entities.add_instance(definition, transformation)
?Then he'd have to replicate the whole of the Place Component functionality in a tool...
-
@thomthom said:
@tig said:
...or...
entities.add_instance(definition, transformation)
?Then he'd have to replicate the whole of the Place Component functionality in a tool...
But he was talking about a 'tool'...
This way his tool can get a picked-point and then insert a component at that point, then repeat if desired...
Your way is much easier, but it will dump him out of the plugin code at the insertion, so no chance of repeat inserts in the same instance of the class [at least without incredible convolution??] ? -
Thanks for the help fellas.
@tig said:
But he was talking about a 'tool'...
This way his tool can get a picked-point and then insert a component at that point, then repeat if desired...
Your way is much easier, but it will dump him out of the plugin code at the insertion, so no chance of repeat inserts in the same instance of the class [at least without incredible convolution??] ?I can listen to
DefinitionObserver
#onComponentInstanceAdded
to get back into Ruby after insertion.This is a neat way to create a tool that's not a Tool.
-
@draftomatic said:
Thanks for the help fellas.
@tig said:
But he was talking about a 'tool'...
This way his tool can get a picked-point and then insert a component at that point, then repeat if desired...
Your way is much easier, but it will dump him out of the plugin code at the insertion, so no chance of repeat inserts in the same instance of the class [at least without incredible convolution??] ?I can listen to
DefinitionObserver
#onComponentInstanceAdded
to get back into Ruby after insertion.This is a neat way to create a tool that's not a Tool.
And you also need to listen to the ToolsObsever to check if the user activates another tool - instead of actually placing the component.
-
@unknownuser said:
And you also need to listen to the ToolsObsever to check if the user activates another tool - instead of actually placing the component.
That doesn't seem to be an issue.
onComponentInstanceAdded
gets fired when the component is placed, not when you activate the tool.
Advertisement