Script Select objs with same name in same group

Next
 From:  noskule
11274.1 
Hi All
Has anyone an idea how to modify the code below to select all objects with the same name but restrict it to the same group?
Thanks for any hints
Nos


/* Extend selection to same names */
var names = new Array();
var objs = moi.geometryDatabase.getSelectedObjects();

for (var i = 0; i < objs.length; ++i) {
var obj = objs.item(i);
if (obj.name != '') {
names[obj.name] = true;
}
}

objs = moi.geometryDatabase.getObjects();
for (var i = 0; i < objs.length; ++i) {
var obj = objs.item(i);
if (obj.name != '' && names[obj.name]) {
obj.selected = true;
}
}



/* Extend selection to same names, show hidden objects */
var names = new Array();
var objs = moi.geometryDatabase.getSelectedObjects();

for (var i = 0; i < objs.length; ++i) {
var obj = objs.item(i);
if (obj.name != '') {
names[obj.name] = true;
}
}

objs = moi.geometryDatabase.getObjects();
for (var i = 0; i < objs.length; ++i) {
var obj = objs.item(i);
if (obj.name != '' && names[obj.name]) {
obj.hidden = false;
obj.selected = true;
}
}

EDITED: 4 Dec 2023 by MICHAEL GIBSON

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  pressure (PEER)
11274.2 In reply to 11274.1 
Hi Nos,

What should happen if there are objects named "x" in group "a" and also objects named "x" in group "b"?

- Peer
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
11274.3 In reply to 11274.1 
Hi Nos,

re:
> Has anyone an idea how to modify the code below to select all objects with the same
> name but restrict it to the same group?

Maybe an easy way for this case could be to mark a combination of the object name and the parent group's id instead of just object name. That way only objects with both that name and in the same group would match.

So like this (warning untested code):

code:
/* Extend selection to same names */
var names = new Array();
var objs = moi.geometryDatabase.getSelectedObjects();

for (var i = 0; i < objs.length; ++i) {
    var obj = objs.item(i);
    if (obj.name != '' && obj.ownerGroup) {
        names[obj.name + obj.ownerGroup.id] = true;
    }
}

objs = moi.geometryDatabase.getObjects();
for (var i = 0; i < objs.length; ++i) {
    var obj = objs.item(i);
    if (obj.name != '' && obj.ownerGroup && names[obj.name + ownerGroup.id]) {
        obj.selected = true;
    }
}


  - Michael

EDITED: 4 Dec 2023 by MICHAEL GIBSON

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  noskule
11274.4 In reply to 11274.2 
If you apply the script to an object in group "a" only objects with the same name in group "a" would be selected.
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  noskule
11274.5 In reply to 11274.3 
Thanks, here the modfied code selecting only objects in the same group.

/* Extend selection to same names, check ownerGroup */
var names = new Array();
var objs = moi.geometryDatabase.getSelectedObjects();

for (var i = 0; i < objs.length; ++i) {
var obj = objs.item(i);
if (obj.name != '' && obj.ownerGroup) {
names[obj.name + obj.ownerGroup.id] = true;
}
}

objs = moi.geometryDatabase.getObjects();
for (var i = 0; i < objs.length; ++i) {
var obj = objs.item(i);
if (obj.name != '' && obj.ownerGroup && names[obj.name + obj.ownerGroup.id]) {
obj.selected = true;
}
}



/* Extend selection to same names, show hidden objects, check ownerGroup */
var names = new Array();
var objs = moi.geometryDatabase.getSelectedObjects();

for (var i = 0; i < objs.length; ++i) {
var obj = objs.item(i);
if (obj.name != '' && obj.ownerGroup) {
names[obj.name + obj.ownerGroup.id] = true;
}
}

objs = moi.geometryDatabase.getObjects();
for (var i = 0; i < objs.length; ++i) {
var obj = objs.item(i);
if (obj.name != '' && obj.ownerGroup && names[obj.name + obj.ownerGroup.id]) {
obj.hidden = false;
obj.selected = true;
}
}
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All