I am working on a grasshopper plugin that will make use of the JSON data format as well as some yaml files. The yaml files will store property values similar to the way CSS stores properties in html. The json data will help better organize object data in nested hierarchies over the current flat user attribute values.
It would be great to allow users to edit those files right in grasshopper rather than having to open up visual studio or other IDE. Is there an easy way to extend the scripting language support of the scripting component so that it provides the necessary highlighting and intelligence? I suppose this would involve created a new grasshopper scripting component for JSON and yaml using the code for the existing python / c# as a base.
Unlike the c# scripts, I would not want these files to run the script, I just want to utilize the script editor separately as a text editor.
Yeah this is a great idea. I made the ticket below for it. I need to create JSON and YAML ‘Parameters’ that can be edited using the script editor, since it does not make sense for them to have input and output properties and execute like a script component.
RH-85929 Json/Yaml Text Parameter with Script Editor for editing
My original question was really if it is possible for us to extend the code editor or does this have to be done on mcneel’s end? I suppose this is part of the core application and not something we can build off of or have access to when we work on a plugin?
I’m not sure if yaml or xml has a strong use case. . . I would image JSON would be a great addition since this is a fairly common data type and with rhino compute Grasshopper really needs better support for JSON. There are a couple of tools to work with JSON, swiftlet and JSwan but really a code editor is the best way to do this. You end up stringing together a bunch of widgets just to do something that would take a single line of code.
If you build out a JSON code editor then do you load Newtonsoft.json? It could be a simple text editor but if you want to manipulate the json data, serialize deserialize what do you use since .Net does not have great built in options. (I was not able to load Newtonsoft via nuget in the new editor FYI)
Personally we are working on using xml and yaml to create a human readable code that describes the structure and style for BIM objects similar to what html and css does for the web. Later those will be encapsulated into dynamic components similar to vue or react. XML describes the structure, the yml file the styling, and javascript can describe the logic. I’m trying to use grasshopper’s infrastructure, ability to create and solve graphs, as much as possible before we build out more infrastructure.
That is why I made the ticket. So potentially we can add a text parameter to GH1 that you can double click and edit the JSON or YAML data using the new editor since it does provide syntax highlighting and linting.
This is what I gathered from your request. Let me know if there is a misunderstanding.
As for Newtonsoft.Json, Rhino is shipped with that so you do not need the NuGet package.
As for the script editor, from what I understand is that it already has built in support for JSON, yaml and XML?
I’ll have to try it and see if I could write JSON or xml or yaml in the C# component and get all the linting and highlighting.
If the highlighting works I guess a quick work around would be to just use it as an editor and then put a return statement at the end so that it outputs just the text file?
Not sure why I didn’t think about that. I assumed that the C# component only worked with C#.
Well the C# component only works with C#. But if you want to write a script that returns JSON string then you can do that with any language, assuming JSON data will be embedded in the script. You will not get highlighting on the JSON string however.