Frozen GH Canvas while importing STL with Pancake

Hi Everyone,
I am working on a small GH file which should be able to switch between the paths of different .STL files to finally load the selected file. The basic idea is the following: a c# component has multiple buttons and a list of .STL paths as inputs. When pressing one of the buttons, a corresponding file path is passed by the c# component. The filepath should not disappear when the button is released until another button is pressed. This is implemented through an internal static variable in the c# component. The output filepath of the c# component is then used to import the geometry using a pancake component Import From (pcImportFrom). This process would allow me to give a preselection of .stl files in a larger project while only loading the geometry that is actually selected.
The switching between the filepaths works fine. However, the GH canvas somehow freezes and the all boxes within GH become uneditable. Any suggestions why this happens would be highly appreciated.

Code within C# component:

using System;
using System.Collections;
using System.Collections.Generic;

using Rhino;
using Rhino.Geometry;

using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;

using System.Linq;
using Rhino.DocObjects;

/// <summary>
/// This class will be instantiated on demand by the Script component.
/// </summary>
public class Script_Instance : GH_ScriptInstance
{
#region Utility functions
  /// <summary>Print a String to the [Out] Parameter of the Script component.</summary>
  /// <param name="text">String to print.</param>
  private void Print(string text) { /* Implementation hidden. */ }
  /// <summary>Print a formatted String to the [Out] Parameter of the Script component.</summary>
  /// <param name="format">String format.</param>
  /// <param name="args">Formatting parameters.</param>
  private void Print(string format, params object[] args) { /* Implementation hidden. */ }
  /// <summary>Print useful information about an object instance to the [Out] Parameter of the Script component. </summary>
  /// <param name="obj">Object instance to parse.</param>
  private void Reflect(object obj) { /* Implementation hidden. */ }
  /// <summary>Print the signatures of all the overloads of a specific method to the [Out] Parameter of the Script component. </summary>
  /// <param name="obj">Object instance to parse.</param>
  private void Reflect(object obj, string method_name) { /* Implementation hidden. */ }
#endregion

#region Members
  /// <summary>Gets the current Rhino document.</summary>
  private readonly RhinoDoc RhinoDocument;
  /// <summary>Gets the Grasshopper document that owns this script.</summary>
  private readonly GH_Document GrasshopperDocument;
  /// <summary>Gets the Grasshopper script component that owns this script.</summary>
  private readonly IGH_Component Component;
  /// <summary>
  /// Gets the current iteration count. The first call to RunScript() is associated with Iteration==0.
  /// Any subsequent call within the same solution will increment the Iteration count.
  /// </summary>
  private readonly int Iteration;
#endregion

  /// <summary>
  /// This procedure contains the user code. Input parameters are provided as regular arguments,
  /// Output parameters as ref arguments. You don't have to assign output parameters,
  /// they will have a default value.
  /// </summary>
  private void RunScript(List<string> file, bool importSphere, bool importSquare, ref object filePath, ref object tempPath)
  {
    if(importSphere){
      fileDirectory = file[0];
      tempPath = file[0];
    }
    else if(importSquare){
      fileDirectory = file[1];
      tempPath = file[1];
    }
    filePath = fileDirectory;
  }

  // <Custom additional code> 
  static string fileDirectory = "";
  // </Custom additional code> 
}


sphere.stl (787.6 KB)
square.stl (684 Bytes)
example_frozenGHcanvas.gh (8.1 KB)

Welcome to the community @Patrick19 !
I don’t know how to fix your problem because I am not a programmer. But I can give you a work around.
I made a file sort to be able to grab parts from a large directory of files. while still allowing the directory to grow. maybe you could modify it to fit your needs
File Sort.gh (14.2 KB)

1 Like

Try True-only button from Pancake because Pancake’s import involves in-Rhino command manipulation and has side effects if something interacts with Grasshopper during the procedure.