Windows Forms on GH and Rhino 8

Hi All,

on Rhino8 for the MAC how do we access winforms? Meaning that all the UI extension for grasshopper are tided to winform and in .net 7 winforms are not available on the mac. Is there something I am missing? E.g. the following code will not build on the mac (C#)

public override bool AppendMenuItems(ToolStripDropDown menu)
{
  var output = base.AppendMenuItems(menu);

   Menu_AppendSeparator(menu);
   Menu_AppendItem(menu, textItem, (s, e) => { RhinoApp.WriteLine("Does not build"); });
}

is there a package on nuget that we can reference or any suggestion you have?

Thanks a lot.
Alberto

1 Like

The best suggestion I can give is to rewrite against Eto.Forms, which is used by Rhino itself, in both Rhino 7 and Rhino 8.

But this is in grasshopper, can you rewrite this for me?

GH_DocumentObject.Menu_AppendItem Method

Is there an API that uses Eto that I am not aware of?

Alberto

I have the same question.

1 Like

@Alberto The ToolStripDropDown is a System.Windows.Forms type. On macOS try adding System.Windows.Forms in the Rhino 8 folder to your project. Do not include that with your plugin distribution as it is already shipped with Rhino

@curtisw Is there a NuGet package to use for macOS Grasshopper plugin builds that need access to ToolStripDropDown and other similar types?

same here :wink:

Thanks @eirannejad whatever works :wink:

Where can I can find the assembly? I looked into the Rhino8 package but cannot find it

Should I grab it from some other location?

Thanks a lot,
Alberto

Rhino 8.app/Contents/Frameworks/RhCore.framework/Versions/Current/Resources/

I tried to add the reference like this:

        <Reference Include="System.Windows.Forms">
          <HintPath>/Applications/Rhino 8.app/Contents/Frameworks/RhCore.framework/Versions/Current/Resources/System.Windows.Forms.dll</HintPath>
        </Reference>

If I do that, I get a weird unrelated error when building:

$  dotnet build --configuration MyConfig --framework net7.0-macos  MySolution.sln
MSBuild version 17.7.3+4fca21998 for .NET
  Determining projects to restore...
  Determining projects to restore...
/usr/local/share/dotnet/sdk/7.0.403/NuGet.targets(158,5): error : Invalid framework identifier ''. [...]

Anyone running into the same problem?

Currently this is blocking us from providing a Mac-compatible version of the ShapeDiver plugin for Rhino 8.

I am not sure that .csproj allows unix-style paths. I copied the dll into my project folder and that make it work.

1 Like

How did you specify the reference to the dll in your csproj file?

@Alberto I could solve it, many thanks for your hint regarding the UNIX path.

Note for others: Using the same approach for System.Drawing.Common.dll included with Rhino 8 for Mac works fine.
Related thread: System.Drawing.Common not compatible with macOS anymore

@curtisw would it be possible to include the mac-specific versions of System.Windows.Forms.dll and System.Drawing.Common.dll in the RhinoCommon nuget package (for the macos platform) ?

Yes we can add that, currently the only way to get access to System.Windows.Forms is to target net48. As for System.Drawing.Common it’s already a nuget package which you can reference (but don’t include the .dll as part of your plugin). I’ve created RH-80655 to get that included.

Thanks for bringing it to our attention!

Cheers,
Curtis.

Just as an update, I’ve found this works for referencing System.Windows.Forms and System.Drawing.Common from non-windows targets:

  <ItemGroup Condition="$(TargetFramework) == 'net7.0-macos'">
    <PackageReference Include="System.Drawing.Common" Version="7.0.0" ExcludeAssets="runtime" />
    <PackageReference Include="Microsoft.WindowsDesktop.App.Ref" GeneratePathProperty="true" Version="7.0.0" ExcludeAssets="all" />
    <Reference Include="$(PkgMicrosoft_WindowsDesktop_App_Ref)\ref\net7.0\System.Windows.Forms.dll" />
  </ItemGroup>
1 Like