Grasshopper

algorithmic modeling for Rhino

Hi,David. I Created a Shared Poperty in gh component. And a input param is set by this poperty. Now I want get a function that If I change this param, All the instance of this component  in current gh canvas changed it's Param in real-time. How can I get this effect? Thank you!

See pic below, If I change one of P param, Everyother P of this comonpent changed by same input. P is Param_Integer.

Views: 350

Reply to This

Replies to This Discussion

All other instances? Or all other instances without source parameters? Or all other instances that haven't been specifically set by the user? My main worry is that you'll start overwriting data that was specifically set by the user. Another problem is to do with adding more RegexText components to the document. How will you know what value to assign to these new parameters?

What you want can be done, but it's dangerous and difficult. Have you considered adding a completely separate component/object which sets a document-wide global value which is then used by the RegexText components? This way each RegexText component could get the data set in the P input, or if the input has no data, go looking for a Global P component in the same document.

OK, It seems a separate component is the right way.

Thank you! I will do as you suggest.

and another question. How can I Recompute all the objects?

Dim Canvas As GH_Canvas = Grasshopper.Instances.ActiveCanvas
If Canvas.IsDocument Then
If GH_Document.EnableSolutions Then
Canvas.Document.NewSolution(True)
Canvas.Refresh()
End If
End If

I use code above. It seems no uses

NewSolution(True) will expire all objects, not just the instances of the RegexText component. That code however should have worked, provided you did not call it during a solution.

Assuming this code is inside a GH_Component called RegexGlobalSettings, here's how I'd write it (warning untested pseudo code):

Protected Overrides Sub ExpireDownStreamObjects()

  MyBase.ExpireDownStreamObjects()

  Dim doc As GH_Document = OnPingDocument()

  If (doc IsNot Nothing) Then

    ForEach obj As IGH_DocumentObject in doc.Objects

      Dim component As RegexTextComponent = TryCast(obj, RegexTextComponent)

      If (component IsNot Nothing) Then

        component.ExpireSolution(False)

      End If

    Next

  End If

End Sub

This will expire (but not recompute) all instances of the RegexTextComponent in the same document as the RegexGlobalSettings component. This code will be called when the RegexGlobalSettings component expires, which happens outside of (and typically just before) a new solution will begin.

Sorry,David. I must use Recompute. Because I ceate a global var by RegexGlobalSettings, It's can be used by my other comonpents not just RegexTextComponent.Could you tell me how to released the Recompute just like in the menu? Thank you!

In that case create an interface in your project called IGlobalVariableAware and implement it in all your components that depends on it. Then the code becomes:

Protected Overrides Sub ExpireDownStreamObjects()

  MyBase.ExpireDownStreamObjects()

  Dim doc As GH_Document = OnPingDocument()

  If (doc IsNot Nothing) Then

    ForEach obj As IGH_DocumentObject in doc.Objects

      Dim active As IGH_ActiveObject = TryCast(obj, IGH_ActiveObject )

      If (active Is Nothing) Then Continue For

      Dim expiree As IGlobalVariableAware = TryCast(obj, IGlobalVariableAware)

      If (expiree Is Nothing) Then Continue For

      active.ExpireSolution(False)

    Next

  End If

End Sub

It works! Great,Thank you David.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2019   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service