sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Open sketchup from Excel VBA and run ruby code

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 2.2k Views 3 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.
    • D Offline
      davesexcel
      last edited by

      I found this code from google groups it opens sketchup from Excel.

      
      
      Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
      Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
      Sub fLaunchProgram(ByVal sProgram As String)
          Dim ProcessHandle As Long
          Dim ProcessId As Long
          On Error GoTo errExit
          ProcessId = Shell(sProgram, vbNormalFocus)
          ProcessHandle = OpenProcess(&H1F0000, 0, ProcessId)
          WaitForSingleObject ProcessHandle, INFINITE
          Exit Sub
      
      errExit;
          MsgBox "External program " & sProgram & " was not found", vbCritical, " fLaunchProgram"
      End Sub
      'To load SU
      Sub pTest()
          fLaunchProgram ("C;\Program Files\SketchUp\SketchUp 2015\SketchUp.exe")
      End Sub
      
      

      I have assigned the macro to a button, using sendkeys seems to take care of the splash screen when Sketchup opens.

      
      Sub Button1_Click()
          pTest
          SendKeys "~ (tilde)"
          
          'Shell ("C;\Users\dmorrison\AppData\Roaming\SketchUp\SketchUp 2015\SketchUp\Plugins\GetFromExcel.rb")
      
      End Sub
      
      

      How can I run a plugin from sketchup with vba?

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        2 ways.

        1. After SketchUp is open, use SendKeys to execute the plugin from SketchUp's Plugins menu.

        2. Set an ENV variable from the VBA in Excel before starting SketchUp, then have a permenant SketchUp plugin that only runs when it sees the ENV variable. It will run automatically everytime SketchUp starts, but only do its work when the ENV var is set.

        Hi

        1 Reply Last reply Reply Quote 0
        • D Offline
          davesexcel
          last edited by

          Thanks Jim,
          SendKeys does work for the interm, ENV variable looks promising, I will have to look into it.

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            .
            FYI, in Ruby the environment is accessed via a hash-like
            object referenced by the constant ENV.

            Ref: http://ruby-doc.org/core-2.2.4/doc/globals_rdoc.html

            Example in Ruby:
            user = ENV["USERNAME"] || ENV["User"]

            (The implication is that the names of the variables differ from Windows to Mac OSX. But the keys are case insensitive, so any of: "User", "USER" or "user" will access the value.)

            If you wish to examine the hash at the console, use the prettyprint method (it should already be loaded.)
            pp ENV

            If you get an error, just call:
            require "pp"
            and try again.


            VBS

            WshEnvironment Object

            [https://msdn.microsoft.com/en-us/library/6s7w15a0(v=vs.84).aspx](https://msdn.microsoft.com/en-us/library/6s7w15a0(v)


            VBA Office

            Environ function

            https://msdn.microsoft.com/en-us/library/office/gg264486.aspx

            πŸ€“

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • D Offline
              davesexcel
              last edited by

              Thanks,
              I think I understand the concept, from excel vba we are opening sketchup and passing on a variable that a plugin will recognize to run the plugin?

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                @davesexcel said:

                Thanks,
                I think I understand the concept, from excel vba we are opening sketchup and passing on a variable that a plugin will recognize to run the plugin?

                I think Jim explained it better and more detailed.

                I'm not here much anymore.

                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