Hi @dale,
thank you for you reply. Your code worked for me. It think it is same as I already have from GitHub but used it without success. Now I can use RhinoCommon without Rhino. Thank you again.
Unfortunately, my goal little bit harder. I would like to open, run and recompute GH from excel. Is it even possible?
I have searched this forum and GitHub for some sample. Unfortunately, again without success. I am able to create a excel Plugin (VSTO) and combine it with this code. When I run project it raise a exception that
RhinoCommon.dll cannot be found.
My code for plugin is below:
public partial class ThisAddIn
{
Rhino.Runtime.InProcess.RhinoCore m_rhino_core;
#region Plugin static constructor
static readonly string SystemDir = (string)Microsoft.Win32.Registry.GetValue
(
@"HKEY_LOCAL_MACHINE\SOFTWARE\McNeel\Rhinoceros\7.0\Install", "Path",
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Rhino 7", "System")
);
static ThisAddIn()
{
ResolveEventHandler OnRhinoCommonResolve = null;
AppDomain.CurrentDomain.AssemblyResolve += OnRhinoCommonResolve = (sender, args) =>
{
const string rhinoCommonAssemblyName = "RhinoCommon";
var assembly_name = new AssemblyName(args.Name).Name;
if (assembly_name != rhinoCommonAssemblyName)
return null;
AppDomain.CurrentDomain.AssemblyResolve -= OnRhinoCommonResolve;
return Assembly.LoadFrom(Path.Combine(SystemDir, rhinoCommonAssemblyName + ".dll"));
};
}
#endregion // Plugin static constructor
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
try
{
//TODO >> grab Excel product name for scheme
var scheme_name = "RhinoInsideExcel";
//Run Rhino.Inside no UI
m_rhino_core = new Rhino.Runtime.InProcess.RhinoCore(new[] { $"/scheme={scheme_name}" });
//TODO >> Run Rhino.Inside with UI - Error -200
//m_rhino_core = new Rhino.Runtime.InProcess.RhinoCore(new[] { $"/scheme={scheme_name}" }, WindowStyle.Maximized);
}
catch (Exception ex)
{
//System.Windows.Forms.MessageBox.Show(ex.Message);
System.Windows.Forms.MessageBox.Show("Cannot load Rhino Inside Addin");
}
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
try
{
m_rhino_core?.Dispose();
}
catch
{
// ignored
}
}
What I have discovered is that SystemDir is always null. Frankly, I am not sure if I understand code correctly but SystemDir should be a path to a Rhino itself and this line
return Assembly.LoadFrom(Path.Combine(SystemDir, rhinoCommonAssemblyName + ".dll"));
should be direction to RhinoCommon. My program fails and this line as RhinoCommon is not loaded.
m_rhino_core = new Rhino.Runtime.InProcess.RhinoCore(new[] { $"/scheme={scheme_name}" });
So my questions are follows:
- What am I doing wrong?
- Is it possible to combine Excel na Rhin/GH in the way I would like?
- How to run GH from Excel and load RhinoCommon properly?
- Is there some kind of a guide for RhinoInside/RhinoInsideExcel?
- What are differences between RhinoInside and RhinoInterface, regarding this post?
Thank you for your time and reply.
Best regards
Ondřej