Grasshopper

algorithmic modeling for Rhino

Hy Guys,

first of all "a happy new year" to the complete grasshopper community.

Now let me get to my question: I want to delete a GH_Component from the canvas. How can I do that?

Nice Greetings

Alex

Views: 5672

Replies to This Discussion

Delete it from where?

This cannot be done during a solution, but if your code runs outside of solutions then it's relatively simple; GH_Document.RemoveObject() and GH_Document.RemoveObjects()

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hi David,

thanks for your fast reply .. I want to delete GH_Components from the Canvas (ActiveCanvas). Especially I want to delete all GH_Components which are having a "Warning" ( so all which are orange ) ..

I know, that I have to iterate over all GH_Components which are on the Active Canvas, but then I don't know how to solve the search for all Components with "Warnings".

I hope somebody can help me.

Thanks a lot and nice greetings

Alex

Try this:

Dim deleteList As New List(Of IGH_DocumentObject)
For Each obj As IGH_DocumentObject In doc.Objects
  Dim actObj As IGH_ActiveObject = TryCast(obj, IGH_ActiveObject)
  If (actObj Is Nothing) Then Continue For
  If (actObj.RuntimeMessageLevel = GH_RuntimeMessageLevel.Warning) Then
    deleteList.Add(actObj)
  End If
Next
doc.RemoveObjects(deleteList, True)

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks David again for your fast reply.

Error: RemoveObjects is no Member of Rhino.RhinoDoc ??

What version Grasshopper do you have?

--

David Rutten

david@mcneel.com

Poprad, Slovakia

0.9.0014 + Rhino 5 (64Bit)

Really should be in there. I'm not exactly sure in what version this method was added but it was a long time ago. Are you writing this inside a script component or a Visual Studio project? If the latter, are you sure you're compiling against 0.9.0014 as well?

--

David Rutten

david@mcneel.com

Poprad, Slovakia

I am working inside a vb script component. I now got it working in some kind of way.

I just have the problem, that when i am removing an object the connection wires keep staying on the Canvas. Is there a way to prevent this? Or some kind of redrawing the Canvas?

In what kind of way have you got it working?

If you use RemoveObject or RemoveObjects, the objects should be automatically isolated (i.e. all wires should be disconnected). Also all recipient objects will be expires, all event handlers will be removed and the appropriate methods on the objects will be called to inform them that they have been removed from the document.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

I've done it with this:

If ghComponent.RuntimeMessageLevel = GH_RuntimeMessageLevel.Warning Then

owner.OnPingDocument().Objects.Remove(ghComponent)

End If


Now some of the connection wires keep remaining on the Canvas

Hi David,

I realize this is quite an old thread, but I am dealing with the same problem here.

I am attempting to remove components from the canvas using a Visual Studio plugin component.

Whenever I use GH_Document.RemoveObject() I get 2 kinds of warnings:

  • An object expired during a solution
  • Component is not associated with a document

Please find a simple sample script attached. I have moved my VS code into a C# script component for easy reference.

private void RemoveComponentsFromDocument()
{
GH_Document doc = GrasshopperDocument;
List<Grasshopper.Kernel.Components.GH_CleanTreeComponent> foundComponents = doc.Objects.OfType<Grasshopper.Kernel.Components.GH_CleanTreeComponent>().ToList();

foreach(Grasshopper.Kernel.Components.GH_CleanTreeComponent obj in foundComponents)
{
doc.RemoveObject(obj, false);
}
}

What am I doing wrong? And how can I fix it?

Attachments:

You cannot delete objects from the document during a solution. This code must run either before or after a solution starts or ends.

The easiest way to deal with this is to schedule a solution and provide a callback method. The attached file doesn't add undo records...

Attachments:

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service