Using RhinoInside in SolidWorks

Hi guys,

Does anybody have a starting example to use RhinoInside for SolidWorks?
Any info is appreciated.

Thanks,
Dmitriy

Can you explain what you mean?

The project is open source. So, if anyone has access to the Solidworks C# SDK, then a Rhino.Inside project could be attempted. It would be interesting to see if it worked.

1 Like

Can you explain what it is? and how to set it up?

Hi Zale_orcid, thanks for your interest.

The examples for Rhino.Inside can be found here rhino-developer-samples/rhino.inside at 7 · mcneel/rhino-developer-samples · GitHub

The Rhino.Inside® technology allows Rhino and Grasshopper to be embedded within other products. It may be possible to:

  • Starting Rhino and Grasshopper as an add in another product.
  • Call directly into the host’s native APIs from a Grasshopper or Rhino plugin.
  • Access Rhino’s APIs through the host application.
  • Grasshopper definitions can be opened and previewed in Rhino within the same process as the parent.
  • Object can be natively created by Rhino or Grasshopper within the parent product.
1 Like

Out of curiosity, has there been any progress with regards to a rhino inside solidworks workflow?
Thanks!

There have been some rumblings in Rhino.Inside.Autocad, haven’t seen or heard of any implementations for Solidworks.

Thanks Japhy. Would be a beautiful thing to see the power of Rhino inside Solidworks! Maybe one day

I’m brand new to Rhino.Inside and don’t know the ins and outs yet. I’ve only just started messing around with this. I was able to adapt the AutoCAD sample project to get Rhino to load from within SOLIDWORKS. I just started with a new template SOLIDWORKS plug-in.

I’m using SOLIDWORKS 2023, but I would imagine this would work for earlier versions as well.

Feel free to start from here and adapt as needed.

Add to SwAddin Local Variables:

		private Rhino.Runtime.InProcess.RhinoCore m_RhinoCore;
		static readonly string SystemDir = (string)Microsoft.Win32.Registry.GetValue
		(
		  @"HKEY_LOCAL_MACHINE\SOFTWARE\McNeel\Rhinoceros\7.0\Install", "Path",
		  Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles), "Rhino WIP", "System")
		);

Add to ConnectToSW:

			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"));
			};

Add to DisconnectFromSW:

			try
			{
				m_RhinoCore?.Dispose();
				m_RhinoCore = null;
			}
			catch
			{
				// ignored
			}

I just added a new button to the command manager that calls this function as it’s callback:

		public void OpenRhino()
		{
			// Load Rhino
			try
			{
				// Sceme
				string SchemeName = $"Inside-SwAddin-0.0.0.1";

				// Window handle
				IntPtr hWnd = IntPtr.Zero;
				ModelDoc2 swModelDoc = iSwApp.ActiveDoc as ModelDoc2;
				if (swModelDoc != null)
				{
					ModelView swModelView = swModelDoc.ActiveView as ModelView;
					if (swModelView != null)
                    {
						hWnd = (IntPtr)swModelView.GetViewHWndx64();
                    }
				}

				// Allocate the Rhino core
				m_RhinoCore = new Rhino.Runtime.InProcess.RhinoCore(new[] { $"/scheme={SchemeName}", "/safemode", "/nosplash" }, Rhino.Runtime.InProcess.WindowStyle.Normal, hWnd);
			}
			catch
			{
				// ignored
			}
		}

I probably added more project references than needed (this project actually started with me looking at RhinoInside.Revit). You may not need all of these, but I added references to the following DLLs from the Rhino System folder:

  • Eto
  • Eto.Wpf
  • Rhino.UI
  • RhinoCommon
  • RhinoWindows

-Luke

1 Like