External Access Rhino 8, Windows, Layerpanel not updating

Background Info

Currently I am updating a plug-in that ran fine with Rhino 6.
The plugin is accessed external as described here:

with further info from
https://developer.rhino3d.com/api/rhinoscript/introduction/external_access.htm

update V6-V8

(I did not manage to update the existing solution / project.) so my approach was:
I started a new Project from the Rhino Visual Studio Template, copied / added all files and renamed

  • plugin
  • new guid for the plugin
  • Com-visible-Class

it also seams that all it is important that everything is targeting the same dot-net version.

Might be that not all above steps are necessary.

Issues

Layer Panel not updating

Referring to above github sample - the following modification allows to reproduce the current error:

Use the external (console) App to call the plug-in that will add a new layer with a single line - the layerpanel does not update / not show the new layer.

Add to SampleCsRhinoObject.cs

/// <summary>
/// add a line on a new layer
/// </summary>
public bool AddLineOnNewLayer()
{
    RhinoDoc doc = RhinoDoc.ActiveDoc;
    // find name
    int i = 0;
    bool search = true;
    string layName = "not set";
    while (search)
    {
        layName = "new_" + i.ToString();
        Layer findLayer = doc.Layers.FindName(layName);
        if (findLayer != null)
        {
            i++;
        }
        else
        {
            search = false;
        }
    }
    // add layer
    int index = doc.Layers.Add(layName, System.Drawing.Color.DarkBlue);
    // make layer invisible
    doc.Layers[index].IsVisible = false;
    // add an object to the hidden layer - in the original project this was a debugging purpose
    Guid objId = doc.Objects.AddLine(new Point3d(0, 0, 0), new Point3d(111, 222, 333), new ObjectAttributes() { LayerIndex = index });
    return objId != Guid.Empty;
}

now in the console App

bool success = plugin.AddLineOnNewLayer();

if I call the same Function from a command within Rhino - everything works fine, the layer panel updates

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
    SampleCsRhinoObject pluginObj = new SampleCsRhinoObject();
    pluginObj.AddLineOnNewLayer();
    return Result.Success;
}

Rhino Background Task

a second Issue:
after debugging above solution and close Rhino, a (invisible) Background task “Rhino” stays in the taskmanager.
If I not close it / end it before the next debugging - I get some null-pointer-execeptions…

File

the following file / solution is a bit of a collage / bricolage / copy paste … and more the result of my error-search then it should be a nice, tidy sample…
cs_SampleCsAutomationV8.zip (460.6 KB)

Hi @Tom_P,

This old sample predates Rhino.Inside. This is now the preferred way to access Rhino externally.

– Dale

Dear Dale - thanks for your comment.
But I do not see the path / approach to call into a running rhino instance with rhino.inside.

do i miss something regarding rhino.inside ?

the current workflow:

a rhino file (my3dm) is open and contains RhinoCam information.
Rhinocam is posting some machine operations using my postprocessor and calling my custom console app.
the costom console app is calling back into the running rhino and is using my plugin to convert the Rhinocam output file. The conversion is adding some geometry to my3dm as debugging / feedback.

it would be great to access the initial rhinofile.
(also with the limitation of com that there only should be one rhino file / instance)

sorry but this is a workflow was successfully skipping rhinocams postprocessor-limitaions.

@dale
is there any “hello world like” sample of how to use rhino.inside console app and call the functionality of an custom installed plugin ?

thanks. - tom

Hi @Tom_P,

Call methods exposed by a plug-in via COM wouldn’t be an different in a Rhino.Inside app. Given time, I’ll work something up.

– Dale