How does Read File watch for changes? - Grasshopper2024-03-28T13:40:53Zhttps://www.grasshopper3d.com/forum/topics/how-does-read-file-watch-for-changes?commentId=2985220%3AComment%3A849505&feed=yes&xn_auth=noAwesome! I cant believe I hav…tag:www.grasshopper3d.com,2013-05-10:2985220:Comment:8495052013-05-10T04:51:30.525ZRyan Gathmannhttps://www.grasshopper3d.com/profile/RyanGathmann
<p>Awesome! I cant believe I have gotten this far! Ok, so I am pretty sure that I have done the whole delegate thing correctly. Is ExpireSolution(true) the best way to force it to resolve? As you can see, the solution is very simple, but randomly as the file is changing, this script will freeze up Grasshopper and Rhino. How can I debug something like that?</p>
<p></p>
<p>Also, is there a better way to post code of these forums? Just as plain text seems sloppy to me.</p>
<p></p>
<p>Thanks for…</p>
<p>Awesome! I cant believe I have gotten this far! Ok, so I am pretty sure that I have done the whole delegate thing correctly. Is ExpireSolution(true) the best way to force it to resolve? As you can see, the solution is very simple, but randomly as the file is changing, this script will freeze up Grasshopper and Rhino. How can I debug something like that?</p>
<p></p>
<p>Also, is there a better way to post code of these forums? Just as plain text seems sloppy to me.</p>
<p></p>
<p>Thanks for all your help! This is starting to make sense now!</p>
<p></p>
<p></p>
<p>/// <summary><br/> /// Expire the solution when ever the file has changed.<br/> /// </summary></p>
<p>public void FileHasChanged(GH_FileWatcher sender, string filename, WatcherChangeTypes change)<br/> {<br/> ExpireSolution(true);<br/> }</p>
<p>/// <summary><br/> /// This is the method that actually does the work.<br/> /// </summary><br/> /// <param name="DA">The DA object can be used to retrieve data from input parameters and <br/> /// to store data in output parameters.</param><br/> <br/> protected override void SolveInstance(IGH_DataAccess DA)<br/> {<br/> // First, we need to retrieve all data from the input parameters.<br/> // We'll start by declaring variables and assigning them starting values.<br/> string json_path = "";<br/> // Then we need to access the input parameters individually. <br/> // When data cannot be extracted from a parameter, we should abort this method.<br/> if (!DA.GetData(0, ref json_path)) return;</p>
<p>if (json_path.Length < 0)<br/> {<br/> AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "You need to assign a filepath"); <br/> }</p>
<p>// Instantiate the delegate as FileHasChanged<br/> GH_FileWatcher.FileChanged fChanged = new GH_FileWatcher.FileChanged(FileHasChanged);</p>
<p>// Invoke the delegate<br/> GH_FileWatcher watcher = GH_FileWatcher.CreateFileWatcher(json_path, GH_FileWatcherEvents.Changed, fChanged);</p>
<p>watcher.Active = true;</p>
<p>string json_string = System.IO.File.ReadAllText(json_path);</p>
<p>var json_list = JsonConvert.DeserializeObject<List<SliderObject>>(json_string);</p>
<p>string output = json_string;</p>
<p>DA.SetData(0, output);<br/> for (int i = 1; i < this.Params.Output.Count; i++)<br/> {<br/> string NickName = this.Params.Output[i].NickName;<br/> // Rhino.RhinoApp.WriteLine("Nickname: {0}", NickName);<br/> int value;<br/> for (int j = 0; j < json_list.Count; j++)<br/> {<br/> if (json_list[j].name == NickName)<br/> {<br/> Rhino.RhinoApp.WriteLine("Match found!");<br/> value = json_list[j].value;<br/> DA.SetData(i, value);<br/> }<br/> else<br/> {<br/> Rhino.RhinoApp.WriteLine("{0} doesn't match", json_list[j].name);<br/> }<br/> }<br/> }</p>
<p><br/> }</p> I just uploaded a new version…tag:www.grasshopper3d.com,2013-05-09:2985220:Comment:8489482013-05-09T11:06:40.333ZDavid Ruttenhttps://www.grasshopper3d.com/profile/DavidRutten
<p>I just uploaded a new version of the SDK docs. Download again to get the correct docs for 0.9.0052</p>
<p></p>
<p>--</p>
<p>David Rutten</p>
<p>david@mcneel.com</p>
<p>Poprad, Slovakia</p>
<p>I just uploaded a new version of the SDK docs. Download again to get the correct docs for 0.9.0052</p>
<p></p>
<p>--</p>
<p>David Rutten</p>
<p>david@mcneel.com</p>
<p>Poprad, Slovakia</p> I cant seem to find any docum…tag:www.grasshopper3d.com,2013-05-09:2985220:Comment:8486812013-05-09T05:14:30.625ZRyan Gathmannhttps://www.grasshopper3d.com/profile/RyanGathmann
<p>I cant seem to find any documentation on the GH_Filewatcher wrapper class in the SDK. Am i just missing it?</p>
<p></p>
<p>Thanks David!</p>
<p>I cant seem to find any documentation on the GH_Filewatcher wrapper class in the SDK. Am i just missing it?</p>
<p></p>
<p>Thanks David!</p> I guess you will never belong…tag:www.grasshopper3d.com,2013-05-02:2985220:Comment:8430142013-05-02T14:04:59.135ZRyan Gathmannhttps://www.grasshopper3d.com/profile/RyanGathmann
<p>I guess you will never belong to the house of Slytherin.....</p>
<p>I guess you will never belong to the house of Slytherin.....</p> ...I still don't speak Python…tag:www.grasshopper3d.com,2013-05-02:2985220:Comment:8428352013-05-02T10:08:51.886ZDanny Boyeshttps://www.grasshopper3d.com/profile/DannyBoyes
<blockquote><p>...<span>I still don't speak Python.</span></p>
</blockquote>
<p></p>
<p>You have in the <a href="http://www.grasshopper3d.com/forum/topics/the-messiah-has-spoken?commentId=2985220%3AComment%3A383258" target="_blank">past</a></p>
<p>:)</p>
<blockquote><p>...<span>I still don't speak Python.</span></p>
</blockquote>
<p></p>
<p>You have in the <a href="http://www.grasshopper3d.com/forum/topics/the-messiah-has-spoken?commentId=2985220%3AComment%3A383258" target="_blank">past</a></p>
<p>:)</p> You probably can. I cannot as…tag:www.grasshopper3d.com,2013-05-02:2985220:Comment:8427652013-05-02T10:06:12.987ZDavid Ruttenhttps://www.grasshopper3d.com/profile/DavidRutten
<p>You probably can. I cannot as I still don't speak Python.</p>
<p></p>
<p>--</p>
<p>David Rutten</p>
<p>david@mcneel.com</p>
<p>Poprad, Slovakia</p>
<p>You probably can. I cannot as I still don't speak Python.</p>
<p></p>
<p>--</p>
<p>David Rutten</p>
<p>david@mcneel.com</p>
<p>Poprad, Slovakia</p> Why would you not be abl to d…tag:www.grasshopper3d.com,2013-05-02:2985220:Comment:8425682013-05-02T06:32:55.100ZLuis Fraguadahttps://www.grasshopper3d.com/profile/LuisFraguada
<p>Why would you not be abl to do this with a python component? I have not tried this myself, but it should be possible without a timer. I found a few links that might help:</p>
<p><a href="https://gist.github.com/vsajip/1675730" target="_blank">https://gist.github.com/vsajip/1675730</a></p>
<p><a href="http://www.ironpython.info/index.php/Watching_the_FileSystem" target="_blank">http://www.ironpython.info/index.php/Watching_the_FileSystem</a> (not sure why the thread goes to sleep for an…</p>
<p>Why would you not be abl to do this with a python component? I have not tried this myself, but it should be possible without a timer. I found a few links that might help:</p>
<p><a href="https://gist.github.com/vsajip/1675730" target="_blank">https://gist.github.com/vsajip/1675730</a></p>
<p><a href="http://www.ironpython.info/index.php/Watching_the_FileSystem" target="_blank">http://www.ironpython.info/index.php/Watching_the_FileSystem</a> (not sure why the thread goes to sleep for an hour)</p>
<p><a href="http://devwiki.beloblotskiy.com/index.php5/IronPython_Tutorial:_Advanced_%28Events,_Delegates,_WinForms,_WPF%29" target="_blank">http://devwiki.beloblotskiy.com/index.php5/IronPython_Tutorial:_Advanced_%28Events,_Delegates,_WinForms,_WPF%29</a></p>
<p></p>
<p>My assumption is that you should be able to define events in the c#, vb.net, and python components without using a timer to update them. Then again, like I said, I have not tried any of the samples above.</p> Grasshopper typically updates…tag:www.grasshopper3d.com,2013-05-01:2985220:Comment:8420632013-05-01T22:14:46.164ZDavid Ruttenhttps://www.grasshopper3d.com/profile/DavidRutten
<p>Grasshopper typically updates in the wake of events, not timers. I indeed use the filesystemwatcher but I've written a wrapper class for it so it's easier to use (I think). Grasshopper.Kernel.GH_FileWatcher.</p>
<p></p>
<p>Also the next release will have a synchronization option on the File Path parameter which will cause it to recompute whenever the target files change:…</p>
<p></p>
<p></p>
<p>Grasshopper typically updates in the wake of events, not timers. I indeed use the filesystemwatcher but I've written a wrapper class for it so it's easier to use (I think). Grasshopper.Kernel.GH_FileWatcher.</p>
<p></p>
<p>Also the next release will have a synchronization option on the File Path parameter which will cause it to recompute whenever the target files change:</p>
<p></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2768813683?profile=original" target="_self"><img src="http://storage.ning.com/topology/rest/1.0/file/get/2768813683?profile=original" width="718" class="align-center"/></a></p>
<p></p>
<p>--</p>
<p>David Rutten</p>
<p>david@mcneel.com</p>
<p>Poprad, Slovakia</p> That was my hunch. I guess th…tag:www.grasshopper3d.com,2013-05-01:2985220:Comment:8421302013-05-01T22:04:40.410ZRyan Gathmannhttps://www.grasshopper3d.com/profile/RyanGathmann
<p>That was my hunch. I guess that custom components can be much more powerful than python components. It was my understanding that python components are only updated by a timer or when an input changes. It seems like there is way more you can do with a custom component.</p>
<p>That was my hunch. I guess that custom components can be much more powerful than python components. It was my understanding that python components are only updated by a timer or when an input changes. It seems like there is way more you can do with a custom component.</p> http://msdn.microsoft.com/en-…tag:www.grasshopper3d.com,2013-05-01:2985220:Comment:8421272013-05-01T22:01:05.524ZLuis Fraguadahttps://www.grasshopper3d.com/profile/LuisFraguada
<p><a href="http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.changed.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.changed.aspx</a></p>
<p></p>
<p>Maybe that?</p>
<p><a href="http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.changed.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.changed.aspx</a></p>
<p></p>
<p>Maybe that?</p>