Activating PaintMatchTool programatically


#1

Hi,

I’m trying to activate PaintMatchTool, aka. eye dropper, using Ruby API but couldn’t accomplish by using

Sketchup.active_model.select_tool('PaintMatchTool')

or

Sketchup.send_action("selectPaintMatchTool:")

Does anyone have an idea how it can be achieved?

Thanks


#2

there is no such tool, you can check for yourself…

run this code >> activate PaintTool >> activate the eyedropper…

what_tool = UI.start_timer(2.0, true) do
  tool = Sketchup.active_model.tools.active_tool_name
  p "waiting for #{tool}" 
 end
# use the following to stop the timer or Quit SU
# UI.stop_timer(what_tool)

you will need to get the Material from a selected Sketchup::Drawingelement

for v18 you can get the color at a pixel using Sketchup::ImageRep

john

P.S: can you fix your Forum profile as you can’t be using SU Free for ruby…


#3

I don’t think there’s a way to call that tool, via the API.
However, I suspect you’d like to continue working in your own tool anyway, and a .send_action() might well break out of it ?

Why not make your own Tool class… which temporarily sets a custom cursor to be the dropper icon, and then uses an onClick pick_helper to determine if the user has clicked on a face [or face within a container ?], and if so return that face.material.
You can then use that material in the main code as you desire…


#4

Thanks for your reply @john_drivenupthewall .

I think I should have been more clear which tool I was talking about. It’s the one with the eye dropper icon in Materials tab on the right. Its tooltip is “Sample Paint”.

When I run the code you provided, I still get the same tool name. Here is a screenshot

P.S: I fixed the SU version to Make. Thanks for pointing it out.


#5

Hi @TIG ,

Thank for your suggestion. I’ll probably go with that but I still wonder why I can’t activate an already implemented tool in SU and rather create my own with the same functionality.

Please also have a look at my reply to @john_drivenupthewall. Maybe it was also not clear for you which tool I was mentioning earlier.


#6

I agree with TIG. I checked out the send_actions as well as using a MIcrosoft SDK tool to watch the UI and see if I could get the automation ID for that tool, but was unsuccessful.

Using the tool ID does not work.

You do know that you can get this tool anytime via shortcut B, then hold the ALT key ?


#7

Yes, I know how to activate it while using SU but I need to activate it through a plugin aka. a button click should activate it.

I’ll go with @TIG’s solution then.

One last favour I can ask if you could find out the cursor id for eye dropper tool?

That would save me from creating an icon image.


#8

The images since v2016 are SVGs in the “images” folder.
There are 3 for the eyedropper.


#9

You might look at ThomThom’s Material Replacer …

https://bitbucket.org/thomthom/material-replacer/downloads/

http://extensions.sketchup.com/en/content/material-replacer

… it also needs his TT_Lib2 …

http://extensions.sketchup.com/en/content/tt_lib²


#10

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.