Space Claim script to detect overlapping selections

Landon Mitchell Kanner
Landon Mitchell Kanner Member, Employee Posts: 183
First Answer First Comment 5 Likes First Anniversary
edited July 2023 in 3D Design

In Space Claim is there a command for detecting overlapping named selections? It is not possible to record "Named Selections" > "Detect Overlapping Selections"

 Are any examples available?

Best Answer

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 183
    First Answer First Comment 5 Likes First Anniversary
    edited July 2023 Answer ✓
    # Python Script, API Version = V23
    def detect_group_overlap():
        """
        detect overlapping groups
        Inputs: 
        None
        Outputs:
        new_groups (List[Group]): List of the newly created groups. Each group contains the objects
        that appear in multiple groups. Each group has the name 'Overlap <group_1_name>:<group_2_name>'
        """
        new_groups=[]
        all_groups=list(Window.ActiveWindow.Groups)
        all_members=[member for group in all_groups for member in group.Members]
        for i,group_a in enumerate(all_groups[:-1]):
            members_a=group_a.Members
            group_a_name=group_a.GetName()
            for group_b in all_groups[i+1:]:
                members_b=group_b.Members
                group_b_name=group_b.GetName()
                overlap=set(members_a) & set(members_b)
                if len(overlap)>0:
                    new_group=Group.Create(GetRootPart(),"Overlap "+group_a_name+":"+group_b_name,List[IDocObject](overlap))
        return new_groups       
     
    
    
    
    
    def fix_group_overlap():
        """
        fix overlapping groups
        Inputs: 
        None
        Outputs:
        None
        """
        new_groups=[]
        all_groups=list(Window.ActiveWindow.Groups)
        all_members=[member for group in all_groups for member in group.Members]
        for i,group_a in enumerate(all_groups[:-1]):
            members_a=group_a.Members
            group_a_name=group_a.GetName()
            for group_b in all_groups[i+1:]:
                members_b=group_b.Members
                group_b_name=group_b.GetName()
                print(group_a_name+"<>"+group_b_name)
                overlap=set(members_a) & set(members_b)
                if len(overlap)>0:
                    new_members_b=list(members_b)
                    for obj in overlap:
                        new_members_b.remove(obj)
                    if len(new_members_b)==0:
                        group_b.Delete()
                    else:
                        NamedSelection.Replace(group_b_name,Selection.Create(new_members_b),Selection.Empty())
        return     
     
     #detect_group_overlap()
     #fix_group_overlap()