I actually want to know how to write this part in ghpython.
“
private List<GH_PathMapper> FindPathMapperObjectInCurrentGroup()
{
var groups = GrasshopperDocument.Objects.OfType<GH_Group>().Where(gr => gr.ObjectIDs.Contains(Component.InstanceGuid)).ToList();
var output = groups.Aggregate(new List<GH_PathMapper>(), (list, item) =>
{
list.AddRange(
GrasshopperDocument.Objects.OfType<GH_PathMapper>()
.Where(obj => item.ObjectIDs.Contains(obj.InstanceGuid))
);
return list;
}).Distinct().ToList();
return output;
”
import Grasshopper as gh
def findPathMapperObjectInCurrentGroup():
output = []
objs = ghenv.Component.OnPingDocument().Objects
for group in objs:
if isinstance(group, gh.Kernel.Special.GH_Group) and group.ObjectIDs.Contains(ghenv.Component.InstanceGuid):
for pathMapper in objs:
if isinstance(pathMapper, gh.Kernel.Special.GH_PathMapper) and group.ObjectIDs.Contains(pathMapper.InstanceGuid):
output.append(pathMapper)
return output
pathMappers = findPathMapperObjectInCurrentGroup();
if len(pathMappers) != 1:
ghenv.Component.AddRuntimeMessage(gh.Kernel.GH_RuntimeMessageLevel.Warning, 'This component should be added in a group with exactly one Path Mapper component.')
else:
pathMappers[0].Lexers.Clear()
pathMappers[0].Lexers.Add(gh.Kernel.Data.GH_LexerCombo(source, target))
pathMappers[0].ExpireSolution(True)
I replied in another topic regarding the static nature of Path Mapper with a component that acts somewhat like a dynamic Path Mapper but with slightly fewer bells and whistles. It uses only Grasshopper native components and no scripts, and makes use of the * wildcard to dynamically handle changing path depths. This can be relevant when using ShapeDiver, as scripts are checked before being allowed.
The * wildcard is basically useful whenever the exact depth of the tree is not known/can change, but it is known where the branch depths of interest are relative to the start or end of the depth (can’t really get around that, as the paths have to stay unambiguous).
P.S. It’s not too slow, but the main bottleneck lies in the “Replace Paths” component that it uses. If someone knows a faster way to place items from one branch onto another, I’m keen to find out!
Sure. You can match by path index. Does Shape Diver support Path Compare? Most of your time is lost in the lexigraphical sorting and merge attempts of Replace Paths
I believe Path Compare doesn’t help in placing items on novel branch paths? When swapping from {a;b} to {b;a}, the original tree may not have already contained {b;a}, so Path Mapper and the Dynamic Path Swapper I sent construct novel paths. I don’t see how Path Compare would prevent the need for Replace Paths, unless I’m missing something?