sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    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

      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
      • thomthomT Offline
        thomthom
        last edited by

        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
        • thomthomT Offline
          thomthom
          last edited by

          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
          • TIGT Offline
            TIG Moderator
            last edited by

            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
            • thomthomT Offline
              thomthom
              last edited by

              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
              • TIGT Offline
                TIG Moderator
                last edited by

                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
                • thomthomT Offline
                  thomthom
                  last edited by

                  @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
                  • TIGT Offline
                    TIG Moderator
                    last edited by

                    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
                    • thomthomT Offline
                      thomthom
                      last edited by

                      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
                      • TIGT Offline
                        TIG Moderator
                        last edited by

                        Added to last post for avoidance of confusion...

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • Chris FullmerC Offline
                          Chris Fullmer
                          last edited by

                          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:

                          Index of Classes & Methods in win32ole: Ruby Standard Library Documentation (Ruby 1.9.3)

                          favicon

                          (www.ruby-doc.org)

                          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
                          • thomthomT Offline
                            thomthom
                            last edited by

                            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.

                            Link Preview Image
                            Object Linking and Embedding - Wikipedia

                            favicon

                            (en.wikipedia.org)

                            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

                              [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

                                @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
                                • First post
                                  Last post
                                Buy SketchPlus
                                Buy SUbD
                                Buy WrapR
                                Buy eBook
                                Buy Modelur
                                Buy Vertex Tools
                                Buy SketchCuisine
                                Buy FormFonts

                                Advertisement