Using win32ole on startup
-
Won't that loop block the rest of SketchUp? Ruby doesn't let SketchUp "breathe" when it's working - that's why the UI white outs because not even the Windows messages are given any opportunity to be processed.
-
But presumably it'll only pause briefly until model.entities in returned ?
OR it could start a timer that'd run separately ?require 'sketchup.rb' require 'win32ole.so' module SR20VET def SR20VET.xls() UI.start_timer(1,false){ model = Sketchup.active_model until model.entities model_dict = model.attribute_dictionary("thisIsADict") if model_dict xl = WIN32OLE.new('Excel.Application') ### rest of code ### end end }#end timer end#def end#module SR20VET.xls()
-
@tig said:
But presumably it'll only pause briefly until model.entities in returned?
Pretty sure it won't, because the rest of SU can't continue until the loop is complete. You might have created an infinite loop. SketchUp's doesn't run in parallel with the ruby engine. It's sequential processing.
-
I think this'll work:
require 'sketchup.rb' require 'win32ole.so' module SR20VET def SR20VET.xls() timer=UI.start_timer(0,false){ UI.stop_timer(timer) model = Sketchup.active_model until model.entities; end model_dict = model.attribute_dictionary("thisIsADict") if model_dict xl = WIN32OLE.new('Excel.Application') ### rest of code ### end }#end timer end#def end#module SR20VET.xls()
-
For timer delay you should immediately stop the timer in it's block - because if a modal window appear within the block, like a messagebox or an error message (which you get when you start SU) will make the timer repeat until the modal window is closed.
<span class="syntaxdefault"><br />timer </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start_timer</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">false</span><span class="syntaxkeyword">){<br /> </span><span class="syntaxdefault">UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">stop_timer</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">timer</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxcomment"># ...<br /></span><span class="syntaxkeyword">}<br /> </span><span class="syntaxdefault"></span>
-
Added to last post for avoidance of confusion...
-
Sorry to drag this off topic, but what does win32ole do? It looks like the code is interfacing with excel? Will win32ole read and write excel files? I'm looking around here:
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/win32ole/rdoc/index.html
But I don't see an explanatiojn of what it does.
-
OLE is an interface for communicating with Objects. Excel has implemented this interface so you can communicate with Excel.
Win32OLE is a library that allows you to use OLE interfaces within Ruby.
-
[Plugin Library] Win32API and Win32OLE so files
Online reference rdocs for these 2 libraries:
-
@thomthom said:
For timer delay you should immediately stop the timer in it's block - because if a modal window appear within the block, like a messagebox or an error message (which you get when you start SU) will make the timer repeat until the modal window is closed.
<span class="syntaxdefault"><br />timer </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start_timer</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">false</span><span class="syntaxkeyword">){<br /></span><span class="syntaxdefault"> UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">stop_timer</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">timer</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># ...<br /></span><span class="syntaxkeyword">}<br /> </span><span class="syntaxdefault"></span>
Hi Thom and TIG, that's exactly how ì solved it. Noticed the fact that a UI.messagebox in the block will make the timer repeat too.
Never used UI.start_timer before but I can think of some nice implementations of it.
Advertisement