I am writing to ask if it is possible to use Ladybug and Honeybee functions in a C# scripting component or in Visual Studio under Grasshopper template?
If yes, is there any source to learn how to do that?
You can use them in python components if you use the new libraries. The legacy plugin is not developed as a library so you have to copy-paste the code or load them from ladybug_ladybug component which is not very elegant. Here is the link to the new WIP libraries:
@mostapha@MingboPeng I would like to bring some Ladybug/Honeybee functionalities (for example HB weekly schedule) into a custom C# component.
What is the best solution?
Using IronBug?
Calling the Ladybug or Honeybee component from the C# component.
Wrapping the python code of the component as you mentioned above in the discussion?
I think @MingboPeng might have some ideas about this. I know that he calls some of the libraries loaded in IronPython using C# in the Pollination Rhino Plugin.
Hi @MingboPeng
Internally we have some custom components which work in combination with LBT.
For example, one component collects data from BCA - Building Control Act
that are fed into the Weekly Schedule HB component.
So the idea is to bring the functionality of the LBT component into the custom component so I can get immediately the output I need, without the need of using 2 nodes all the time.
I just created an example for you to create a new schedule in C# and convert it to python object that you can output to downstream LBT components.
(I havenât tested it, but you get the ideas)
public static List<object> ToPythonObjs()
{
// create C# model
var model = new HoneybeeSchema.Model("SomeID", HoneybeeSchema.ModelProperties.Default);
var newScheduleDay = new HoneybeeSchema.ScheduleDay("MyScheduleDay", new List<double> { 1 });
var newSchedule = new HoneybeeSchema.ScheduleRuleset("MyScheduleID", new List<HoneybeeSchema.ScheduleDay> { newScheduleDay }, "MyScheduleDay");
model.Properties.Energy.Schedules.Add(newSchedule);
//Or
//model.AddSchedules(new List<HoneybeeSchema.ScheduleRuleset> { newSchedule });
// set up Python runtime
var pyRun = Rhino.Runtime.PythonScript.Create();
// convert the model to json sting and set to "_hb_str" in python
pyRun.SetVariable("_hb_str", model.ToJson());
string pyScript =
$@"
import honeybee.dictutil as hb_dict_util
from honeybee.model import Model
import json
hb_dict = json.loads(_hb_str)
model = hb_dict_util.dict_to_object(hb_dict, False)
objects = model.properties.energy.schedules;
";
// execute python script
pyRun.ExecuteScript(pyScript);
// get output objects
var objs = pyRun.GetVariable("objects");
var pyObjs = (objs as IList<object>)?.ToList();
return pyObjs;
}
Thanks @MingboPeng
I assume the HoneybeeShema is come from here?
And the âfrom honeybee.model import Modelâ from here
Ok, you are using the Rhino runtime. Did you try pythonnet?
Is ladybug-grasshopper-dotnet the way of calling LB nodes? I donât see schemas for it.
Thanks @MingboPeng
Iâll try the solution, and see how it works, as well as the use of pythonnet.
It will be interesting to bring the node-in-code capability to LB nodes.
Hey @MingboPeng
LBT.Newtonsoft.Json clashes with Newtonsoft.Json.Rhino.dll funny enough I can use Newtonsoft.Json but the compiler raises the error that doesnât know which one has to use, but I canât associate one.