Path mapper with variable input


Is there a possibility to modify branch names of a tree with a viriable input X (so its dynamic)?

Lets say I would like to modify the branch names, by adding a value of X (dependent of some other variable).

so lets say X=2

{0} + X --> {2}
{1} + X --> {3}
{2} + X --> {4}

thank you in advance,


You can use replacePaths: (16.9 KB)

ahh thank you!

You can also use “Path Mapper”.

PathMapper doesn’t accept dynamic variable input. however here I’ve made a little script that can change PathMapper source and target dynamically:

  private void RunScript(string source, string target)
    var pathMappers = FindPathMapperObjectInCurrentGroup();
    if(pathMappers.Count != 1)
      Component.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "This component should be added in a group with exactly one Path Mapper component.");
    pathMappers[0].Lexers.Add(new GH_LexerCombo(source, target));

  // <Custom additional code> 
  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) =>
        .Where(obj => item.ObjectIDs.Contains(obj.InstanceGuid))
      return list;
    return output;
  } (18.0 KB)
You need to add this script component in a group with the PathMapper component you want to edit.
Part of this code is inspired by scriptparasite plugin for grasshopper. by @arendvw.

1 Like