• Login
sketchucation logo sketchucation
  • Login
πŸ”Œ Quick Selection | Try Didier Bur's reworked classic extension that supercharges selections in SketchUp Download

Using win32ole on startup

Scheduled Pinned Locked Moved Developers' Forum
14 Posts 5 Posters 272 Views 5 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    SR20VET
    last edited by 5 Nov 2012, 12:45

    Hello,

    I have some difficulties on starting a WIN32OLE.new('Excel.Application') on startup of SketchUp... code I have is simple in test.rb:

    
    require 'sketchup.rb'
    require 'win32ole.so'
    model_dict = Sketchup.active_model.attribute_dictionary "thisIsADict"
    xl = WIN32OLE.new('Excel.Application') if model_dict
    
    

    The Error i get is:
    uninitialized constant WIN32OLE

    I think this has something to do with me trying to start an ole connection directly on start-up. If I assign the code to a command, there is no problem...
    But, the code needs to be executed directly when a specific .skp (with "thisIsADict" library) is opened...

    Any ideas how to solve this would be great.

    Cheers!

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 5 Nov 2012, 13:06

      You shouldn't be adding the extension. require 'win32ole' is the convention.

      Not sure if that's the source of your issues though.

      But you might have other problems: trying to access Sketchup.active_model on startup. Not sure if everything is available when the Ruby engine is initialized. You might want to check that.

      Thomas Thomassen β€” SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • T Offline
        thomthom
        last edited by 5 Nov 2012, 13:07

        Does the same code work if you run it after SketchUp has started?

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 5 Nov 2012, 13:48

          Have you tried enclosing it and then waiting until things settle down?

          require 'sketchup.rb'
          require 'win32ole.so'
          module SR20VET
            def SR20VET.xls()
              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#def
          end#module
          SR20VET.xls()
          
          

          TIG

          1 Reply Last reply Reply Quote 0
          • T Offline
            thomthom
            last edited by 5 Nov 2012, 13:56

            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.

            Thomas Thomassen β€” SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • T Offline
              TIG Moderator
              last edited by 5 Nov 2012, 13:59

              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

              1 Reply Last reply Reply Quote 0
              • T Offline
                thomthom
                last edited by 5 Nov 2012, 14:02

                @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.

                Thomas Thomassen β€” SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • T Offline
                  TIG Moderator
                  last edited by 5 Nov 2012, 15:08

                  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()
                  

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    thomthom
                    last edited by 5 Nov 2012, 15:11

                    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&nbsp;</span><span class="syntaxkeyword">=&nbsp;</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 />&nbsp;&nbsp;</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 />&nbsp;&nbsp;</span><span class="syntaxcomment">#&nbsp;...<br /></span><span class="syntaxkeyword">}<br />&nbsp;</span><span class="syntaxdefault"></span>
                    

                    Thomas Thomassen β€” SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      TIG Moderator
                      last edited by 5 Nov 2012, 16:07

                      Added to last post for avoidance of confusion...

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • Chris FullmerC Offline
                        Chris Fullmer
                        last edited by 5 Nov 2012, 16:52

                        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.

                        Lately you've been tan, suspicious for the winter.
                        All my Plugins I've written

                        1 Reply Last reply Reply Quote 0
                        • T Offline
                          thomthom
                          last edited by 5 Nov 2012, 16:55

                          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.

                          http://en.wikipedia.org/wiki/Object_Linking_and_Embedding

                          Thomas Thomassen β€” SketchUp Monkey & Coding addict
                          List of my plugins and link to the CookieWare fund

                          1 Reply Last reply Reply Quote 0
                          • Dan RathbunD Offline
                            Dan Rathbun
                            last edited by 6 Nov 2012, 08:46

                            [Plugin Library] Win32API and Win32OLE so files

                            Online reference rdocs for these 2 libraries:

                            • Win32API rdoc
                            • WIN32OLE rdoc

                            I'm not here much anymore.

                            1 Reply Last reply Reply Quote 0
                            • S Offline
                              SR20VET
                              last edited by 6 Nov 2012, 22:33

                              @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 />&nbsp;</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.

                              1 Reply Last reply Reply Quote 0
                              • 1 / 1
                              1 / 1
                              • First post
                                1/14
                                Last post
                              Buy SketchPlus
                              Buy SUbD
                              Buy WrapR
                              Buy eBook
                              Buy Modelur
                              Buy Vertex Tools
                              Buy SketchCuisine
                              Buy FormFonts

                              Advertisement