ICON MF_ENABLED, MF_CHECKED
-
TIG no problem.
Indeed "Kaas" had identified the problem!
As a noodle, I did not understand that the "@" missing, should be in brackets.
The solution to the error message is simply this:
cc_menu.add_item (@commandA) tb.add_item (@commandA)
And it's the same for "commandeB".
As this problem is resolved, we can move forward hopefully.
TIG, the line of code:
@commandA.set_validation_proc{MF_DISABLED}
Does not work!
If there are orders below this line, they will not be executed.
I tried all possible variants, with the "@" among the accolades, but it does not change ...
1.Do you knows why?
Other subject:
The more I discovered the ruby, the more I realize that it is an incredible complexity.
If I write this in ruby ââconsol:
model = Sketchup.active_model model_definition = model.definitions model_def = model_definition['box'] valeur = model_def.get_attribute 'dynamic_attributes','mode'
She references me the value of the "mode" attribute, which exists in the dynamic component, "box".
Let's say the result is 1.
If I add this logic test:
if valeur == 1 puts "MODE 1" else puts "MODE2" end
He answer each time, "Mode 2".
Or am i completely off base of wall, if who is the safest, or the ruby ââscript is not logical.
2.Can you tell me, how such a thing is possible?
I thank you for your emotional support.
David
-
Answering in reverse order...
DC values are strings
If it exists it might be say"1"
rather than1
If it doesn't exist it'd benil
- UNLESS you use a default response...
valeur = model_def.get_attribute('dynamic_attributes', 'mode', 'merde')
In which case you'd get a meaningful 'bad' result...
To see if it's getting read add in...
puts @commandA
It should show a valid command in the Ruby Console...
then try...
@commandA.set_validation_proc{ MF_DISABLED }
Try other alternatives: MF_ENABLED, MF_DISABLED, MF_CHECKED, MF_UNCHECKED, or MF_GRAYED.
ALWAYS test your code running it with the Ruby Console open, so you see the useful error messages...Remember that the commands need to 'negate' their opposite sibling command...
Remember that your code needs to disable the opposite command as it starts and then re-enable it on completion of its processing, otherwise it'll remain disabled thereafter ! -
@TNTDAVID - to investigate problems like this yourself, you just do
puts valeur
just aftervaleur = model_def.get_attribute 'dynamic_attributes','mode'
At that moment you will see a value, an error, a string etc - when you expected an int etc etc. Next you can try to fix it.If that puts returns a value though as expected you do the same in the next line where some code is executed etc etc. Repeat until you solved the problem.
Leaving the ruby console open is essential because errors are displayed there with some hints/line numbers where the code fails.For anyone new in ruby (also for me), this really helps in learning why code fails. Asking here might result in a solution but you will learn not as much compared to trying to debug your code yourself.
-
I do not have the expected result, but at least the code works with the "puts".
@commandB.set_validation_proc{ puts MF_DISABLED }
The ruby console goes crazy, and sending 0 continuously after clicking on an icon ...
Here's the code:
module TesteCube module ClickWindow @@path_to_resources = File.join(File.dirname(__FILE__), 'Resources') if !file_loaded?(__FILE__) su_menu = UI.menu("Plugins") cc_menu = su_menu.add_submenu(%Q(TesteCube)) tb = UI;;Toolbar.new(%Q(TesteCube)) @commandA = UI;;Command.new("mode1"){ ClickWindow.cmdA()} @commandA.small_icon = File.join(@@path_to_resources,"add_A.png") @commandA.large_icon = File.join(@@path_to_resources,"add_A.png") @commandA.tooltip = %Q(Opens Settings SketchUp) @commandA.status_bar_text = %Q(Opens Settings SketchUp) @commandA.menu_text = %Q(Opens Settings SketchUp) cc_menu.add_item(@commandA) tb.add_item(@commandA) @commandB = UI;;Command.new("mode1"){ ClickWindow.cmdB()} @commandB.small_icon = File.join(@@path_to_resources,"add_B.png") @commandB.large_icon = File.join(@@path_to_resources,"add_B.png") @commandB.tooltip = %Q(Opens Settings SketchUp) @commandB.status_bar_text = %Q(Opens Settings SketchUp) @commandB.menu_text = %Q(Opens Settings SketchUp) cc_menu.add_item(@commandB) tb.add_item(@commandB) tb.restore file_loaded(__FILE__) end def self.cmdA() @commandB.set_validation_proc{ puts MF_DISABLED } model = Sketchup.active_model model_definition = model.definitions model_def = model_definition['Box'] model_def.set_attribute 'dynamic_attributes','a0000mode', '1' model_def.set_attribute 'dynamic_attributes','_a0000mode_label', 'mode' model_def.set_attribute 'dynamic_attributes','_a0000mode_units', 'STRING' model_def.set_attribute 'dynamic_attributes','_a0000mode_access', 'TEXTBOX' @commandB.set_validation_proc{ puts MF_ENABLED } end ### you say you want vice vers affects from the two toolbar buttons ! ????? def self.cmdB() @commandA.set_validation_proc{ puts MF_DISABLED } model = Sketchup.active_model model_definition = model.definitions model_def = model_definition['Box'] model_def.set_attribute 'dynamic_attributes','mode', '2' model_def.set_attribute 'dynamic_attributes','_mode_label', 'mode' model_def.set_attribute 'dynamic_attributes','_mode_units', 'STRING' model_def.set_attribute 'dynamic_attributes','_mode_access', 'TEXTBOX' @commandA.set_validation_proc{ puts MF_ENABLED } end end end
The code inside the methods are properly executed, but the icons state does not change.
What's wrong?
@tig said:
DC values are strings
If it exists it might be say "1" rather than 1TIG thank you, it works fine now.
The message is passed, "Kaas" I work only with the ruby consol to find my mistakes.
I just noticed that the ruby consol, create the toolbar and the icons.
It lacks the "png", but this is normal.
Big thank you to you both for your advice.
Thank you
-
The 'crazy console' is because you put a puts at a very strange position ?!?
@commandB.set_validation_proc{puts MF_DISABLED}
Why did you put the puts there?? It makes no sense (to me). Think about the difference.
@commandB.set_validation_proc{MF_DISABLED}
-
If I remove the strange puts it still doesn't work and I think the reason is; you mixed up the logic for enabling / disabling the buttons;
if you enable A, you should disable B and vice versa. In your code you first enable A and then disable the same again.The code below does show switching icons. I used CHECKED instead of ENABLED so its more clear.
module TesteCube module ClickWindow @@path_to_resources = File.join(File.dirname(__FILE__), 'Resources') if !file_loaded?(__FILE__) su_menu = UI.menu("Plugins") cc_menu = su_menu.add_submenu(%Q(TesteCube)) tb = UI;;Toolbar.new(%Q(TesteCube)) @commandA = UI;;Command.new("mode1"){ ClickWindow.cmdA()} @commandA.small_icon = File.join(@@path_to_resources,"add_A.png") @commandA.large_icon = File.join(@@path_to_resources,"add_A.png") @commandA.tooltip = %Q(Opens Settings SketchUp) @commandA.status_bar_text = %Q(Opens Settings SketchUp) @commandA.menu_text = %Q(Opens Settings SketchUp) cc_menu.add_item(@commandA) tb.add_item(@commandA) @commandB = UI;;Command.new("mode1"){ ClickWindow.cmdB()} @commandB.small_icon = File.join(@@path_to_resources,"add_B.png") @commandB.large_icon = File.join(@@path_to_resources,"add_B.png") @commandB.tooltip = %Q(Opens Settings SketchUp) @commandB.status_bar_text = %Q(Opens Settings SketchUp) @commandB.menu_text = %Q(Opens Settings SketchUp) cc_menu.add_item(@commandB) tb.add_item(@commandB) tb.restore file_loaded(__FILE__) end def self.cmdA() #puts'cmdA' @commandA.set_validation_proc{MF_CHECKED} @commandB.set_validation_proc{MF_DISABLED} end def self.cmdB() #puts'cmdB' @commandA.set_validation_proc{MF_DISABLED} @commandB.set_validation_proc{MF_CHECKED} end end end
-
Kaas Congratulations!
A simple test of logic and the code works.
For "puts", I misunderstood fredo:
@fredo6 said:
This is a proc, so it is called by Sketchup and expect a return value to set the state of the icon. It is called almost continuously (you can check that by the statement command18.set_validation_proc { puts "icon proc" ; MF_GRAYED }.
I can resume my labors, and I hold you informed of advancements or problems.
Thank you for your help!
See you soon
David
-
A question that comes to mind.
How an icon can be activated and deactivated with each click.
Example:
1st click on iconeA = "MF_CHECKED"
2nd click on iconeA = "MF_ENABLED"
3rd click on iconeA = "MF_CHECKED" ....I tried this line of code:
@commandA.set_validation_proc{ MF_CHECKED; MF_ENABLED }
It does not work.
Do you know the method to be followed?
Thank you
-
No surprise it doesn't work - you are making up code that doesn't exist in the API. http://www.sketchup.com/intl/en/developer/docs/ourdoc/command#set_validation_proc
Just make a @variable to store the current state (0/1/2) and after clicking on an icon read the variable, use the proper MF_... and set the @variable to another value.
Off-topic; coming from someone who is selling a SketchUp plugin for E99,- I find your questions and knowledge of Ruby rather 'strange'...
-
I discovered the ruby ...
My plugins are tools that work only with Dynamic Components.
Many underestimate the power of dynamic components, which offer unlimited possibilitys.
Example:
Click-Change or Click-Kitchen, totaling 100,000 downloads, and more than a Million views in the entropot extensions.
And 100% of my clients are satisfied.
I am currently working on an updated Click-Window 3D, which will bring a lot of positive change.
If I cling to the ruby, it's in the one and only goal, to offer even more to my customers.
-
With your code
@commandA.set_validation_proc{ MF_CHECKED; MF_ENABLED }
It should set the @commandA menu item to be checked and enabled.
It probably won't 'check' the toolbar button - which should be enabled or disabled/grayed ?
BUT before you do that have you added
puts @commandA
in a line immediately before.
When you run the command from its button, then it is shows up in the Ruby Console as a reference to a command if it's working right, but if it's nil it's somehow coded wrongly... -
Good evening,
Icon 1, use the following method:
def self.panel model = Sketchup.active_model layers = model.layers new_layer = layers.add "Click-Window 3D" if new_layer.visible? new_layer.visible = false else new_layer.visible = true end end
Icon 2, uses this method:
def self.layerhid model = Sketchup.active_model layers = model.layers new_layer = layers.add "Click-Window 3D" new_layer.visible = false instance.layer = new_layer end
When I use the two icons, the visibility of the layer starts to bugger.
Even if the code activates or deactivates the layer in the Layers window, the composents with this layer do not change state.
Do you know why this strange bug?
If so, how to avoid it?
Thank you in advance for your help.
David
-
If you added some puts to your code, you could get some more info on what your code is doing and where/why your code fails.
In short:
your first block (self.panel) is just toggling the visibility ofnew_layer
your second block (self.layerhid) is always hiding the visibility ofnew_layer
instance
has not been defined in that second block so if you try to change its layer usinginstance.layer=
it will fail. It probably has to be@my_instance
that you have defined elsewhere. There probably was an error message about that in the Ruby Console that you forgot to read/post...def self.panel model = Sketchup.active_model layers = model.layers new_layer = layers.add "Click-Window 3D" if new_layer.visible? new_layer.visible = false puts %(self.panel is setting visibility to false) else new_layer.visible = true puts %(self.panel is setting visibility to true) end end def self.layerhid model = Sketchup.active_model layers = model.layers new_layer = layers.add "Click-Window 3D" new_layer.visible = false puts %(self.layerhid is setting visibility to false) instance.layer = new_layer puts instance.layer end
-
@tig said:
With your code
@commandA.set_validation_proc{ MF_CHECKED; MF_ENABLED }
It should set the @commandA menu item to be checked and enabled.Thank you for that clarification, TIG.
@kaas said:
instance has not been defined in that second block so if you try to change its layer using instance.layer= it will fail. It probably has to be @my_instance that you have defined elsewhere. There probably was an error message about that in the Ruby Console that you forgot to read/post...
Oops! I made a mistake in my copy / pasted, instance.layer should not exist in "Method layerhid".
As I noticed the error in the ruby ââconsole, and there to any subject in the API on "instance.layer", I ended up deleting it.
Regarding "Puts", I added them more, because it can prevent in some cases, a method of work.
Example:
if new_layer.visible? puts new_layer.visible = false # action 1A puts Sketchup.send_action "selectSelectionTool;" # action 2A elsif puts new_layer.visible = true # action 1B puts Sketchup.active_model.select_tool(DCInteractTool.new($dc_observers)) # action 2B end
This does not work!
If I remove the puts as:
if new_layer.visible? new_layer.visible = false # action 1A Sketchup.send_action "selectSelectionTool;" # action 2A elsif pnew_layer.visible = true # action 1B Sketchup.active_model.select_tool(DCInteractTool.new($dc_observers)) # action 2B end
The code works!
With or without "Puts", the console displays the line number or there is an error.
So what are the avanatges of "Puts"?
@kaas said:
def self.panel
  model = Sketchup.active_model
  layers = model.layers
  new_layer = layers.add "Click-Window 3D"
  if new_layer.visible?
    new_layer.visible = false
    puts %(self.panel is setting visibility to false)
  else
    new_layer.visible = true
    puts %(self.panel is setting visibility to true)
  end
enddef self.layerhid
  model = Sketchup.active_model
  layers = model.layers
  new_layer = layers.add "Click-Window 3D"
  new_layer.visible = false
  puts %(self.layerhid is setting visibility to false)
  instance.layer = new_layer
  puts instance.layer
endThank you for your example code.
Unfortunately the problem still exists.
Here is the error message:
@unknownuser said:
self.layerhid is setting visibility to false
Error: #<NoMethodError: undefined methodtransform!' for #<Sketchup::ComponentDefinition:0x0000000e47fb40>> c:/users/david/appdata/roaming/sketchup/sketchup 2015/sketchup/plugins/su_dynamiccomponents/ruby/dcclass_v1.rbs:454:in
redraw'
c:/users/david/appdata/roaming/sketchup/sketchup 2015/sketchup/plugins/su_dynamiccomponents/ruby/dcclass_v1.rbs:406:inredraw_with_undo' C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TNT_ClickWindow3D_Pro_mm/logic.rb:217:in
mode1'
C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TNT_ClickWindow3D_Pro_mm/logic.rb:252:inblock in <module:CW_Pro_mm>' SketchUp:1:in
call'Here are the relevant lines:
L217 - $dc_observers.get_latest_class.redraw_with_undo(model_def)
# mode 1L252 - @commandA = UI::Command.new("Mode 1"){ CW_Pro_mm.mode1 }
L406 - command12.tooltip = %Q(add Crank Window)
L454 - @commandO.small_icon = File.join(@@path_to_resources,"add_O.png")
I'm surprised these lines triggers an error message!
They exist in other methods or command, with these objects that works.
It is therefore difficult to understand the reasons of the error message.
Thank you
David
-
I think the changing of button states on the fly is an issue.
So try this alternative:module TesteCube module ClickWindow @@path_to_resources = File.join(File.dirname(__FILE__), 'Resources') if ! file_loaded?(__FILE__) su_menu = UI.menu("Plugins") cc_menu = su_menu.add_submenu(%Q(TesteCube)) tb = UI;;Toolbar.new(%Q(TesteCube)) @disableA=false @disableB=false @commandA = UI;;Command.new("mode1"){ @disableB=true; self.cmdA(); @disableB=false } @commandA.small_icon = File.join(@@path_to_resources,"add_A.png") @commandA.large_icon = File.join(@@path_to_resources,"add_A.png") @commandA.tooltip = %Q(Opens Settings SketchUp) @commandA.status_bar_text = %Q(Opens Settings SketchUp) @commandA.menu_text = %Q(Opens Settings SketchUp) cc_menu.add_item(@commandA) tb.add_item(@commandA) @commandB = UI;;Command.new("mode1"){ @disableA=true; self.cmdB(); @disableA=false } @commandB.small_icon = File.join(@@path_to_resources,"add_B.png") @commandB.large_icon = File.join(@@path_to_resources,"add_B.png") @commandB.tooltip = %Q(Opens Settings SketchUp) @commandB.status_bar_text = %Q(Opens Settings SketchUp) @commandB.menu_text = %Q(Opens Settings SketchUp) cc_menu.add_item(@commandB) tb.add_item(@commandB) @commandA.set_validation_proc{ if @disableA MF_DISABLED else MF_ENABLED end } @commandB.set_validation_proc{ if @disableB MF_DISABLED else MF_ENABLED end } tb.restore file_loaded(__FILE__) end def self.cmdA() UI.messagebox('cmdA') end def self.cmdB() UI.messagebox('cmdB') end end end
It sets two possible states for the buttons and sets/resets those each time the commands are run, running the code between those 'bookends'...
I've made it a UI.messagebox so you can the affect on the toolbar buttons - otherwise it'll be transitory... -
TIG thank you, but the state of the buttons is not the problem!
The bontons work fine with my current code.
I was wrong on all the line!
The problem is this object:
$dc_observers.get_latest_class.redraw_with_undo(model_def)
It is used in this method:
def self.mode1 @commandA.set_validation_proc{MF_GRAYED} @commandB.set_validation_proc{MF_ENABLED} @commandP.set_validation_proc{MF_GRAYED} @commandO.set_validation_proc{MF_ENABLED} model = Sketchup.active_model model_definition = model.definitions model_def = model_definition['Control Panel'] model_def.set_attribute 'dynamic_attributes','a0000mode', '1' model_def.set_attribute 'dynamic_attributes','_a0000mode_label', 'a0000mode' model_def.set_attribute 'dynamic_attributes','_a0000mode_units', 'STRING' model_def.set_attribute 'dynamic_attributes','_a0000mode_access', 'TEXTBOX' $dc_observers.get_latest_class.redraw_with_undo(model_def) end
This method changes a component attribute that uses the "Click-Window 3D"
Once this method is used, the component's display starts messing.
Here is my problem:
Have you an idea of the problem?
Thank you
-
Isn't that method used on the currently selected DC instance NOT a definition !?
So perhaps it should be something like
$dc_observers.get_latest_class.redraw_with_undo(model_def.instances[0])
-
@tig said:
Isn't that method used on the currently selected DC instance NOT a definition !?
So perhaps it should be something like
$dc_observers.get_latest_class.redraw_with_undo(model_def.instances[0])It is in this kind of situation that your experience is very beneficial, TIG.
Congratulation!
Advertisement