diff --git a/Connectors/Rhino/Speckle.Connectors.Grasshopper8/Components/Collections/CreateCollection.cs b/Connectors/Rhino/Speckle.Connectors.Grasshopper8/Components/Collections/CreateCollection.cs index 6646d725e..e3e565b01 100644 --- a/Connectors/Rhino/Speckle.Connectors.Grasshopper8/Components/Collections/CreateCollection.cs +++ b/Connectors/Rhino/Speckle.Connectors.Grasshopper8/Components/Collections/CreateCollection.cs @@ -83,7 +83,7 @@ public class CreateCollection : GH_Component, IGH_VariableParameterComponent continue; } - childCollection["topology"] = GetParamTopology(inputParam); + childCollection["topology"] = GrasshopperHelpers.GetParamTopology(inputParam); foreach (var obj in data) { @@ -96,7 +96,7 @@ public class CreateCollection : GH_Component, IGH_VariableParameterComponent try { var geometryBase = geoGeo.GeometricGooToGeometryBase(); - var converted = ToSpeckleConversionContext.ToSpeckleConverter.Convert(geometryBase); // .Convert(geometryBase); + var converted = ToSpeckleConversionContext.ToSpeckleConverter.Convert(geometryBase); var wrapper = new SpeckleObject() { GeometryBase = geometryBase, Base = converted }; childCollection.elements.Add(wrapper); @@ -111,7 +111,7 @@ public class CreateCollection : GH_Component, IGH_VariableParameterComponent { // TODO remove copy pasta var docObject = RhinoDoc.ActiveDoc.Objects.FindId(modelObject.Id.NotNull()); - var converted = ToSpeckleConversionContext.ToSpeckleConverter.Convert(docObject.Geometry); // .Convert(docObject.Geometry); + var converted = ToSpeckleConversionContext.ToSpeckleConverter.Convert(docObject.Geometry); var wrapper = new SpeckleObject() { GeometryBase = docObject.Geometry, Base = converted }; childCollection.elements.Add(wrapper); @@ -183,14 +183,4 @@ public class CreateCollection : GH_Component, IGH_VariableParameterComponent } }; } - - public string GetParamTopology(IGH_Param param) - { - string topology = ""; - foreach (Grasshopper.Kernel.Data.GH_Path myPath in param.VolatileData.Paths) - { - topology += myPath.ToString(false) + "-" + param.VolatileData.get_Branch(myPath).Count + " "; - } - return topology; - } } diff --git a/Connectors/Rhino/Speckle.Connectors.Grasshopper8/Components/Collections/FilterObjectsByPaths.cs b/Connectors/Rhino/Speckle.Connectors.Grasshopper8/Components/Collections/FilterObjectsByPaths.cs index 876eb0cd4..251974ce3 100644 --- a/Connectors/Rhino/Speckle.Connectors.Grasshopper8/Components/Collections/FilterObjectsByPaths.cs +++ b/Connectors/Rhino/Speckle.Connectors.Grasshopper8/Components/Collections/FilterObjectsByPaths.cs @@ -6,6 +6,13 @@ using Speckle.Sdk.Models.Collections; namespace Speckle.Connectors.Grasshopper8.Components.Collections; +/// +/// Given a collection and a path, this component will output the objects in the corresponding collection. +/// Note: This component does not flatten the selected collection - if it contains sub collections those will not +/// be outputted. +/// +/// To extract those objects out, you should select that specific sub path as well. +/// public class FilterObjectsByPaths : GH_Component { public override Guid ComponentGuid => new("77CAEE94-F0B9-4611-897C-71F2A22BA311"); @@ -65,12 +72,11 @@ public class FilterObjectsByPaths : GH_Component var tree = GrasshopperHelpers.CreateDataTreeFromTopologyAndItems(topology, targetCollection.elements); dataAccess.SetDataTree(0, tree); } - // dataAccess.SetData(0, test); } private Collection FindCollection(Collection root, string unifiedPath) { - var collectionNames = unifiedPath.Split(new string[] { " :: " }, StringSplitOptions.None).Skip(1).ToList(); + var collectionNames = unifiedPath.Split([" :: "], StringSplitOptions.None).Skip(1).ToList(); Collection currentCollection = root; while (collectionNames.Count != 0) { diff --git a/Connectors/Rhino/Speckle.Connectors.Grasshopper8/HostApp/Helpers.cs b/Connectors/Rhino/Speckle.Connectors.Grasshopper8/HostApp/Helpers.cs index ea21bb254..e1911c0fd 100644 --- a/Connectors/Rhino/Speckle.Connectors.Grasshopper8/HostApp/Helpers.cs +++ b/Connectors/Rhino/Speckle.Connectors.Grasshopper8/HostApp/Helpers.cs @@ -1,4 +1,5 @@ using Grasshopper; +using Grasshopper.Kernel; using Grasshopper.Kernel.Data; using Grasshopper.Kernel.Types; using Rhino; @@ -101,6 +102,12 @@ public static class GrasshopperHelpers throw new SpeckleException("Failed to cast IGH_GeometricGoo to geometry base"); } + /// + /// Creates a tree based of a string that encodes the grasshopper topology. + /// + /// + /// + /// public static DataTree CreateDataTreeFromTopologyAndItems(string topology, System.Collections.IList subset) { var tree = new DataTree(); @@ -131,4 +138,20 @@ public static class GrasshopperHelpers return tree; } + + /// + /// Encodes a tree topology into an exhaustive string which can be used to recreate it using + /// . + /// + /// + /// + public static string GetParamTopology(IGH_Param param) + { + string topology = ""; + foreach (GH_Path myPath in param.VolatileData.Paths) + { + topology += myPath.ToString(false) + "-" + param.VolatileData.get_Branch(myPath).Count + " "; + } + return topology; + } }