How to do not show inference points on the moving component itself?

I write a custom move tool.
When moving the component, the InputPont show the inference point itself.

custom_move_tool

But the builtin move tool don’t show the inference point itselt.

builtin_move_tool

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

This line, in the draw() method, draws the inputpoint …

@mouse_ip.draw(view) if @mouse_ip && @mouse_ip.display?

Comment it out and try again.

@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.
1 Like

@Aerilius

certain conditions: inputpoint’s instance_path does 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.
  • Just like the built in move tool do.

Thank you all the same. :smile:

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).

1 Like

The API doesn’t expose any way for Sketchup::Inputpoint to ignore specific entities. But it sounds like a nice improvement.

You can log bugs and improvements in our issue tracker: Issues · SketchUp/api-issue-tracker · GitHub

1 Like

@Aerilius
Maybe I’m not explaining it very well. Let’s the complete code say:

  1. 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

  1. The @mouse_ip is the inference engine, it draw the inference point of the inference object.

  2. 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?

@tt_su Log it on the issue tracker.

Is there a temporary solution?

2 Likes

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)
1 Like

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.