Open sketchup from Excel VBA and run ruby code
-
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?
-
2 ways.
-
After SketchUp is open, use SendKeys to execute the plugin from SketchUp's Plugins menu.
-
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.
-
-
Thanks Jim,
SendKeys does work for the interm, ENV variable looks promising, I will have to look into it. -
.
FYI, in Ruby the environment is accessed via a hash-like
object referenced by the constantENV
.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
-
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? -
@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.
Advertisement