Moving objects from the document "space" to the grasshopper's

Hi all,
sorry for likely incorrect terms, but hopefully the idea will be clear to everybody.

I have a python node, in which I use rs.Command() function to execute my request to a custom plugin. The command generates a pair of curves. Then I can obtain the newly created objects in the document space by rs.LastCreatedObjects() to manipulate them as any other already existing document’s object. But what should I do with those objects to move those curves from the document’s space to the grasshopper’s? In other words, I need a kind of “reversed baking”. Thanks!

I moved this from the “Grasshopper” forum to “Grasshopper Developer” forum.

LastCreatedObjects() should return an array of identifiers.
In rhinoscript you can convert each identifier to a string with CStr(identifier) , not sure how with python…

If you send that string to grasshopper, you can feed it to a “Geometry” parameter:
2022-12-18 01_11_35-Grasshopper - unnamed

Or if you have the identifier/string inside your c# plugin, you can use it like:
RhinoObject obj = this.RhinoDocument.Objects.FindId((Guid) yourstringhere);
(here is a string casted to Guid)

1 Like

Thank you very much for the reply! Actually, it is not exactly what I mean. Sorry if my explanation is not clear. I’ve tried an approach similar to yours - just enumerated the objects received from LastCreatedObjects() and fed them to the two curve nodes. Thus, of course, I can use these curves in further nodes. But what I am looking for is rather the following: how to detach the result of the command from the document space and make it live only in grasshoper, as if it were a result of, for example, genuine grasshopper’s Line node. The rationale for that is to protect the generated curves from accident deletion or change in the Rhino’s main view. Thanks!


connect v0.1.gh (4.6 KB)

This scripts take the guid of a rhino line object and set it as persistent data to the grasshopper line parameter connected as recipient to “A”.

  private void RunScript(Guid id, ref object A)
  {
    IGH_Param IDP = (IGH_Param) this.Component.Params.Output[0].Recipients[0].Attributes.GetTopLevel.DocObject;
    if(IDP.SourceCount > 0 && id != null){
      geo = this.RhinoDocument.Objects.FindId(id).Geometry;
      if(IDP is Grasshopper.Kernel.Parameters.Param_Line){
        paramline = (Grasshopper.Kernel.Parameters.Param_Line) IDP;
        this.GrasshopperDocument.ScheduleSolution(5, Connect);
      }
    }
  }
  // <Custom additional code> 
  public Rhino.Geometry.GeometryBase geo;
  public Grasshopper.Kernel.Parameters.Param_Line paramline;
  private void Connect(GH_Document doc){
    paramline.RemoveAllSources();
    paramline.PersistentData.ClearData();
    paramline.SetPersistentData(geo);
  }

Thank you very much! The result looks pretty much like what I wanted, but I have no idea about C# =) will try to study the code and adapt it to my project