VCB greyed out
-
I'm making a fairly simple script called Thicken, thats basically a wrapper for JPP. My problem is that the VCB is greyed out - even after putting in enabledVCB?
Does anything stand out here (I removed the guts between start_operation and commit_operation for debugging purposes)?
### NOTE; Dev. halted - couldnt get Measurements (VCB/Value Control Box) input working require 'sketchup.rb' require 'extensions.rb' require 'jointpushpull.rb' thickenExt = SketchupExtension.new "Thicken", "CKD_Thicken.rb" thickenExt.version = '1.0' thickenExt.description = 'Uses JPP to thicken the select face/s directly or inside the selected groups' Sketchup.register_extension thickenExt, true module Thicken def initialize() @thickness = 100.mm @model = Sketchup.active_model selectedEntities = model.selection thickenTool = ThickenTool.new(self) @model.select_tool thickenTool model.start_operation "Thicken" model.commit_operation end class ThickenTool def initialize(caller_class) @caller = caller_class end def activate Sketchup.set_status_text "Thickness", SB_VCB_LABEL Sketchup.active_model.active_view.invalidate end def deactivate(view) view.invalidate end def onUserText(text, view) UI.messagebox("what") end def enableVCB? return true end end #Class ThickenTool if( !$thickenLoaded ) $ckdSubMenu.add_item("Thicken") { thicken } thickenLoaded = true end end #Module Thicken
-
First of all I get an error because $ckdSubMenu is not defined.
I replace that with
UI.menu('plugins')
and I get a new error:
Error: #<NameError: undefined local variable or method
thicken' for Thicken:Module>
c:/thicken.rb:52`I cannot just replace
thicken
withThicken.initialize
because that is a private method. I replace that withdef self.start_tool()
and call that.I then get an error on
selectedEntities = model.selection
becausemodel
is not defined. I replace allmodel
references with@model
.Then, when all these errors are solved the Tool activates and the VCB works just fine.
My question to you, did you even have the Ruby Console open when you tried your code?
<span class="syntaxdefault"></span><span class="syntaxcomment">### NOTE; Dev. halted - couldnt get Measurements (VCB/Value Control Box) input working<br /><br /> </span><span class="syntaxkeyword">require </span><span class="syntaxstring">'sketchup.rb'<br /> </span><span class="syntaxkeyword">require </span><span class="syntaxstring">'extensions.rb'<br /> </span><span class="syntaxkeyword">require </span><span class="syntaxstring">'jointpushpull.rb'<br /><br /> </span><span class="syntaxdefault">thickenExt </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">SketchupExtension</span><span class="syntaxkeyword">.new </span><span class="syntaxstring">"Thicken"</span><span class="syntaxkeyword">, </span><span class="syntaxstring">"CKD_Thicken.rb"<br /> </span><span class="syntaxdefault">thickenExt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">version </span><span class="syntaxkeyword">= </span><span class="syntaxstring">'1.0'<br /> </span><span class="syntaxdefault">thickenExt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">description </span><span class="syntaxkeyword">= </span><span class="syntaxstring">'Uses JPP to thicken the select face/s directly or inside the selected groups'<br /> </span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">register_extension thickenExt</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">true<br /><br /> module Thicken<br /><br /> def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start_tool</span><span class="syntaxkeyword">()<br /> @</span><span class="syntaxdefault">thickness </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">100.mm<br /><br /> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">model </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br /> selectedEntities </span><span class="syntaxkeyword">= @</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">selection<br /> <br /> thickenTool </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">ThickenTool</span><span class="syntaxkeyword">.new(</span><span class="syntaxdefault">self</span><span class="syntaxkeyword">)<br /> @</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">select_tool thickenTool<br /><br /> </span><span class="syntaxcomment">#model.start_operation "Thicken"<br /><br /> #model.commit_operation <br /> </span><span class="syntaxdefault">end<br /><br /> </span><span class="syntaxkeyword">class </span><span class="syntaxdefault">ThickenTool<br /> def initialize</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">caller_class</span><span class="syntaxkeyword">)<br /> @</span><span class="syntaxdefault">caller </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">caller_class<br /> end<br /> <br /> def activate<br /> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">set_status_text </span><span class="syntaxstring">"Thickness"</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">SB_VCB_LABEL<br /> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">invalidate<br /> end<br /> <br /> def deactivate</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">view</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">invalidate<br /> end<br /> <br /> def onUserText</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">text</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">view</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">messagebox</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"what"</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">end<br /> <br /> def enableVCB</span><span class="syntaxkeyword">?<br /> return </span><span class="syntaxdefault">true<br /> end<br /> end </span><span class="syntaxcomment">#Class ThickenTool<br /><br /> </span><span class="syntaxkeyword">if( !</span><span class="syntaxdefault">$thickenLoaded </span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'Plugins'</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Thicken"</span><span class="syntaxkeyword">) { </span><span class="syntaxdefault">Thicken</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start_tool </span><span class="syntaxkeyword">} <br /> </span><span class="syntaxdefault">thickenLoaded </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">true<br /> end<br /><br /> end </span><span class="syntaxcomment">#Module Thicken<br /> </span><span class="syntaxdefault"></span>
-
Duke, ya need to get your files and folders organized (so you stop using global variables.)
Separate the code into 3 files, thus:file: "Plugins/CKD_Thicken_ext.rb"
### # "Plugins/CKD_Thicken_ext.rb" require('sketchup.rb') require('extensions.rb') module CKD module Thicken @@plugin = SketchupExtension.new "Thicken", "CKD/Thicken/CKD_Thicken.rb" @@plugin.version = '1.0' @@plugin.creator = 'CKD (aka "Duke")' @@plugin.copyright = '2012, CKD' @@plugin.description = 'Uses JPP to thicken the select face/s directly or inside the selected groups' Sketchup.register_extension( @@plugin, true ) end # module Thicken end # module CKD
file: "Plugins/CKD/CKD_module.rb"
# ------------------------------------------------------------------------- # "Plugins/CKD/CKD_module.rb" module CKD @@topmenu = UI.menu('Plugins') @@submenu = @@topmenu.add_submenu('CKD') @@menuitem = {} def self.menuitem() return @@menuitem end def self.submenu() return @@submenu end def self.topmenu() return @@topmenu end end # module CKD
file: "Plugins/CKD/Thicken/CKD_Thicken.rb"
# ------------------------------------------------------------------------- # "Plugins/CKD/Thicken/CKD_Thicken.rb" require('sketchup.rb') require('jointpushpull.rb') require('CKD/CKD_module.rb') module CKD;;Thicken @@tool = nil class ThickenTool def initialize(caller_class) @caller = caller_class @thickness = 100.mm end def activate @model = Sketchup.active_model @selected = @model.selection Sketchup.set_status_text("Thickness", SB_VCB_LABEL) Sketchup.active_model.active_view.invalidate end def deactivate(view) view.invalidate @model = nil @selected = nil end def resume(view) @model = Sketchup.active_model @selected = @model.selection Sketchup.set_status_text("Thickness", SB_VCB_LABEL) Sketchup.active_model.active_view.invalidate end def suspend(view) nil end def onUserText(text, view) UI.messagebox("what") # call method thicken() here ? end def enableVCB? return true end def thicken model.start_operation("Thicken") # # change model here # model.commit_operation rescue Exception => e model.abort_operation puts("Thicken Error!\n#{e.message}") puts(e.backtrace) end end #Class ThickenTool class << self # Proxy class def tool() if @@tool.nil? @@tool = CKD;;Thicken;;ThickenTool.new(self) end # return @@tool # end end # Proxy class # RUN ONCE unless file_loaded?( 'CKD;;Thicken' ) CKD;;menuitem["Thicken"]= CKD;;submenu.add_item("Thicken") { Sketchup.active_model.select_tool( CKD;;Thicken;;tool ) } file_loaded( 'CKD;;Thicken' ) end end # module CKD;;Thicken
Advertisement