ScriptSpot

Forum topic · Scripts Wanted

Text objects for each selected object

By noparlescripto · 2008-08-27

Description

I'm guessing this might be a very easy script, but unfortunately I wasn't able to do it my self.
What I would like to do is to create a text object at a center of each selected object with a name for each source object like "source object name"_text and the text it self would be the source object name.
So for three boxes, Box1, box2 and box3 I would end up with three text shapes at center of each box with object names box1_text, box2_text and box3_text and each one would have the text itself taken from the boxes, so Box1, box2 and box3.

Any ideas?

I'm kind of a stuck on "for i=1 to ..." ;)

Comments (2)

martinskinner · 2008-08-27

Hi noparles - Try this, should do the trick


for i in selection do
-- loops through all the currently selected objects
(
	 t = text()
	 -- creates a text shape
	 t.pos = i.pos
	 -- positions it at the centre of the object
	 t.text = i.name
	 -- makes the text match the name of the object
	 t.size = ((i.max.y)/(i.max.x))
	 -- measures the bounding box of the object to create the text size
	 -- this can be altered as you see fit
	 t.name = i.name + "_Text"
	 -- renames the text shape with that of the object, + _Text
	 t.parent = i
	 -- parents the text shape to the original object
	 
)-- end loop

Martin

noparlescripto · 2008-08-27

Thank you, thank you, thank you.

That works absolutly great.