Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
How do I get which group the bar belongs to via API?
Please, if possible, a code in C#
Solved! Go to Solution.
How do I get which group the bar belongs to via API?
Please, if possible, a code in C#
Solved! Go to Solution.
you should read these topics
(API) Retrieve Nodes of a group from exsisting group and then extracting the results
Note:
Here is an extension method that allows you to parse a Robot entity list string into a distinct, ordered array of integers (offline).
internal static class CollectionExtensions {
static readonly string To = "to", By = "By";
private static IEnumerable<int> AsSequence(this string entityLst) {
foreach (string entity in entityLst.Split([' '], RemoveEmptyEntries)) {
string[] byParts = entity.Split([By], None),
toParts = byParts[0].Split([To], None);
int start = int.Parse(toParts[0]),
end = toParts.Length > 1 ? int.Parse(toParts[1]) : start,
step = byParts.Length > 1 ? int.Parse(byParts[1]) : 1;
if (start > 0 && end > 0 && step > 0) for (int i = start; i <= end; i += step) yield return i;
}
}
public static int[] AsArray(this string entityLst) => [.. entityLst.AsSequence().Distinct().Order()];
}
you need to define the By and To variables according to the working language in the preferences. to simplify, you can choose a language (USA) during the execution time.
Best Regards
more clearly, here's an example (Offline)
static void FindNumber(int number = 42) {
string[] Grps = ["1to15 26to37 48 59 60", "16to25 38to47", "49to58 61to82"];
for (int i = 0; i < Grps.Length; i++)
if (Grps[i].AsArray().Contains(number)) {
WriteLine($"number {number} was found in group {i + 1} ({Grps[i]})"); break;
}
}
//number 42 was found in group 2 (16to25 38to47)
here's a method when Robot is connected
static void FindBarInListGroup(int number = 42) {
var Structure = new RobotApplication().Project.Structure;
var Groups = Structure.Groups; var bSel = Structure.Selections.Create(I_OT_BAR);
for (int i = 1; i <= Groups.GetCount(I_OT_BAR); i++) { var Group = Groups.Get(I_OT_BAR, i); bSel.FromText(Group.SelList);
if (bSel.Contains(number)) WriteLine($"number {number} was found in group {Group.Name} ({Group.SelList})");
}
}
Best Regards