SketchUcation Plugin Store

 

 

[Plugin] Recall last tool v1.2

[Plugin] Recall last tool v1.2

Postby Matt666 » Tue Feb 17, 2009 6:08 pm

Hi all!
This plugin can recall last tool used. Based on this request.
You can use native Sketchup Shortcut function to add a new shortcut. I use F2!
;)
All suggestions are welcomed!!

[EDIT1] This plugin is not compatible with Mac. Sorry. See below if you want to know why. A SU bug for Mac users.
[EDIT2] v1.2 -> 09/04/2009 : Observer was not always activated before using tool. Thank you Simon Le Bon!
Please, register (free) to access all the attachments on the forums.
Last edited by Matt666 on Thu Apr 09, 2009 10:15 am, edited 2 times in total.
Frenglish at its best !
My scripts
Matt666
 
Posts: 829
Joined: Wed Dec 05, 2007 8:38 am
Location: 48.1184, -1.675
Name: Matt

Re: [Plugin] Recall last tool

Postby jmmad » Tue Feb 17, 2009 6:12 pm

Thxs Matt works great with Key shortcuts :berserk:
Get Upa !
jmmad
 
Posts: 42
Joined: Sat Dec 27, 2008 8:54 pm
Location: Santiago, Chile

Re: [Plugin] Recall last tool

Postby RickW » Tue Feb 17, 2009 7:34 pm

Matt,

Nice work. My suggestion would be to use class variables (@@Matt_Model_Toolid, @@Matt_Model_Toolid2) or instance variables (@Matt_Model_Toolid, @Matt_Model_Toolid2) rather than global variables. Note that class variables must be declared right after the class is declared:
Code: Select all
   class Matt_Observer < Sketchup::ToolsObserver
      @@Matt_Model_Toolid = nil
      @@Matt_Model_Toolid2 = nil
      def onActiveToolChanged (tools_object, toolname, toolid)
         # ETC...

but instance variables can be delcared anywhere in the class methods.
RickW
 
Posts: 770
Joined: Fri Nov 16, 2007 6:38 am
Location: Wichita, KS
Name: Rick Wilson

Re: [Plugin] Recall last tool

Postby Matt666 » Tue Feb 17, 2009 10:42 pm

Hi Rick!
Thank you for the comment, I've updated the code... ;)
Frenglish at its best !
My scripts
Matt666
 
Posts: 829
Joined: Wed Dec 05, 2007 8:38 am
Location: 48.1184, -1.675
Name: Matt

Re: [Plugin] Recall last tool

Postby EarthMover » Thu Feb 19, 2009 2:27 am

Hey Matt - You are eternally my friend! Thanks for listening to my request. I'm sure it will be useful to many!
A designer is an emerging synthesis of artist, inventor, mechanic, objective economist and evolutionary strategist. - R. Buckminster Fuller
Some of my 3D crap
User avatar
EarthMover
Top SketchUcator
 
Posts: 1792
Joined: Fri Sep 12, 2008 9:06 pm
Location: Eastern Pennsylvania
Name: Adam Hails

Re: [Plugin] Recall last tool

Postby Matt666 » Thu Feb 19, 2009 7:46 am

;)
Frenglish at its best !
My scripts
Matt666
 
Posts: 829
Joined: Wed Dec 05, 2007 8:38 am
Location: 48.1184, -1.675
Name: Matt

Re: [Plugin] Recall last tool

Postby Pilou » Wed Feb 25, 2009 12:27 pm

Astucieux! :fro:
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie
User avatar
Pilou
Top SketchUcator
 
Posts: 10213
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
License type: Free/Make
SketchUp use: hobby
Level of SketchUp: Advanced

Re: [Plugin] Recall last tool

Postby Matt666 » Wed Feb 25, 2009 2:40 pm

Merci Pilou ;)
Frenglish at its best !
My scripts
Matt666
 
Posts: 829
Joined: Wed Dec 05, 2007 8:38 am
Location: 48.1184, -1.675
Name: Matt

Re: [Plugin] Recall last tool

Postby Edson » Wed Feb 25, 2009 3:43 pm

matt,

here we go again. unless i do not know how to use your new script, it is not working on mac! sorry...
edson mahfuz, architect
http://www.mahfuz.arq.br

Anyone can get you more for more, but it takes genius to get you more for less.
User avatar
Edson
Global Moderator
 
Posts: 2663
Joined: Mon Oct 22, 2007 1:46 pm
Location: Porto Alegre, Brasil
Name: Edson Mahfuz
Operating system: Mac
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [Plugin] Recall last tool

Postby Matt666 » Wed Feb 25, 2009 4:55 pm

Hi Edson... I hope you do not know!! I'm cursed...

So : Draw a :circle: . Draw a :rectangle: . Press space bar for :select: .
Go to Plugins/Recall last tool. Rectangle tool is now recalled.

If it does not work, can you open your ruby console, and try again, please?
And, at last, can you call rectangle tool, and try to copy this code in the ruby console ?
Code: Select all
Sketchup.send_action(21022)
This code calls selection tool.
Thank you Edson. And sorry for the inconvenience.
Frenglish at its best !
My scripts
Matt666
 
Posts: 829
Joined: Wed Dec 05, 2007 8:38 am
Location: 48.1184, -1.675
Name: Matt

Re: [Plugin] Recall last tool

Postby Edson » Wed Feb 25, 2009 5:27 pm

matt,

it did not work. i had done it that way before. below is the ruby console reading.

glad to help you. keep your requests coming.
Please, register (free) to access all the attachments on the forums.
edson mahfuz, architect
http://www.mahfuz.arq.br

Anyone can get you more for more, but it takes genius to get you more for less.
User avatar
Edson
Global Moderator
 
Posts: 2663
Joined: Mon Oct 22, 2007 1:46 pm
Location: Porto Alegre, Brasil
Name: Edson Mahfuz
Operating system: Mac
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [Plugin] Recall last tool

Postby Burkhard » Wed Feb 25, 2009 10:02 pm

I read a lot /users/mahfuz... ;)
User avatar
Burkhard
Premium Member
Premium Member
 
Posts: 883
Joined: Sat Nov 17, 2007 12:45 pm
Location: Germany
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: interior design
Level of SketchUp: Advanced

Re: [Plugin] Recall last tool

Postby pecan » Wed Feb 25, 2009 10:18 pm

Matt666 wrote:Hi Edson... I hope you do not know!! I'm cursed...
Code: Select all
Sketchup.send_action(21022)
This code calls selection tool.
Thank you Edson. And sorry for the inconvenience.


On differenct OS's, even the same OS with different menus, that magic number will have changed.

What's wrong with Sketchup.send_action(selectSelectionTool:);

When the menu structure is updated, then the call will still work even tho the menu id has changed.
pecan
 
Posts: 67
Joined: Fri Sep 26, 2008 10:28 pm

Re: [Plugin] Recall last tool

Postby simon le bon » Wed Feb 25, 2009 11:32 pm

Bravo Matt !!
at the very beginning of my learning SketchUp, I was surprised not to have this feature at disposal. And then I was accustomed to always recall my tools. And Here comes your ruby. It is as if suddenly we had won a great lightness. (F2 is great)

it already belongs to my toolbox. :thumb: :thumb: :-)simon
User avatar
simon le bon
 
Posts: 1077
Joined: Sat Jan 26, 2008 10:22 am
Location: Chouy/ Picardie/ France
Name: Simon Bonnet

Re: [Plugin] Recall last tool

Postby Matt666 » Thu Feb 26, 2009 8:19 am

Merci Simon ! ;)
pecan wrote:On different OS's, even the same OS with different menus, that magic number will have changed.
Hi pecan! Are you sure of that? I use only two different numbers in my code. The rest is a recall of the last number used.
But there's a biiig problem with Mac... On Mac, function "send_action" does not accept integers. Only strings! :(

Edson wrote:It did not work. i had done it that way before. below is the ruby console reading.
Thank you Edson!
Ouch. I will try to find a solution. Can you test this code below, please?
Code: Select all
Sketchup.send_action("21022")
Frenglish at its best !
My scripts
Matt666
 
Posts: 829
Joined: Wed Dec 05, 2007 8:38 am
Location: 48.1184, -1.675
Name: Matt

Re: [Plugin] Recall last tool

Postby Edson » Thu Feb 26, 2009 12:23 pm

it looks good!
Please, register (free) to access all the attachments on the forums.
edson mahfuz, architect
http://www.mahfuz.arq.br

Anyone can get you more for more, but it takes genius to get you more for less.
User avatar
Edson
Global Moderator
 
Posts: 2663
Joined: Mon Oct 22, 2007 1:46 pm
Location: Porto Alegre, Brasil
Name: Edson Mahfuz
Operating system: Mac
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [Plugin] Recall last tool

Postby Matt666 » Thu Feb 26, 2009 12:39 pm

Ok. But if you have rectangle tool called, when you copy and validate the code, is the selection tool activated?
Frenglish at its best !
My scripts
Matt666
 
Posts: 829
Joined: Wed Dec 05, 2007 8:38 am
Location: 48.1184, -1.675
Name: Matt

Re: [Plugin] Recall last tool

Postby Edson » Thu Feb 26, 2009 12:58 pm

i drew a rectangle, then pressed the space bar, then used the script from the menu. the result is in the picture.
Please, register (free) to access all the attachments on the forums.
edson mahfuz, architect
http://www.mahfuz.arq.br

Anyone can get you more for more, but it takes genius to get you more for less.
User avatar
Edson
Global Moderator
 
Posts: 2663
Joined: Mon Oct 22, 2007 1:46 pm
Location: Porto Alegre, Brasil
Name: Edson Mahfuz
Operating system: Mac
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [Plugin] Recall last tool

Postby Matt666 » Thu Feb 26, 2009 1:58 pm

Sorry Edson, and all mac users. But I can't do anything with this bug. :( Function 'send_action' doesn't accept integers (so tool IDs) on Mac.
Frenglish at its best !
My scripts
Matt666
 
Posts: 829
Joined: Wed Dec 05, 2007 8:38 am
Location: 48.1184, -1.675
Name: Matt

Re: [Plugin] Recall last tool

Postby pecan » Thu Feb 26, 2009 7:12 pm

Result from SU ruby console

(eval)
result = Sketchup.send_action "selectSelectionTool:"
true

I was in error suggesting it was a num.
pecan
 
Posts: 67
Joined: Fri Sep 26, 2008 10:28 pm

Re: [Plugin] Recall last tool

Postby pecan » Thu Feb 26, 2009 7:37 pm

Using the tool name should work:

Code: Select all
def onActiveToolChanged (tools_object, toolname, toolid)
        print tools_object, toolname, toolid
      @@Matt_Model_Toolid = @@Matt_Model_Toolid2 if @@Matt_Model_Toolid2
      #@@Matt_Model_Toolid2 = toolid if not([21022,10508].index toolid)
      @@Matt_Model_Toolid2 = "select#{toolname}:";
      puts "1: #{@@Matt_Model_Toolid} 2: #{@@Matt_Model_Toolid2}"
   end
pecan
 
Posts: 67
Joined: Fri Sep 26, 2008 10:28 pm

Re: [Plugin] Recall last tool

Postby pecan » Thu Feb 26, 2009 7:45 pm

pecan wrote:Using the tool name should work:

Code: Select all
def onActiveToolChanged (tools_object, toolname, toolid)
        print tools_object, toolname, toolid
      @@Matt_Model_Toolid = @@Matt_Model_Toolid2 if @@Matt_Model_Toolid2
      #@@Matt_Model_Toolid2 = toolid if not([21022,10508].index toolid)
      @@Matt_Model_Toolid2 = "select#{toolname}:";
      puts "1: #{@@Matt_Model_Toolid} 2: #{@@Matt_Model_Toolid2}"
   end


Well... almost.

"selectCameraOrbitTool:" doesnt work.
It's action name is simply OrbitTool.
So maybe a hash of returned tool names and the send_action name.

sendActionToolName = {"CameraOrbitTool", "OrbitTool", } etc.
Or maybe a hash of just the exceptions.

Its a shame SU has to be so inconsistent.
pecan
 
Posts: 67
Joined: Fri Sep 26, 2008 10:28 pm

Re: [Plugin] Recall last tool

Postby pecan » Thu Feb 26, 2009 8:25 pm

Here's a list of the send_actions and the actual tool name returned by the observer.
Code: Select all
howRubyPanel:
viewBack:
viewBottom:
viewFront:
viewIso:
viewLeft:
viewRight:
viewTop:
viewPerspective:
viewShowAxes:
viewShowHidden:
viewZoomExtents:
viewZoomToSelection:
viewUndo:
selectOrbitTool: (CameraOrbitTool)
    ok  selectPositionCameraTool:
selectDollyTool: (CameraDollyTool
selectTurnTool:
selectWalkTool: (CameraWalkTool)
selectZoomTool: (CameraZoomTool)
selectFieldOfViewTool: (CameraFOVTool) <=== inconsistency
selectZoomWindowTool: (CameraZoomWindowTool)
pageAdd:
pageDelete:
pageUpdate:
pageNext:
pagePrevious:
renderWireframe:
renderHiddenLine:
renderMonochrome:
renderShaded:
renderTextures:
    ok  selectArcTool:
selectAxisTool: (SketchCSTool)
    ok  selectCircleTool:
    ok selectEraseTool:
    ok  selectFreehandTool:
selectLineTool: (SketchTool)
    ok  selectMeasureTool:
    ok  selectMoveTool:
    ok  selectOffsetTool:
    ok  selectPaintTool:
selectPolygonTool: (PolyTool)
    ok  selectProtractorTool:
    ok  selectPushPullTool:
    ok  selectRectangleTool:
    ok  selectRotateTool:
    ok  selectScaleTool:
    ok  selectSectionPlaneTool:
    ok  selectTextTool:
    ok  selectDimensionTool:
    ok  selectExtrudeTool:
    ok  selectSelectionTool:
editUndo:
editRedo:
editHide:
editUnhide:
fixNonPlanarFaces:

axes is returning SketchCSTool
3d text is returning 3DTextTool
plugins return RubyTool
orbit return CameraOrbitTool
pan returns CameraDollyTool
zoom returns CameraZoomTool
field of view returns CameraFDVTool
zoom window returns CameraFOVTool
zoom extends return CameraZoomWindowTool
walk return CamerWalkTool
look returns CameraPanTool
line returns selectSketchTool


Except for "selectFieldOfViewTool: (CameraFOVTool)" you can remove "Camera" from the observer reported name and prefix "select".
Special cases are PolyTool, Line tool, and axis tool.

On second thought, a hash like {reportedObserverName, sendSelectName} might be the best bet.
pecan
 
Posts: 67
Joined: Fri Sep 26, 2008 10:28 pm

Re: [Plugin] Recall last tool

Postby pecan » Thu Feb 26, 2009 8:59 pm

The following seems to work, and you can add to the exceptions hash when you find 'em.

Hope this helps some...

Code: Select all
# Supports Organizer.rb
=begin
Copyright 2009, Matt
All Rights Reserved

THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

License:   Free

Author:        Matthieu NOBLET
Organization:   Matt
Name:            Recall_lst_tool
Version:         1.0
SU Version:      6 and 7
Date:            17/02/2009
Description:      Recall last tool used
Usage:         If you want to have a shortcut, please try with native Sketchup shortcuts...
History:
   1.000   17/02/2009
         First version

   1.100   17/02/2009
         Global variables replaced by Class variables
=end

require 'sketchup.rb'

class Matt_Observer < Sketchup::ToolsObserver
    def initialize
        @ToolExceptionsHash = {
           # observerName    send_actionName
            "FOVTool",       "FieldOfViewTool",
            "SketchCSTool",  "AxisTool",
            "SketchTool",    "LineTool",
            "PolyTool",      "PolygonTool"
        }
    end
   @@Matt_Model_Toolid = nil
   @@Matt_Model_Toolid2 = nil
   def onActiveToolChanged (tools_object, toolname, toolid)
        print tools_object, " ", toolname, " ", toolid, "\n"
        tname = toolname;
      @@Matt_Model_Toolid = @@Matt_Model_Toolid2 if @@Matt_Model_Toolid2
      # remove "Camera" prefix reported by ToolObserver"
      @@Matt_Model_Toolid2 = (tname[0,6]="" if (tname[0,6] == "Camera"));
      tname = @ToolExceptionsHash.fetch(tname, tname);
      @@Matt_Model_Toolid2 = "select#{tname}:";
      puts "1: #{@@Matt_Model_Toolid} 2: #{@@Matt_Model_Toolid2}"
   end
   def self.recall_last
        puts "sending action #{@@Matt_Model_Toolid}" if @@Matt_Model_Toolid
      return Sketchup.send_action(@@Matt_Model_Toolid) if @@Matt_Model_Toolid
      return Sketchup.send_action("selectSelectionTool:")
   end
end

unless file_loaded?(__FILE__)
   file_loaded(__FILE__)
   Sketchup.active_model.tools.add_observer(Matt_Observer.new)
   $submenu ? (organizer = $submenu) : (organizer = UI.menu("Plugins"))
   organizer.add_item("Recall last tool"){ Matt_Observer.recall_last }
end

pecan
 
Posts: 67
Joined: Fri Sep 26, 2008 10:28 pm

Re: [Plugin] Recall last tool

Postby Matt666 » Fri Feb 27, 2009 6:00 pm

Hi pecan!
Sorry, I didn"t test your plugin, but I think it doesn't work with plugins. So Non native tools...
I will test it! Thank you for that Pecan!
Frenglish at its best !
My scripts
Matt666
 
Posts: 829
Joined: Wed Dec 05, 2007 8:38 am
Location: 48.1184, -1.675
Name: Matt

Re: [Plugin] Recall last tool

Postby Matt666 » Thu Apr 09, 2009 10:12 am

Hi Pecan! Your method does not work with ruby tools, as expected...
A new version has been posted in the first post. It fixes a bug found by Simon Le Bon. Thank you Simon!
Frenglish at its best !
My scripts
Matt666
 
Posts: 829
Joined: Wed Dec 05, 2007 8:38 am
Location: 48.1184, -1.675
Name: Matt

Re: [Plugin] Recall last tool v1.2

Postby simon le bon » Thu Apr 09, 2009 1:26 pm

Hi Matt,
Hip Hip! I've just installed your plug v 1.2 and it seems working very well (all tools are seemingly supported)! So cool!!
It's too young to see if it remain operative on duration, but i believe this is now fixed.

Many thanks for that tool dear Matt :thumb: :)

I take it!


simon.
User avatar
simon le bon
 
Posts: 1077
Joined: Sat Jan 26, 2008 10:22 am
Location: Chouy/ Picardie/ France
Name: Simon Bonnet

Re: [Plugin] Recall last tool

Postby Edson » Thu Apr 09, 2009 1:40 pm

Matt666 wrote:Sorry Edson, and all mac users. But I can't do anything with this bug. :( Function 'send_action' doesn't accept integers (so tool IDs) on Mac.

would the last update make it usable in macs?
edson mahfuz, architect
http://www.mahfuz.arq.br

Anyone can get you more for more, but it takes genius to get you more for less.
User avatar
Edson
Global Moderator
 
Posts: 2663
Joined: Mon Oct 22, 2007 1:46 pm
Location: Porto Alegre, Brasil
Name: Edson Mahfuz
Operating system: Mac
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [Plugin] Recall last tool v1.2

Postby Matt666 » Thu Apr 09, 2009 5:19 pm

I take it!
:thumb:
would the last update make it usable in macs?
... Dear Edson... I'm so sorry! :( You (and all Mac users!)have some problems with many of my scripts... Included this one...
I can't be usable in mac. Mac has a bug with main function used in this script: Sketchup.send_action(ToolID). And I can't do anything.
Sorry again Edson... :oops:
Frenglish at its best !
My scripts
Matt666
 
Posts: 829
Joined: Wed Dec 05, 2007 8:38 am
Location: 48.1184, -1.675
Name: Matt

Re: [Plugin] Recall last tool v1.2

Postby Edson » Thu Apr 09, 2009 6:24 pm

matt,

no problem. several other plugins you created work without problems. let's hope this bug gets solved in the future.
edson mahfuz, architect
http://www.mahfuz.arq.br

Anyone can get you more for more, but it takes genius to get you more for less.
User avatar
Edson
Global Moderator
 
Posts: 2663
Joined: Mon Oct 22, 2007 1:46 pm
Location: Porto Alegre, Brasil
Name: Edson Mahfuz
Operating system: Mac
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago

Need Authorised SketchUp Training by experts in various disciplines? Check out our Training details.

Ad Machine
Robot
 
Posts: 2012

Next

Return to Plugins

Who is online

Users browsing this forum: ALDob, archsejas, Bing [Bot], sohardaway and 6 guests