So basically I would like to recreate MoveTool/ComponentTool functionality and show model position while moving mouse. I know that I could use place_component but this solution changes tool to ComponentTool and I need to change logic in onMouseMove so that solution cannot be used.
Is there way to draw model from RubyApi on specific position without placing it? Or another question is it possible to recreate MoveTool/ComponentTool from RubyAPI?
Just checked it. And there is similiar problem as with my own solution using place_component.
I would like to have moving functionality but with possibility to add some logic to handlers (onMouseMove, onLButtonDown) but place_component change tool to ComponentTool and as this is native tool I cannot add my own logic.
Thatās why I wanted to recreate moving tool functionality but as I see it cannot be done to create your own custom tool which works exactly as native ComponentTool or MoveTool without using place_component (so in fact changing tool to ComponentTool but from code). Am I right?
For this discussion, the term should not be āmodelā but component instance.
One way is to place the instance in the model.active_entities (usually at the local ORIGIN,) and then transform the instance to follow the mouse as SketchUp calls your custom tool onMouseMove() callback method.
Take care to remove the instance (or fire a Sketchup::undo) if the user cancels and/or deactivates the tool.
This is not a new idea. There may even be some example plugins lying around over at SketchUcation.
I remember it being discussed over there in the past.
You can also draw to the screen within a tool. So you could actually be drawing a facsimile of the component (that is still only just a definition, but not an actual placed instance,) on the end of the cursor as your tool moves it.
This can be done because it is the definition that āownsā the entities collection, not instances. So you can read and explore the definitionās entities before a real instance is actually placed into the modelās entities collection.
The API tool class is abstract. This means that there is not a defined superclass for it.
The methods described in the API are optional callback methods, but since itās your custom class, you may also define other internal methods to help organize the code (as long as they have names other than the API callback methods.)
There are several examples of tools by the SketchUp Team in the Extension Warehouse.
I suggest you write a tool that loads a 1m cube component into the modelās definition list, then reads that definition to get faces, and recreate those 6 faces on the screen attached to the mouse cursor.
When clicked then an instance of that cube is placed at the click point.
When you get that working, you can use it as a superclass to tweak further to do the other nifty ideas you have.
Ensure me if Iām right. When my definition will be already put in definitions list then I should create instance of that definition (using add_instance method) and then in OnMouseMove handler transform that instance position to āmouse cursor positionā (probably some more calculation will be needed than just transform to x,y of cursor).
One way is to place the instance in the model.active_entities (usually at the local ORIGIN,)
What do you mean by āplace the instance in the model.active_entitiesā. Iām not sure do I understand this.
Will you need to do a view.invalidate to get SketchUp to display the newly moved ComponentInstance?
Is this likely to cause sluggish performance of the Tool (I have not tried this technique, only used the #draw method to create basic OpenGL items in the Tool)?
For a tool that moves drawing elements you donāt want to put a whole bunch of transformations on the undo stack (if possible) whilst dragging with the mouse.
But you might want to put the last position on the undo stack if itās move.
To do this just re transform to the last point making a call to #transform! instead of #move!.
The rotates you will want recorded so use #transform! for those.