Getting output from each iteration of the loop in c# - Grasshopper2024-03-29T06:26:34Zhttps://www.grasshopper3d.com/forum/topics/getting-output-from-each-iteration-of-the-loop-in-c?commentId=2985220%3AComment%3A1668449&feed=yes&xn_auth=noIf you want to draw every sin…tag:www.grasshopper3d.com,2017-01-08:2985220:Comment:16684552017-01-08T14:04:25.249ZVicente Solerhttps://www.grasshopper3d.com/profile/VicenteSoler
<p>If you want to draw every single iteration you can put the Component.ExpireSolution(true) line inside the for loop.</p>
<p>If you want to draw every single iteration you can put the Component.ExpireSolution(true) line inside the for loop.</p> A hybrid approach could be to…tag:www.grasshopper3d.com,2017-01-08:2985220:Comment:16684492017-01-08T13:34:35.984ZVicente Solerhttps://www.grasshopper3d.com/profile/VicenteSoler
<p>A hybrid approach could be to run your simulation asynchronously in another thread and have it constantly update a field in the scripting component. Parallel to this, expire the scripting component in regular intervals or whenever it can and have it output the value of this field.</p>
<p></p>
<p>I am not sure of all the performance and synchronisation implications of having a thread constantly writing a field and another constantly reading it. There are compiler optimizations that can make…</p>
<p>A hybrid approach could be to run your simulation asynchronously in another thread and have it constantly update a field in the scripting component. Parallel to this, expire the scripting component in regular intervals or whenever it can and have it output the value of this field.</p>
<p></p>
<p>I am not sure of all the performance and synchronisation implications of having a thread constantly writing a field and another constantly reading it. There are compiler optimizations that can make the local cache of each core have different values (but gh scripting components have these disabled) and probably other unintended consequences i'm not aware about.</p>
<p></p>
<p>But the following works:</p>
<p></p>
<p>private void RunScript(object x, object y, ref object A)<br/> {<br/> if (task == null || task.IsCompleted)<br/> {<br/> task = System.Threading.Tasks.Task.Run(() => Animation());<br/> }</p>
<p>Component.ExpireSolution(true);</p>
<p>A = point;<br/> }</p>
<p>// <Custom additional code> <br/> System.Threading.Tasks.Task task = null;<br/> Point3d point;</p>
<p><br/> void Animation()<br/> {<br/> for(int i = 0;i < 1000;i++)<br/> {<br/> point = new Point3d(i, 0, 0);<br/> System.Threading.Thread.Sleep(1);<br/> }<br/> }<br/> // </Custom additional code> <br/>}</p>
<p></p>
<p>You could also use a timer component to update, rather the Component.Expiresolution.</p>
HI!You can do like this way.tag:www.grasshopper3d.com,2016-12-29:2985220:Comment:16637812016-12-29T03:16:16.529Z0ddw589ypu3jvhttps://www.grasshopper3d.com/xn/detail/u_0ddw589ypu3jv
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2769228291?profile=original" target="_self"><img width="721" class="align-full" src="http://storage.ning.com/topology/rest/1.0/file/get/2769228291?profile=RESIZE_1024x1024"/></a></p>
<p>HI!You can do like this way.</p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2769228291?profile=original" target="_self"><img width="721" class="align-full" src="http://storage.ning.com/topology/rest/1.0/file/get/2769228291?profile=RESIZE_1024x1024"/></a></p>
<p>HI!You can do like this way.</p> This can be tricky. I don't k…tag:www.grasshopper3d.com,2016-12-28:2985220:Comment:16634492016-12-28T11:26:14.586ZDavid Ruttenhttps://www.grasshopper3d.com/profile/DavidRutten
<p>This can be tricky. I don't know exactly how Daniel solves it, but there's two main approaches you can take:</p>
<ol>
<li>Don't loop internally, keep completing solutions for every iteration. This way Grasshopper draws your previews for you. You will of course have to trigger new solutions at the end of each (or every Nth) iteration.</li>
<li>Keep looping internally, but draw your intermediate solutions yourself. This may be problematic for two reasons. One, if you start redrawing the Rhino…</li>
</ol>
<p>This can be tricky. I don't know exactly how Daniel solves it, but there's two main approaches you can take:</p>
<ol>
<li>Don't loop internally, keep completing solutions for every iteration. This way Grasshopper draws your previews for you. You will of course have to trigger new solutions at the end of each (or every Nth) iteration.</li>
<li>Keep looping internally, but draw your intermediate solutions yourself. This may be problematic for two reasons. One, if you start redrawing the Rhino viewports in the middle of a GH solution, the rest of the Grasshopper preview may go missing. Two, I'm not even sure it is reliably possible to redraw Rhino viewports from within a tight loop. It may be that all you can do is trigger a redraw in the future, which won't actually happen until Rhino feels the time is right.</li>
</ol>