ICON MF_ENABLED, MF_CHECKED
-
Please indent your coe consistently and helpfully...
You have NOT added the @ !
None of your commands have a @ prefix.
If this is all of your code it's also wrong in other ways.
The various @ references need a commond 'parent' module, so they can be seen by the methods...
It all needs to be inside your own module[s].
The commands are set up as the code loads.
These should have @ names so that the methods can also access them.
Here is an outline - I have already given you something like this earlier in the week...
Do NOT following the exact naming etc just understand how the parts work, and apply them to your own needs...module TNTDAVID module ClickWindow ### set up commands @commandA = UI.command.new('CmdA'){self.cmdA()} ### add icons, tooltips etc @commandB = UI.command.new('CmdB'){self.cmdB()} ### add icons, tooltips etc ### add it's toolbar ### add the buttons to toolbar to run the commands ### etc ### the methods run by the commands... ### def self.cmdA() ### the code run by commandA ### do stuff here, that can then 'see' the @commandA and @commandB ### which are instance variable references to the two commands ! ### disable @commandB ### do some processing... ### if the user jumps out of processing before the end ensure that @commandB is re-enabled ### ### at the end re-enable @commandB end#method ### you say you want vice vers affects from the two toolbar buttons ! def self.cmdB() ### the code run by commandB ### do stuff here, that can then 'see' the @commandA and @commandB ### which are instance variable references to the two commands ! ### disable @commandA ### do some processing... ### if the user jumps out of processing before the end ensure that @commandA is re-enabled ### ### at the end re-enable @commandA end#method end#module end#module
-
@tig said:
o NOT following the exact naming etc just understand how the parts work, and apply them to your own needs...
I understand your logic in your example!
If I miss is the formulation of the code ....
**module TNTDAVID
module ClickWindow
### set up commands OK
@commandA = UI.command.new('CmdA'){self.cmdA()}### add icons, tooltips etc %(#FF0000)[OK] @commandB = UI.command.new('CmdB'){self.cmdB()} ### add icons, tooltips etc %(#FF0000)[OK] ### add it's toolbar %(#FF0000)[OK] ### add the buttons to toolbar to run the commands %(#FF0000)[OK] ### etc ### the methods run by the commands... %(#FF0000)[OK] ### def self.cmdA() ### the code run by commandA %(#FF0000)[OK] ### do stuff here, that can then 'see' the @commandA and @commandB %(#FF0000)[OK] ### which are instance variable references to the two commands ! %(#BF0000)[OK] ### disable @commandB %(#FF0040)[**1.how?**
@cmdB.set_validation_proc{MF_GRAYED}
The code does not work, even if I add an "@", between maybe curly braces.]
### do some processing... %(#FF0000)[OK] ### if the user jumps out of processing before the end ensure that @commandB is re-enabled
2.How should write the code?
### at the end re-enable @commandB **%(#FF0000)[3.how?]** end#method ### you say you want vice vers affects from the two toolbar buttons !** %(#FF0000)[OK]
I think I expressed myself badly, is you do not have can understand my goals.
"cmdA" is "GRAYED" by défeaut which is (mode1), even when you start SketchUp.
It remains "GRAYED" all the TIME! unless the user clicks on the icon "CMDB" to enter in the (mode2).
Under this condition, the icon "cmdB" becomes "GRAYED" is "cmdA" becomes "ENABLED".
---cmdA- cmdB
4.I think your example, does not have the same objectives?
Thank you
David
-
Reread what you wrote...
@cmdB
is a method NOT a command, so try
@commandB.set_validation_proc{MF_GRAYED}
In Ruby there is the:
begin ... #a rescue ... #b ensure ... #c end
functionAfter you disable
@commandB
then you ought to do all of your remaining processing within the 'begin......end
' - starting at#a
If these is a possibility that the user stops the process part way through, then you need to somehow spot it and then re-enable @commandB - that depends on your own code...
If it fails with an error - it invokes 'rescue' at #b - so then you also need to re-enable @commandB in that part.
The safety-net is the 'ensure' at #c - then you also need to re-enable @commandB in that part as well.
For further confidence I'd also add a re-enable for @commandB after the end of the
begin......end
- although I think it'll survive without it [obviously I haven't tested any of the is !]NB: The re-enable code is:
@commandB.set_validation_proc{MF_ENABLED}
-
TIG, I just write code that conforms to your example:
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() model = Sketchup.active_model model_definition = model.definitions model_def = model_definition['Box'] model_def.set_attribute 'dynamic_attributes','mode', '1' 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{MF_GRAYED} @commandB.set_validation_proc{MF_DISABLED} end ### you say you want vice vers affects from the two toolbar buttons ! ????? def self.cmdB() 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' @commandB.set_validation_proc{MF_GRAYED} @commandA.set_validation_proc{MF_DISABLED} end end end
Error message:
@unknownuser said:
Error: #<NameError: undefined local variable or method `commandA' for TesteCube::ClickWindow:Module>
There is a problem with "@" because without it, there is no error.
Or are my mistakes?
Thank you
-
Just looking at the error:
Error: #<NameError: undefined local variable or method
commandA'`
My guess would be you forgot to add the @ in these lines. If you don't add it, the commandA is not initialized/set.
-
As @kaas succinctly says...
Your code is full of typos or un-corrected errors.
Please proofread more closely [see below]...Also learn to read the error messages - where the reference or the line is given in the error-message in the Ruby Console...
If you have Notepad++ and still can't locate the erroneous line, then you could select a variable's name and use 'find' to 'mark' all matching strings in your code.
Any strings with a similar, BUT not exactly-matching, name can be found using a 'find' etc...This is an issue of attention to detail and care, rather than understanding how the code might work...
5/10 -
Thanks you kaas for your advices.
I added the "@", and there is always the same error message.
@tig said:
Your code is full of typos or un-corrected errors.
Or are errors frape TIG?
That surprises me because the code works without any error message if there is no longer the @.
To my typos, you refer to your examples:
@tig said:
@cmdA=UI.command.new('cmdA'){self.cmdA())
I had to correct like this:
@commandA = UI::Command.new("cmdA"){ ClickWindow.cmdA()}
If not, there was a lot of error messages for a single line.
Thank you to tell me that I have errors in my code, I would be happier if you show me.
Thank you
David
-
OK, gloves off...
You do not seem to be able to understand OR to appreciate good advice...
Many of us had offered tips, which you then ignore - often annoyingly !
...In the example code you posted, you use 'commandA' and 'cmdA' with no thought as to what they refer to !!!
One is a 'command' and the other is a 'method' resulting from that command...So as it is this will certainly fail.
Please learn how to inspect your code, for at least some semblance of order, and correct it...
The rest of us have other lives to lead and work to do - please try to help us to help you................
-
@tig said:
OK, gloves off...
You do not seem to be able to understand OR to appreciate good advice...
Many of us had offered tips, which you then ignore - often annoyingly !Of course I'm taking your advice and I'm doing my best to move forward.
I voluntarily writing new code, to follow your example, so it is not fair to say things like that.
@tig said:
In the example code you posted, you use 'commandA' and 'cmdA' with no thought as to what they refer to !!!
One is a 'command' and the other is a 'method' resulting from that command...I did the same thing on your example, "cmdA" is a method of command is "commandeA".
So I do not understand or you see a problem?
Perhaps if you do a simple copy / paste my code with your corrections, it would be much simpler and effective?
It's allow myself to understand my mistakes very quickly. -
Sorry I got overwrought.
But you can be very frustrating...def self.cmdA()
is the method that is run by the command@commandA
The reason you make it an instance variable with the @ is that the method should see the reference to the command, without it it will not.
As @kaas highlighted in yellow boxes you [correctly] set up
@commandA
and later on make a reference tocommandA
which will not work !
You also make the same error for@commandB
...Please read your code carefully.
With Notepad++ if you select the text
@commandA
all occurrences of it will be colored.
You can then 'mark' then, then selectcommandA
[sans @] and all will color - including so that were not marked in the earlier step, because of the missing @... -
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.
Advertisement