Delete Rhino Objects via GUID

How can I delete a referenced Rhino object via GUID?

There are no standard components for modifying anything in Rhino. You’ll need to write a small script for it. Set the input type hint to Guid, and in the C# area write something like:

RhinoDocument.Objects.Delete(id);

I’m doing this from memory on an iPad, code is probably not 100% correct.

2 Likes

I can’t make it work.
What I want to do is to make a C component that can delete a referenced object via the press of a button.

I have found a code that can replace the referenced geometry with new one from grasshopper. I need to somehow modify it just to delete the original referenced geometry and nothing else.

private void RunScript(List Referenced_geo_to_be_replaced, List New_geo, bool DO_IT)
{
// Setting inputs to private lists, to make them accessible in the private function
id = Referenced_geo_to_be_replaced;
geo = New_geo;
// Calling an external function
// because otherwise deleting referenced object will expire it AND this c# component while working, during solution, and give an error, illegal stuff…
if(DO_IT){
GrasshopperDocument.ScheduleSolution(5, SolutionCallback);
}
}

//
private List id;
private List geo;
private Rhino.DocObjects.ObjectAttributes attr;
// Deleting old geometry and placing new geometry with duplicated attributes
private void SolutionCallback(GH_Document doc){
int i = 0;
foreach (GeometryBase g in geo){
attr = RhinoDocument.Objects.FindId(id[i]).Attributes.Duplicate();
this.RhinoDocument.Objects.Delete(id[i], false);
this.RhinoDocument.Objects.Add(g, attr);
i++;
}
return;
}

delete and replace.gh (3.6 KB)

Ha! You were totally right.

DeleteObject.gh (3.7 KB)

1 Like

it is not working! Is there a solution to modify this code?
and hi @Michael_Pryor
@Mahdiyar
Do you have a solution for this?

private void RunScript(DataTree<Guid> guids, bool delete)
{
  ids = guids.AllData();
  if(delete)
    GrasshopperDocument.ScheduleSolution(5, SolutionCallback);
}
// <Custom additional code> 
List<Guid> ids;
void SolutionCallback(GH_Document doc)
{
  RhinoDocument.Objects.Delete(ids, true);
}
// </Custom additional code> 

DeleteObjects.gh (2.8 KB)

3 Likes

thank you👍

thanks again! May Python Code Write how ?؟
@Mahdiyar

import Rhino
def callback(doc):
    Rhino.RhinoDoc.ActiveDoc.Objects.Delete(guids.AllData(), True)
if delete:
    doc = ghenv.Component.OnPingDocument()
    doc.ScheduleSolution(5, callback)

DeleteObjects.gh (5.4 KB)

3 Likes