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)