Grasshopper

algorithmic modeling for Rhino

Deleting curves from Rhino with definition in Grasshopper?

I want to use the "Curve" parameter to select some Multiply straight lines from my Rhino window. Now, from input of those curves, I will make some Grasshopper definition.

 

What I want to know: when my Grasshopper definition ends, is there a way I can delete my straight lines from Rhino (the ones that I inputted in Grasshopper using the "Curve" parameter) using the definition from Grasshopper?

 

Thank you.

Views: 2367

Replies to This Discussion

But deleting them will cripple the Grasshopper file as it depends on those curves. Is this what you want?

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hm, you are right David.

Is there a way I could bake my definition, and then use different one (but inside the same .ghx file) to delete this lines?

Not at present, it's a bit tricky because of events. This is the basic problem: whenever an object disappears from the Rhino document, Grasshopper checks to see whether that object is referenced by any component. If it is, then that component is expired (including all objects that depends on it). Then, when Grasshopper detects that Rhino is done deleting, it will start a new solution. So if you delete objects from within a running Solution, it will expire the original curve parameter also within a solution, which is illegal. I can sort of hack around the problem by timing the deletion precisely (see attached), but it's a very fragile script.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

 

Attachments:

Its perfect David.

This is exactly what I needed - baking my definition, and then after that, deleting the lines from Rhino within the same .ghx file.

 

I owe you big time

Veľmi vám ďakujem!

This VB script you made, was working just fine on 0.8.0050

But today I opened it, in grasshopper 0.8.0066.

And the script is not working properly. And on top of that, on Vb script component there is a sign: "old".

Is there any chance you could rearrange it, so that it can be used on 0.8.0066?


Thank you.

Here is the code:

Option Strict Off
Option Explicit On

'Import SDK and Framework namespaces
Imports Rhino
Imports Rhino.Geometry
Imports Rhino.Collections

Imports Grasshopper
Imports Grasshopper.Kernel
Imports Grasshopper.Kernel.Data
Imports Grasshopper.Kernel.Types

Imports GH_IO
Imports GH_IO.Serialization

Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Linq
Imports System.Linq
Imports System.Data
Imports System.Drawing
Imports System.Reflection
Imports System.Collections
Imports System.Windows.Forms
Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Runtime.InteropServices



'Code generated by Grasshopper(R) (except for RunScript() content and Additional content)
'Copyright (C) 2012 - Robert McNeel & Associates
<System.Runtime.CompilerServices.CompilerGenerated()> _
Public Class Script_Instance
  Implements IGH_ScriptInstance

#Region "Members"
  ''' <summary>List of error messages. Do not modify this list directly.</summary>
  Private __err As New List(Of String)

  ''' <summary>List of print messages. Do not modify this list directly, use the Print() and Reflect() functions instead.</summary>
  Private __out As New List(Of String)

  ''' <summary>Represents the current Rhino document.</summary>
  Private doc As RhinoDoc = RhinoDoc.ActiveDoc

  ''' <summary>Represents the Script component which maintains this script.</summary>
  Public owner As Grasshopper.Kernel.IGH_ActiveObject
#End Region

#Region "Utility functions"
  ''' <summary>Print a String to the [Out] Parameter of the Script component.</summary>
  ''' <param name="text">String to print.</param>
  Private Sub Print(ByVal text As String)
    __out.Add(text)
  End Sub

  ''' <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 Sub Print(ByVal format As String, ByVal ParamArray args As Object())
    __out.Add(String.Format(format, args))
  End Sub

  ''' <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 Sub Reflect(ByVal obj As Object)
    __out.Add(GH_ScriptComponentUtilities.ReflectType_VB(obj))
  End Sub

  ''' <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 Sub Reflect(ByVal obj As Object, ByVal method_name As String)
    __out.Add(GH_ScriptComponentUtilities.ReflectType_VB(obj, method_name))
  End Sub
#End Region

  ''' <summary>
  ''' This procedure contains the user code. Input parameters are provided as ByVal arguments,
  ''' Output parameter are ByRef arguments. You don't have to assign output parameters,
  ''' they will be null by default.
  ''' </summary>
  Private Sub RunScript(ByVal id As Guid, ByVal deleteObjects As Boolean, ByRef A As Object)
    If (Not deleteObjects) Then Return

    m_guids.Add(id)
    If (Not m_handled) Then
      AddHandler owner.OnPingDocument().SolutionEnd, AddressOf SolutionEnd
    End If
  End Sub

  '<Custom additional code>
  Private m_guids As New List(Of Guid)
  Private m_handled As Boolean = False

  Private Sub SolutionEnd(ByVal sender As Object, ByVal e As GH_SolutionEventArgs)
    RemoveHandler e.Document.SolutionEnd, AddressOf SolutionEnd
    m_handled = False

    Dim undo As UInt32 = doc.BeginUndoRecord("Grasshopper Delete")

    For Each id As Guid In m_guids
      doc.Objects.Delete(id, True)
    Next
    m_guids.Clear()

    doc.EndUndoRecord(undo)

    e.Document.ScheduleSolution(1)
  End Sub
  '</Custom additional code>

End Class

You can upgrade the component yourself via the Solution menu:

How is it not working properly?

--

David Rutten

david@mcneel.com

Poprad, Slovakia

I am apologizing for such a late reply David.

I see now that the problem is not in your VB script, but in input of "Guid" parameter. It seems it can only have so called "Referenced curves/lines". But not regular curves/lines. Although I do not know difference between these two.

When I have simply a "Curve" parameter which takes a couple of curves from Rhino and inputs them into "Guid", then "Guid" shows no error and your component works with no problem.

But when instead of direct "Curve" parameter input, I am inputting curves through Karamba plugin, by using "Cull" component, "Guid" parameter becomes red and I am getting following error message:

Error: Data conversion failed from Curve to Guid
Warning: Floating parameter ID failed to collect data

Why does "Guid" work with "Referenced curves/lines", but does not with regular curves/lines?

Thank you.

I forgot to attach the .gh file. Here it is.
It requires the Karamba 0.9.084 plugin.

Nevertheless if you do not have it, just take a look at the part of the definition which is grouped in green block. That's the one I posted a screenshot of it in the last reply.

Attachments:

And here is the Rhino .3dm file that goes along with .gh definition.

Attachments:

Any help with this issue?

Thank you.

Hey David,

I have a definition that would be an example of where it would be beneficial to be able to do this.  It takes some curves moves their start points to the most acute angle in the curves.  When the resulting curves are baked, I have no use for the originals used for input.  Not even for the definition.  I close it and am done.

I know it breaks the idea of grasshopper, but in this case grasshopper is used more like a RhinoScript in which I would get rid of the input curves.

Thanks,

ryan

btw, this component works great David, thank you.

ryan

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service