How to select an object with object-name using script?

Next
 From:  hamkoo
9848.1 
How to select an object with object-name using script?tks!
  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:  Frenchy Pilou (PILOU)
9848.2 In reply to 9848.1 
You speak about this script ?

script: /* ObjectName = Name Style + Number */ var objs = moi.geometryDatabase.getObjects(); var styles = moi.geometryDatabase.getObjectStyles(); for ( var i = 0; i < objs.length; ++i ) { var obj = objs.item(i); obj.name = styles.item(obj.styleIndex).name + '_' + i; }

I believe you just open the Browser and select your wished object on the Object list...where each object has a different name given by the script...like ...Blue_2, Red_3

EDITED: 23 Jun 2020 by PILOU

  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
9848.3 In reply to 9848.1 
Hi hamkoo,

re:
> How to select an object with object-name using script?tks!

There are a couple of different ways, one way is to just loop through all objects looking at the object's .name property for the one you want and then set its .selected property to true like this:

script: var objs = moi.geometryDatabase.getObjects(); for ( var i = 0; i < objs.length; ++i ) { var obj = objs.item(i); if (obj.name == 'testname' ) obj.selected = true; }

There is also a selectNamed() function you can use that does that for you and also supports "wildcard" characters like * and ? :

script: moi.geometryDatabase.selectNamed( 'testname' );

Also if you type in the object name into the XYZ input box it will run the select named function on that name. So for example to select all objects that start with 'test' push the Tab key to put focus in the XYZ input box, type test* and push enter and now all objects beginning with 'test' will get selected.

- Michael
  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:  Cemortan_Tudor
9848.4 
& how should i select all unnamed (ex: hide/show unnamed)
  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:  Michael Gibson
9848.5 In reply to 9848.4 
Hi Cemortan_Tudor,

re:
> & how should i select all unnamed (ex: hide/show unnamed)

Type Tab to put focus in the XYZ control, type * and push Enter to select all named objects, then use Select > Invert.

You could also set up a keyboard shortcut with this script to do it:

script: var objs = moi.geometryDatabase.getObjects(); for ( var i = 0; i < objs.length; ++i ) { var obj = objs.item(i); if (obj.name == '' ) obj.selected = true; }

- Michael
  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