Shared Poperty in My gh component - Grasshopper2024-03-29T10:45:54Zhttps://www.grasshopper3d.com/forum/topics/shared-poperty-in-my-gh-component?commentId=2985220%3AComment%3A1292231&feed=yes&xn_auth=noIt works! Great,Thank you Dav…tag:www.grasshopper3d.com,2015-05-23:2985220:Comment:12924062015-05-23T12:27:08.679Zhuaxiamengqinghttps://www.grasshopper3d.com/profile/huaxiamengqing
<p>It works! Great,Thank you David.</p>
<p>It works! Great,Thank you David.</p> In that case create an interf…tag:www.grasshopper3d.com,2015-05-23:2985220:Comment:12926682015-05-23T10:19:03.897ZDavid Ruttenhttps://www.grasshopper3d.com/profile/DavidRutten
<p>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:</p>
<p></p>
<p>Protected Overrides Sub ExpireDownStreamObjects()</p>
<p> MyBase.ExpireDownStreamObjects()</p>
<p></p>
<p> Dim doc As GH_Document = OnPingDocument()</p>
<p> If (doc IsNot Nothing) Then</p>
<p> ForEach obj As IGH_DocumentObject in doc.Objects</p>
<p> Dim active As IGH_ActiveObject = TryCast(obj,…</p>
<p>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:</p>
<p></p>
<p>Protected Overrides Sub ExpireDownStreamObjects()</p>
<p> MyBase.ExpireDownStreamObjects()</p>
<p></p>
<p> Dim doc As GH_Document = OnPingDocument()</p>
<p> If (doc IsNot Nothing) Then</p>
<p> ForEach obj As IGH_DocumentObject in doc.Objects</p>
<p> Dim active As IGH_ActiveObject = TryCast(obj, IGH_ActiveObject )</p>
<p> If (active Is Nothing) Then Continue For</p>
<p> Dim expiree As IGlobalVariableAware = TryCast(obj, IGlobalVariableAware)</p>
<p> If (expiree Is Nothing) Then Continue For</p>
<p> active.ExpireSolution(False)</p>
<p> Next</p>
<p> End If</p>
<p>End Sub</p> Sorry,David. I must use Recom…tag:www.grasshopper3d.com,2015-05-23:2985220:Comment:12926452015-05-23T00:24:11.208Zhuaxiamengqinghttps://www.grasshopper3d.com/profile/huaxiamengqing
<p>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!</p>
<p>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!</p> NewSolution(True) will expire…tag:www.grasshopper3d.com,2015-05-22:2985220:Comment:12925172015-05-22T18:07:41.673ZDavid Ruttenhttps://www.grasshopper3d.com/profile/DavidRutten
<p>NewSolution(True) will expire <strong>all</strong> objects, not just the instances of the RegexText component. That code however should have worked, provided you did not call it during a solution.</p>
<p></p>
<p>Assuming this code is inside a GH_Component called RegexGlobalSettings, here's how I'd write it (warning untested pseudo code):</p>
<p></p>
<p>Protected Overrides Sub ExpireDownStreamObjects()</p>
<p> MyBase.ExpireDownStreamObjects()</p>
<p></p>
<p> Dim doc As GH_Document =…</p>
<p>NewSolution(True) will expire <strong>all</strong> objects, not just the instances of the RegexText component. That code however should have worked, provided you did not call it during a solution.</p>
<p></p>
<p>Assuming this code is inside a GH_Component called RegexGlobalSettings, here's how I'd write it (warning untested pseudo code):</p>
<p></p>
<p>Protected Overrides Sub ExpireDownStreamObjects()</p>
<p> MyBase.ExpireDownStreamObjects()</p>
<p></p>
<p> Dim doc As GH_Document = OnPingDocument()</p>
<p> If (doc IsNot Nothing) Then</p>
<p> ForEach obj As IGH_DocumentObject in doc.Objects</p>
<p> Dim component As RegexTextComponent = TryCast(obj, RegexTextComponent)</p>
<p> If (component IsNot Nothing) Then</p>
<p> component.ExpireSolution(False)</p>
<p> End If</p>
<p> Next</p>
<p> End If</p>
<p>End Sub</p>
<p></p>
<p>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.</p> Dim Canvas As GH_Canvas = Gra…tag:www.grasshopper3d.com,2015-05-22:2985220:Comment:12920032015-05-22T13:06:25.147Zhuaxiamengqinghttps://www.grasshopper3d.com/profile/huaxiamengqing
<p>Dim Canvas As GH_Canvas = Grasshopper.Instances.ActiveCanvas<br/> If Canvas.IsDocument Then<br/> If GH_Document.EnableSolutions Then<br/> Canvas.Document.NewSolution(True)<br/> Canvas.Refresh()<br/> End If<br/> End If</p>
<p>I use code above. It seems no uses</p>
<p></p>
<p>Dim Canvas As GH_Canvas = Grasshopper.Instances.ActiveCanvas<br/> If Canvas.IsDocument Then<br/> If GH_Document.EnableSolutions Then<br/> Canvas.Document.NewSolution(True)<br/> Canvas.Refresh()<br/> End If<br/> End If</p>
<p>I use code above. It seems no uses</p>
<p></p> and another question. How can…tag:www.grasshopper3d.com,2015-05-22:2985220:Comment:12920782015-05-22T12:28:41.526Zhuaxiamengqinghttps://www.grasshopper3d.com/profile/huaxiamengqing
<p>and another question. How can I Recompute all the objects?</p>
<p>and another question. How can I Recompute all the objects?</p> OK, It seems a separate compo…tag:www.grasshopper3d.com,2015-05-22:2985220:Comment:12922442015-05-22T11:35:40.934Zhuaxiamengqinghttps://www.grasshopper3d.com/profile/huaxiamengqing
<p>OK, It seems a separate component is the right way.</p>
<p>Thank you! I will do as you suggest.</p>
<p>OK, It seems a separate component is the right way.</p>
<p>Thank you! I will do as you suggest.</p> All other instances? Or all o…tag:www.grasshopper3d.com,2015-05-22:2985220:Comment:12922312015-05-22T10:46:58.665ZDavid Ruttenhttps://www.grasshopper3d.com/profile/DavidRutten
<p>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?</p>
<p></p>
<p>What you want can be done, but it's dangerous and difficult. Have you considered adding a completely…</p>
<p>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?</p>
<p></p>
<p>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.</p>
<p></p>
<p></p>