how to name an object via scripting

 From:  Michael Gibson
6731.2 In reply to 6731.1 
Hi steve, yes it's possible to name an object using scripting - objects have a .name property that can be set on them.

One trick though is that often times scripts do not deal with individual objects directly themselves but rather create what's called a "geometry factory" and it's actually the factory that deals directly with the objects. That's how RingCircle2 works and so you'll need to retrieve the object from the factory before you'll be able to then set the name on it.

That would go like this - find the line near the end of RingCircle2.js that has this in it:

code:
	// Commit the factory to finalize creation of the circle.
	Factory.commit();
}


And right before that, insert these 2 lines:

code:
	var circle = Factory.getCreatedObjects().item(0);
	circle.name = 'Name goes here';	

	// Commit the factory to finalize creation of the circle.
	Factory.commit();



What that does is get a list of all created objects from the geometry factory, then gets the first item of that list which is the circle object, then the name property of the circle object can be set.

This will only work in v3 I think, not v2 since v2 does not have that .getCreatedObjects() access method in it.

Hope this helps!

- Michael