Robot Structural Analysis Forum
Welcome to Autodesk’s Robot Structural Analysis Forums. Share your knowledge, ask questions, and explore popular Robot Structural Analysis topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
eng_leandromartins
147 Views, 3 Replies

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

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

3 REPLIES 3
Message 2 of 4

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

Best Regards

 

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) {
    foreach (string keyword in new string[] { By, To }) {
        string[] parts = EntityLst.Split(new[] { keyword }, StringSplitOptions.RemoveEmptyEntries);
        for (int i = 0; i < parts.Length; i++) parts[i] = parts[i].Trim();
        EntityLst = string.Join(keyword, parts);
    }
    List<int> result = new List<int>();
    string[] entities = EntityLst.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    foreach (var entity in entities) {
        string[] byParts = entity.Split(new[] { By }, StringSplitOptions.None),
                 toParts = byParts[0].Split(new[] { To }, StringSplitOptions.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().OrderBy(i => i).ToArray();
}

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.

 

 

Tags (2)
Message 3 of 4

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++) {
        string Grp = Grps[i];
        if (RLstToArray(Grp).Contains(number)) {
            Console.WriteLine($"number {number} was found in group {i + 1} ({Grp})");
            break;
        }
    }
}

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

 

Tags (2)
Message 4 of 4

hi @eng_leandromartins 

here's a method when Robot is connected

static void FindBarInListGroup(){
    RobotApplication RobApp = new RobotApplication();
    RobotStructure Structure = RobApp.Project.Structure;

    IRobotObjectType BarType = IRobotObjectType.I_OT_BAR;

    RobotSelection BarSelection = Structure.Selections.Create(BarType);
    RobotGroupServer Groups = Structure.Groups;

    int BarToFind = 42;

    for (int i = 1; i <= Groups.GetCount(BarType); i++) {
        RobotGroup Group = Groups.Get(BarType, i);
        string List = Group.SelList;
        BarSelection.FromText(List);

        bool Exist = BarSelection.Contains(BarToFind);
        if (Exist) Console.WriteLine($"number {BarToFind} was found in group {Group.Name} ({List})");
    }
}

Best Regards

 

Tags (2)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report