(API) GET THE GROUP THAT THE BAR BELONGS TO VIA API

(API) GET THE GROUP THAT THE BAR BELONGS TO VIA API

eng_leandromartins
Enthusiast Enthusiast
661 Views
3 Replies
Message 1 of 4

(API) GET THE GROUP THAT THE BAR BELONGS TO VIA API

eng_leandromartins
Enthusiast
Enthusiast

How do I get which group the bar belongs to via API?
Please, if possible, a code in C#

0 Likes
Accepted solutions (1)
662 Views
3 Replies
Replies (3)
Message 2 of 4

Stephane.kapetanovic
Mentor
Mentor

hi @eng_leandromartins 

you should read these topics

(API) Retrive Nodes of a group from exsisting group and then extracting the results 

(API) Get groups through API 

Group Colors

 

Note:

Here's a code that might inspire you to return an integer array as a function of a text list in Robot format (Offline).

static int[] RLstToArray(string entityLst) {
    List<int> result = [];
    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) result.Add(i);
    }
    return [.. result.Distinct().Order()];
}

you need to define the By and To variables according to the working language in the prefrences. to simplify, you can choose a language (USA) during the execution time.

Best Regards

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
Message 3 of 4

Stephane.kapetanovic
Mentor
Mentor

more clearly, here's an example (Offline)

static void FindNumber(int number = 42) {
    To = "to"; By = "By";
    string Grp1 = "1to15 26to37 48 59 60", Grp2 = "16to25 38to47", Grp3 = "49to58 61to82";
    string[] Grps = new string[] { Grp1, Grp2, Grp3 };
    for (int i = 0; i < Grps.Count(); i++)
        if (RLstToArray(Grps[i]).Contains(number)) {
            WriteLine($"number {number} was found in group {i + 1} ({Grps[i]})"); break;
        }
}

//number 42 was found in group 2 (16to25 38to47)

 

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
0 Likes
Message 4 of 4

Stephane.kapetanovic
Mentor
Mentor
Accepted solution

hi @eng_leandromartins 

here's a method when Robot is connected

static void FindBarInListGroup() {
    RobotApplication RobApp = new RobotApplication();
    RobotStructure Structure = RobApp.Project.Structure;
    RobotSelection bSel = Structure.Selections.Create(I_OT_BAR);
    RobotGroupServer Groups = Structure.Groups;

    int BarToFind = 42;
    for (int i = 1; i <= Groups.GetCount(I_OT_BAR); i++) {
        RobotGroup Group = Groups.Get(I_OT_BAR, i); string sList = Group.SelList, Name = Group.Name;
        bSel.FromText(sList);
        if (bSel.Contains(BarToFind))
            WriteLine($"number {BarToFind} was found in group {Name} ({sList})");
    }
}

Best Regards

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
0 Likes