diff --git a/GH/CsGH/CsGH.csproj b/GH/CsGH/CsGH.csproj new file mode 100644 index 0000000..4c8a7ea --- /dev/null +++ b/GH/CsGH/CsGH.csproj @@ -0,0 +1,15 @@ + + + + net48 + 1.0 + CsGH + Description of CsGH + .gha + + + + + + + \ No newline at end of file diff --git a/GH/CsGH/CsGHComponent.cs b/GH/CsGH/CsGHComponent.cs new file mode 100644 index 0000000..fafaba9 --- /dev/null +++ b/GH/CsGH/CsGHComponent.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; + +using Grasshopper; +using Grasshopper.Kernel; +using Rhino.Geometry; + +namespace CsGH +{ + public class CsGHComponent : GH_Component + { + /// + /// Each implementation of GH_Component must provide a public + /// constructor without any arguments. + /// Category represents the Tab in which the component will appear, + /// Subcategory the panel. If you use non-existing tab or panel names, + /// new tabs/panels will automatically be created. + /// + public CsGHComponent() + : base("CsGH Component", "Nickname", + "Description of component", + "Category", "Subcategory") + { + } + + /// + /// Registers all the input parameters for this component. + /// + protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) + { + } + + /// + /// Registers all the output parameters for this component. + /// + protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) + { + } + + /// + /// This is the method that actually does the work. + /// + /// The DA object can be used to retrieve data from input parameters and + /// to store data in output parameters. + protected override void SolveInstance(IGH_DataAccess DA) + { + } + + /// + /// Provides an Icon for every component that will be visible in the User Interface. + /// Icons need to be 24x24 pixels. + /// You can add image files to your project resources and access them like this: + /// return Resources.IconForThisComponent; + /// + protected override System.Drawing.Bitmap Icon => null; + + /// + /// Each component must have a unique Guid to identify it. + /// It is vital this Guid doesn't change otherwise old ghx files + /// that use the old ID will partially fail during loading. + /// + public override Guid ComponentGuid => new Guid("57815B6C-58D2-42BE-84D7-6EA495D6A5B1"); + } +} \ No newline at end of file diff --git a/GH/CsGH/CsGHInfo.cs b/GH/CsGH/CsGHInfo.cs new file mode 100644 index 0000000..5e45b44 --- /dev/null +++ b/GH/CsGH/CsGHInfo.cs @@ -0,0 +1,26 @@ +using System; +using System.Drawing; +using Grasshopper; +using Grasshopper.Kernel; + +namespace CsGH +{ + public class CsGHInfo : GH_AssemblyInfo + { + public override string Name => "CsGH Info"; + + //Return a 24x24 pixel bitmap to represent this GHA library. + public override Bitmap Icon => null; + + //Return a short string describing the purpose of this GHA library. + public override string Description => ""; + + public override Guid Id => new Guid("8FDABF86-6067-4496-977B-E17C6341F89E"); + + //Return a string identifying you or your company. + public override string AuthorName => ""; + + //Return a string representing your preferred contact details. + public override string AuthorContact => ""; + } +} \ No newline at end of file diff --git a/GH/CsGH/Properties/launchSettings.json b/GH/CsGH/Properties/launchSettings.json new file mode 100644 index 0000000..a4f5b31 --- /dev/null +++ b/GH/CsGH/Properties/launchSettings.json @@ -0,0 +1,9 @@ +{ + "profiles": { + "CsGH": { + "commandName": "Executable", + "executablePath": "C:\\Program Files\\Rhino 7\\System\\Rhino.exe", + "commandLineArgs": "" + } + } +} \ No newline at end of file diff --git a/GH/CsGH/bin/Debug/net48/CsGH.gha b/GH/CsGH/bin/Debug/net48/CsGH.gha new file mode 100644 index 0000000..ff3c055 Binary files /dev/null and b/GH/CsGH/bin/Debug/net48/CsGH.gha differ diff --git a/GH/CsGH/bin/Debug/net48/CsGH.pdb b/GH/CsGH/bin/Debug/net48/CsGH.pdb new file mode 100644 index 0000000..3d8f912 Binary files /dev/null and b/GH/CsGH/bin/Debug/net48/CsGH.pdb differ diff --git a/GH/CsGH/obj/CsGH.csproj.nuget.dgspec.json b/GH/CsGH/obj/CsGH.csproj.nuget.dgspec.json new file mode 100644 index 0000000..74fb8f1 --- /dev/null +++ b/GH/CsGH/obj/CsGH.csproj.nuget.dgspec.json @@ -0,0 +1,59 @@ +{ + "format": 1, + "restore": { + "F:\\script-sync\\GH\\CsGH\\CsGH.csproj": {} + }, + "projects": { + "F:\\script-sync\\GH\\CsGH\\CsGH.csproj": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "F:\\script-sync\\GH\\CsGH\\CsGH.csproj", + "projectName": "CsGH", + "projectPath": "F:\\script-sync\\GH\\CsGH\\CsGH.csproj", + "packagesPath": "C:\\Users\\andre\\.nuget\\packages\\", + "outputPath": "F:\\script-sync\\GH\\CsGH\\obj\\", + "projectStyle": "PackageReference", + "crossTargeting": true, + "fallbackFolders": [ + "C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages" + ], + "configFilePaths": [ + "C:\\Users\\andre\\AppData\\Roaming\\NuGet\\NuGet.Config", + "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config", + "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" + ], + "originalTargetFrameworks": [ + "net48" + ], + "sources": { + "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, + "https://api.nuget.org/v3/index.json": {} + }, + "frameworks": { + "net48": { + "targetAlias": "net48", + "projectReferences": {} + } + }, + "warningProperties": { + "warnAsError": [ + "NU1605" + ] + } + }, + "frameworks": { + "net48": { + "targetAlias": "net48", + "dependencies": { + "Grasshopper": { + "include": "Compile, Build", + "target": "Package", + "version": "[8.0.23164.14305-wip, )" + } + }, + "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.408\\RuntimeIdentifierGraph.json" + } + } + } + } +} \ No newline at end of file diff --git a/GH/CsGH/obj/CsGH.csproj.nuget.g.props b/GH/CsGH/obj/CsGH.csproj.nuget.g.props new file mode 100644 index 0000000..abd2a55 --- /dev/null +++ b/GH/CsGH/obj/CsGH.csproj.nuget.g.props @@ -0,0 +1,19 @@ + + + + True + NuGet + $(MSBuildThisFileDirectory)project.assets.json + $(UserProfile)\.nuget\packages\ + C:\Users\andre\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages + PackageReference + 5.11.1 + + + + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + + \ No newline at end of file diff --git a/GH/CsGH/obj/CsGH.csproj.nuget.g.targets b/GH/CsGH/obj/CsGH.csproj.nuget.g.targets new file mode 100644 index 0000000..032b0f2 --- /dev/null +++ b/GH/CsGH/obj/CsGH.csproj.nuget.g.targets @@ -0,0 +1,10 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + + + + + + \ No newline at end of file diff --git a/GH/CsGH/obj/Debug/net48/.NETFramework,Version=v4.8.AssemblyAttributes.cs b/GH/CsGH/obj/Debug/net48/.NETFramework,Version=v4.8.AssemblyAttributes.cs new file mode 100644 index 0000000..15efebf --- /dev/null +++ b/GH/CsGH/obj/Debug/net48/.NETFramework,Version=v4.8.AssemblyAttributes.cs @@ -0,0 +1,4 @@ +// +using System; +using System.Reflection; +[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] diff --git a/GH/CsGH/obj/Debug/net48/CsGH.AssemblyInfo.cs b/GH/CsGH/obj/Debug/net48/CsGH.AssemblyInfo.cs new file mode 100644 index 0000000..996d6e7 --- /dev/null +++ b/GH/CsGH/obj/Debug/net48/CsGH.AssemblyInfo.cs @@ -0,0 +1,23 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +using System; +using System.Reflection; + +[assembly: System.Reflection.AssemblyCompanyAttribute("CsGH")] +[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] +[assembly: System.Reflection.AssemblyDescriptionAttribute("Description of CsGH")] +[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0")] +[assembly: System.Reflection.AssemblyProductAttribute("CsGH")] +[assembly: System.Reflection.AssemblyTitleAttribute("CsGH")] +[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] + +// Generated by the MSBuild WriteCodeFragment class. + diff --git a/GH/CsGH/obj/Debug/net48/CsGH.AssemblyInfoInputs.cache b/GH/CsGH/obj/Debug/net48/CsGH.AssemblyInfoInputs.cache new file mode 100644 index 0000000..3a1da4d --- /dev/null +++ b/GH/CsGH/obj/Debug/net48/CsGH.AssemblyInfoInputs.cache @@ -0,0 +1 @@ +8cbbdd594077555e06bb3b9285b5118f2966b3f2 diff --git a/GH/CsGH/obj/Debug/net48/CsGH.GeneratedMSBuildEditorConfig.editorconfig b/GH/CsGH/obj/Debug/net48/CsGH.GeneratedMSBuildEditorConfig.editorconfig new file mode 100644 index 0000000..412059e --- /dev/null +++ b/GH/CsGH/obj/Debug/net48/CsGH.GeneratedMSBuildEditorConfig.editorconfig @@ -0,0 +1,3 @@ +is_global = true +build_property.RootNamespace = CsGH +build_property.ProjectDir = F:\script-sync\GH\CsGH\ diff --git a/GH/CsGH/obj/Debug/net48/CsGH.assets.cache b/GH/CsGH/obj/Debug/net48/CsGH.assets.cache new file mode 100644 index 0000000..05102e8 Binary files /dev/null and b/GH/CsGH/obj/Debug/net48/CsGH.assets.cache differ diff --git a/GH/CsGH/obj/Debug/net48/CsGH.csproj.AssemblyReference.cache b/GH/CsGH/obj/Debug/net48/CsGH.csproj.AssemblyReference.cache new file mode 100644 index 0000000..d0d7c65 Binary files /dev/null and b/GH/CsGH/obj/Debug/net48/CsGH.csproj.AssemblyReference.cache differ diff --git a/GH/CsGH/obj/Debug/net48/CsGH.csproj.CoreCompileInputs.cache b/GH/CsGH/obj/Debug/net48/CsGH.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..fd23335 --- /dev/null +++ b/GH/CsGH/obj/Debug/net48/CsGH.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +29b94e183ca448bfcd87af0796c4391fd9685fb0 diff --git a/GH/CsGH/obj/Debug/net48/CsGH.csproj.FileListAbsolute.txt b/GH/CsGH/obj/Debug/net48/CsGH.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..29be766 --- /dev/null +++ b/GH/CsGH/obj/Debug/net48/CsGH.csproj.FileListAbsolute.txt @@ -0,0 +1,9 @@ +F:\script-sync\GH\CsGH\bin\Debug\net48\CsGH.gha +F:\script-sync\GH\CsGH\bin\Debug\net48\CsGH.pdb +F:\script-sync\GH\CsGH\obj\Debug\net48\CsGH.csproj.AssemblyReference.cache +F:\script-sync\GH\CsGH\obj\Debug\net48\CsGH.GeneratedMSBuildEditorConfig.editorconfig +F:\script-sync\GH\CsGH\obj\Debug\net48\CsGH.AssemblyInfoInputs.cache +F:\script-sync\GH\CsGH\obj\Debug\net48\CsGH.AssemblyInfo.cs +F:\script-sync\GH\CsGH\obj\Debug\net48\CsGH.csproj.CoreCompileInputs.cache +F:\script-sync\GH\CsGH\obj\Debug\net48\CsGH.gha +F:\script-sync\GH\CsGH\obj\Debug\net48\CsGH.pdb diff --git a/GH/CsGH/obj/Debug/net48/CsGH.gha b/GH/CsGH/obj/Debug/net48/CsGH.gha new file mode 100644 index 0000000..ff3c055 Binary files /dev/null and b/GH/CsGH/obj/Debug/net48/CsGH.gha differ diff --git a/GH/CsGH/obj/Debug/net48/CsGH.pdb b/GH/CsGH/obj/Debug/net48/CsGH.pdb new file mode 100644 index 0000000..3d8f912 Binary files /dev/null and b/GH/CsGH/obj/Debug/net48/CsGH.pdb differ diff --git a/GH/CsGH/obj/project.assets.json b/GH/CsGH/obj/project.assets.json new file mode 100644 index 0000000..1ef5ca7 --- /dev/null +++ b/GH/CsGH/obj/project.assets.json @@ -0,0 +1,138 @@ +{ + "version": 3, + "targets": { + ".NETFramework,Version=v4.8": { + "Grasshopper/8.0.23164.14305-wip": { + "type": "package", + "dependencies": { + "RhinoCommon": "[8.0.23164.14305-wip]" + }, + "compile": { + "lib/net48/GH_IO.dll": {}, + "lib/net48/Grasshopper.dll": {} + }, + "runtime": { + "lib/net48/_._": {} + }, + "build": { + "build/net48/Grasshopper.targets": {} + } + }, + "RhinoCommon/8.0.23164.14305-wip": { + "type": "package", + "compile": { + "lib/net48/Ed.Eto.dll": {}, + "lib/net48/Eto.dll": {}, + "lib/net48/Rhino.UI.dll": {}, + "lib/net48/RhinoCommon.dll": {} + }, + "runtime": { + "lib/net48/_._": {} + }, + "build": { + "build/net48/RhinoCommon.targets": {} + } + } + } + }, + "libraries": { + "Grasshopper/8.0.23164.14305-wip": { + "sha512": "hzHby/AFHT2jnlsA+gKr7exeFuy/xS8oRU1c8zY4GxmYXRGcIqyOAmeVm2e3pvqkcerCp7KYGMHfw4ukpuOaOA==", + "type": "package", + "path": "grasshopper/8.0.23164.14305-wip", + "files": [ + ".nupkg.metadata", + ".signature.p7s", + "build/net48/Grasshopper.targets", + "grasshopper.8.0.23164.14305-wip.nupkg.sha512", + "grasshopper.nuspec", + "grasshopper.png", + "lib/net48/GH_IO.dll", + "lib/net48/GH_IO.xml", + "lib/net48/Grasshopper.dll", + "lib/net48/Grasshopper.xml" + ] + }, + "RhinoCommon/8.0.23164.14305-wip": { + "sha512": "kTIWpk+jOG6TmNIn/usy3cX9hyAOT3DITL8CFe6QgpCU7H19c0S3Lm/jAHh0xUJb+WdigsgBgQUeloBwHNc+/g==", + "type": "package", + "path": "rhinocommon/8.0.23164.14305-wip", + "files": [ + ".nupkg.metadata", + ".signature.p7s", + "Eto-LICENSE.txt", + "build/net48/RhinoCommon.targets", + "lib/net48/Ed.Eto.dll", + "lib/net48/Ed.Eto.xml", + "lib/net48/Eto.dll", + "lib/net48/Eto.xml", + "lib/net48/Rhino.UI.dll", + "lib/net48/RhinoCommon.dll", + "lib/net48/RhinoCommon.xml", + "rhinocommon.8.0.23164.14305-wip.nupkg.sha512", + "rhinocommon.nuspec", + "rhinocommon.png" + ] + } + }, + "projectFileDependencyGroups": { + ".NETFramework,Version=v4.8": [ + "Grasshopper >= 8.0.23164.14305-wip" + ] + }, + "packageFolders": { + "C:\\Users\\andre\\.nuget\\packages\\": {}, + "C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {} + }, + "project": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "F:\\script-sync\\GH\\CsGH\\CsGH.csproj", + "projectName": "CsGH", + "projectPath": "F:\\script-sync\\GH\\CsGH\\CsGH.csproj", + "packagesPath": "C:\\Users\\andre\\.nuget\\packages\\", + "outputPath": "F:\\script-sync\\GH\\CsGH\\obj\\", + "projectStyle": "PackageReference", + "crossTargeting": true, + "fallbackFolders": [ + "C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages" + ], + "configFilePaths": [ + "C:\\Users\\andre\\AppData\\Roaming\\NuGet\\NuGet.Config", + "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config", + "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" + ], + "originalTargetFrameworks": [ + "net48" + ], + "sources": { + "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, + "https://api.nuget.org/v3/index.json": {} + }, + "frameworks": { + "net48": { + "targetAlias": "net48", + "projectReferences": {} + } + }, + "warningProperties": { + "warnAsError": [ + "NU1605" + ] + } + }, + "frameworks": { + "net48": { + "targetAlias": "net48", + "dependencies": { + "Grasshopper": { + "include": "Compile, Build", + "target": "Package", + "version": "[8.0.23164.14305-wip, )" + } + }, + "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.408\\RuntimeIdentifierGraph.json" + } + } + } +} \ No newline at end of file diff --git a/GH/CsGH/obj/project.nuget.cache b/GH/CsGH/obj/project.nuget.cache new file mode 100644 index 0000000..95c75a2 --- /dev/null +++ b/GH/CsGH/obj/project.nuget.cache @@ -0,0 +1,11 @@ +{ + "version": 2, + "dgSpecHash": "YysQEqrSBDoSgLrjrvnusf6yyCS6W8Dl1PqWizXcJDL678ay7hpOzvKmKZFcviv2GM4Yj3sZx9PDJZjV0Ax0pg==", + "success": true, + "projectFilePath": "F:\\script-sync\\GH\\CsGH\\CsGH.csproj", + "expectedPackageFiles": [ + "C:\\Users\\andre\\.nuget\\packages\\grasshopper\\8.0.23164.14305-wip\\grasshopper.8.0.23164.14305-wip.nupkg.sha512", + "C:\\Users\\andre\\.nuget\\packages\\rhinocommon\\8.0.23164.14305-wip\\rhinocommon.8.0.23164.14305-wip.nupkg.sha512" + ], + "logs": [] +} \ No newline at end of file diff --git a/GH/PyGH/components/scriptsynccpy/code.py b/GH/PyGH/components/scriptsynccpy/code.py index f88f216..f05cfa3 100644 --- a/GH/PyGH/components/scriptsynccpy/code.py +++ b/GH/PyGH/components/scriptsynccpy/code.py @@ -1,10 +1,5 @@ import System import System.Drawing -import Rhino -import rhinoscriptsyntax as rs -import Grasshopper -import Grasshopper as gh -from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML import sys import os import time @@ -25,6 +20,14 @@ import traceback +import Rhino +import rhinoscriptsyntax as rs +import Grasshopper +import Grasshopper as gh +from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML +import ghpythonlib.treehelpers as th + + def add_button(self, nickname: str, indx: int, @@ -401,7 +404,6 @@ def safe_exec(self, path, globals, locals, package_2_reload): return locals except Exception as e: - # sys.stdout = sys.__stdout__ # Get the traceback tb = traceback.format_exc() @@ -478,6 +480,18 @@ def AfterRunScript(self): its calculation. It is used to load the GHComponent outputs with the values created in the script. """ + def _is_first_lvl_nested_iterable(lst : typing.List) -> bool: + """ + Detect if the first level of a list is nested. + e.g. + [1, 2, 3, 4, [5,6]] --> return value: False + [[1, 2], [3, 4]] --> return value: True + + :param lst: The list to check + :return: True if the first level is nested, False otherwise + """ + return all(isinstance(item, list) for item in lst) + def _nesting_level(container: typing.Union[typing.List, typing.Tuple]) -> int: """ Get the level of nesting of a list or tuple. """ if isinstance(container, (list, tuple)): @@ -485,10 +499,66 @@ def _nesting_level(container: typing.Union[typing.List, typing.Tuple]) -> int: else: return 0 - def _is_nested_iterable( lst): - """ Detect if a list is nested. """ - return any(isinstance(i, list) for i in lst) - + def _force_nesting_list(lst : typing.List) -> list: + """ + Transform a list with nested lists into a list of lists. + + Example: + >>> list_C = [ + 1, 2, 3, 4, # {0;0} + [5, 6], # {1;0} + [7, 8] # {2;0} + ] + >>> _force_nesting_list(list_C) + [[1, 2, 3, 4], [5, 6], [7, 8]] + + :param lst: The list to transform + :return: The transformed list + """ + transformed_list = [] + sublist = [] + + for item in lst: + if isinstance(item, list): + if sublist: + transformed_list.append(sublist) + sublist = [] + transformed_list.append(item) + else: + sublist.append(item) + if sublist: + transformed_list.append(sublist) + + return transformed_list + + def _get_list_shape(lst : typing.List) -> tuple: + """ + Get the shape of a list of lists. + + Example: + >>> list_A = [ + [ + [1, 2], # {0;0} + [3, 4] # {0;1} + ], + [ + [5, 6], # {1;0} + [7, 8] # {1;1} + ] + ] + >>> _get_list_shape(list_A) + (2, 2, 2) + + :param lst: The list to get the shape of + :return: The shape of the list + """ + if isinstance(lst, list): + if len(lst) == 0: + return (0,) + return (len(lst),) + _get_list_shape(lst[0]) + else: + return () + if not self.is_success: return @@ -496,36 +566,69 @@ def _is_nested_iterable( lst): outparam_names = [p.NickName for p in outparam] for idx, outp in enumerate(outparam): - # case: nested lists + # case 1: nested lists if type(self._var_output[idx]) == tuple or type(self._var_output[idx]) == list: - ghenv.Component.Params.Output[idx].VolatileData.Clear() - if _nesting_level(self._var_output[idx]) == 1: - ghenv.Component.Params.Output[idx].AddVolatileDataList(gh.Kernel.Data.GH_Path(0), self._var_output[idx]) - elif _nesting_level(self._var_output[idx]) == 2: - nbr_tuples_aka_branches = len(self._var_output[idx]) - for i in range(nbr_tuples_aka_branches): - ghenv.Component.Params.Output[idx].AddVolatileDataList(gh.Kernel.Data.GH_Path(i), self._var_output[idx][i]) - elif _nesting_level(self._var_output[idx]) > 2: - nbr_tuples_aka_branches = len(self._var_output[idx]) - for i in range(nbr_tuples_aka_branches): - for j in range(len(self._var_output[idx][i])): - ghenv.Component.Params.Output[idx].AddVolatileDataList(gh.Kernel.Data.GH_Path(i, j), self._var_output[idx][i][j]) + self._var_output[idx] = th.list_to_tree(self._var_output[idx]) + + + # ghenv.Component.Params.Output[idx].VolatileData.Clear() + + # list_nest_lvl = _nesting_level(self._var_output[idx]) + + # # case *: force the nesting of the list if it is nested but also with single elements on the first level (e.g. [1, 2, [3, 4]] --> [[1, 2], [3, 4]]) + # if list_nest_lvl >= 2 and _is_first_lvl_nested_iterable(self._var_output[idx]) is False: + # self._var_output[idx] = _force_nesting_list(self._var_output[idx]) + + # # case 1.A: <<< DESCRIPTION >>> + # if list_nest_lvl == 1: + # ghenv.Component.Params.Output[idx].AddVolatileDataList(gh.Kernel.Data.GH_Path(0), self._var_output[idx]) + # # case 1.B: <<< DESCRIPTION >>> + # elif list_nest_lvl == 2: + # nbr_tuples_aka_branches = len(self._var_output[idx]) + # for i in range(nbr_tuples_aka_branches): + # ghenv.Component.Params.Output[idx].AddVolatileDataList(gh.Kernel.Data.GH_Path(i), self._var_output[idx][i]) + # # case 1.C: <<< DESCRIPTION >>> + # elif list_nest_lvl > 2: + + + # # TODO: to be solved + # # >>>>>>>>>>>>>>>>>>>>>>>>> + # list_shape = _get_list_shape(self._var_output[idx]) + # # Create a recursive function to add the volatile data + + + # def add_volatile_data_recursive(output_param, data, path): + # if isinstance(data, list): + # for i, item in enumerate(data): + # new_path = gh.Kernel.Data.GH_Path(path) + # new_path = new_path.AppendElement(i) + # add_volatile_data_recursive(output_param, item, new_path) + # else: + # output_param.AddVolatileData(path, 0, data) # Use index 0 for leaf nodes + + # # Example usage within your existing code + # nbr_tuples_aka_branches = len(self._var_output[idx]) + # for i in range(nbr_tuples_aka_branches): + # path = gh.Kernel.Data.GH_Path(i) + # add_volatile_data_recursive(ghenv.Component.Params.Output[idx], self._var_output[idx][i], path) + # # <<<<<<<<<<<<<<<<<<<<<<<<< + # else: + # case 2: single values + ghenv.Component.Params.Output[idx].VolatileData.Clear() + # case 2.A: the user is returning a Grasshopper.DataTree[System.Object] via the utility ghpythonlib.treehelpers + # e.g.: list_tree = th.list_to_tree(list_A) + # this will be conserve the structure + if type(self._var_output[idx]) == Grasshopper.DataTree[System.Object]: + # self._var_output[idx].SimplifyPaths() + branch_count = self._var_output[idx].BranchCount + for i in range(branch_count): + path = self._var_output[idx].Paths[i] + data = self._var_output[idx].Branch(path) + ghenv.Component.Params.Output[idx].AddVolatileDataList(path, data) + # case 2.B: simple single value else: - ghenv.Component.Params.Output[idx].VolatileData.Clear() - # case: the user is returning a Grasshopper.DataTree[System.Object] via the utility ghpythonlib.treehelpers - # e.g.: list_tree = th.list_to_tree(list_A) - # this will be conserve the structure - if type(self._var_output[idx]) == Grasshopper.DataTree[System.Object]: - self._var_output[idx].SimplifyPaths() - branch_count = self._var_output[idx].BranchCount - for i in range(branch_count): - path = self._var_output[idx].Paths[i] - print(path) - data = self._var_output[idx].Branch(path) - ghenv.Component.Params.Output[idx].AddVolatileDataList(path, data) - # case: simple single value - else: - ghenv.Component.Params.Output[idx].AddVolatileData(gh.Kernel.Data.GH_Path(0), 0, self._var_output[idx]) + ghenv.Component.Params.Output[idx].AddVolatileData(gh.Kernel.Data.GH_Path(0), 0, self._var_output[idx]) + self._var_output.clear() @property