I write a custom move tool.
When moving the component, the InputPont show the inference point itself.
But the builtin move tool don’t show the inference point itselt.
how to do it?
The code is follow, Copy it and run in the bulitin ruby console:
class CustomMoveTool
def onMouseMove(flags, x, y, view)
@mouse_ip = view.inputpoint(x, y)
if @mouse_ip.valid?
# create component instance from builtin components
if @component_instance.nil?
model = Sketchup.active_model
def_path = Sketchup.find_support_file 'Door Interior.skp', 'Components/Components Sampler'
door_def = model.definitions.load def_path
transform = Geom::Transformation.new
@component_instance = model.entities.add_instance door_def, transform
end
# move door by mouse position
transform = Geom::Transformation.new @mouse_ip.position
@component_instance.move! transform
view.tooltip = @mouse_ip.tooltip
view.invalidate
end
end
def draw(view)
# display the mouse position uses inferencing
# FIXME: Don't display inferencing point on the moving component
@mouse_ip.draw(view) if @mouse_ip && @mouse_ip.display?
end
end
Sketchup.active_model.select_tool CustomMoveTool.new
@DanRathbun The View draw the inference point and tooltip by the InputPoint class.
If comment it out, no inference point is shown.
I need to show some inference points, but the moving component’s inference points are not included.
Is there any other solution?
You call draw on every InputPoint instance individually.
If you want an InputPoint instance not to be drawn, just do not call draw on it.
If you want an input point to be drawn only under certain conditions (inputpoint’s instance_path contains the moved component instance), then add a condition around the call to draw.
certain conditions: inputpoint’s instance_pathdoes not contain the moved component instance
I change the code and try again:
def draw(view)
if @mouse_ip && @mouse_ip.display? && !@mouse_ip.instance_path.include?(@component_instance)
@mouse_ip.draw(view)
view.tooltip = @mouse_ip.tooltip
end
end
As I do, I can feel that the inference system slower and clumsy.
I need a better solution:
When the component instance is being moved, the user can see the component, but the inference system can’t see the component instance.
When the component instance has been moved, neither the user nor the inference system can see the component instance.
That means that you don’t do view.inputpoint(...) when you don’t want the inference system to get an inference.
This sounds like your tool has several steps (states), and you would have much more ease with it if you think about the states and state transitions first (state machine).
@Aerilius
Maybe I’m not explaining it very well. Let’s the complete code say:
The CustomMoveTool use the inference engine, in order to find the inference point of the inference entity, and move the moving entity to the position of the inference point.
For example, we move the door to the start point of an edge:
term | example
–|–|– moving entity | door inference entity | edge inference point | start point
The @mouse_ip is the inference engine, it draw the inference point of the inference object.
The @component_instance is moving entity, so the @mouse_ip don’t need to draw ** inference point** of the @component_instance, BUT HOW TO DO IT?
What about moving the component far away before picking the point and then, after the point is picked and before invalidating the view moving it back to the picked point position? It works for me:
class MyTool5
def activate
@ip = Sketchup::InputPoint.new
end
def onMouseMove(flags, x, y, view)
ent=Sketchup.active_model.selection[0];
ent.move! Geom::Transformation.new([100000,100000,100000]);
@ip.pick view,x,y
ent.move! Geom::Transformation.new(@ip.position)
view.invalidate
end
def draw(view)
view.tooltip = "inference engine says: "+ @ip.tooltip
@ip.draw(view) if @ip && @ip.display?
end
end
Sketchup.active_model.select_tool(MyTool5.new)
Not a great one. You could try to use InputPoint as main source - then if it return an entity you want to ignore, try to use model.raytest (Class: Sketchup::Model — SketchUp Ruby API Documentation) and shoot rays and perform your own custom picking. But you loose all inference magic.