Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

TextPlus: How to label an Object using its Object name

Anonymous

TextPlus: How to label an Object using its Object name

Anonymous
Not applicable

Is it possible to label an Object with its Object Name using TextPlus?

 

I have watched the TextPlus Set Value as Text tutorial but this only enables values from a reference Object, not its Name

 

I have ~200 objects to label in my scene, it would be much quicker if there is a method to support this, rather than having to type out the individual object names 200 times

 

thanks

0 Likes
Reply
Accepted solutions (1)
1,669 Views
9 Replies
Replies (9)

Alfred.DeFlaminis
Alumni
Alumni

Hello @Anonymous and welcome to the community,

 

Since this thread didn't get a reply and I'm not really great at scripting I am going to move this thread to the programming forum in the hopes that you get a reply there.  Thank you.

 

Best Regards,

0 Likes

Anonymous
Not applicable

no worries @Alfred.DeFlaminis, cheers

0 Likes

drew.avis
Autodesk
Autodesk
Accepted solution

Hi, here's a short script that applies a textplus label to every non-textplus object in a scene.  You can use it as a starting point for what you're trying to do.

 

-- label everything in the scene w/ a textplus

fn label_it obj = (

	str = obj.name

	t = TextPlus size:10
	t.SetFont "Arial" 0
	t.ResetStyle()
	t.ResetString()
	t.AppendString str
	t.pos = obj.pos
	bb = nodeLocalBoundingBox obj
	t.pos.z = bb[2].z
)

allObjects = $*
for obj in allObjects do (
	
	print obj.name
	-- don't label textplus objects, that would be silly
	if (classOf obj != TextPlus) do (
		label_it obj
	)
)


Drew Avis
Content Experience Designer

Alfred.DeFlaminis
Alumni
Alumni

Nice one Drew, I tested it and it's great!  Does that help @Anonymous?

 

If you feel that this solves the issue for you @Anonymous, please mark Drew's post as the solution.  Thanks!  

Best Regards,

0 Likes

Anonymous
Not applicable

cheers thanks @drew.avis exactly what I was after!

0 Likes

Anonymous
Not applicable

thanks @Alfred.DeFlaminis for progressing this, as always you rock 

0 Likes

Anonymous
Not applicable

nice @drew.avis, if you don't mind, I think this is useful (just 1 bold line added)

 

-- label everything in the scene w/ a textplus

fn label_it obj = (

	str = obj.name

	t = TextPlus size:10
	t.SetFont "Arial" 0
	t.ResetStyle()
	t.ResetString()
	t.AppendString str
	t.pos = obj.pos
	bb = nodeLocalBoundingBox obj
	t.pos.z = bb[2].z
	t.parent = obj   -- link label to object
)

allObjects = $*
for obj in allObjects do (
	
	print obj.name
	-- don't label textplus objects, that would be silly
	if (classOf obj != TextPlus) do (
		label_it obj
	)
)

just so if you move the objects around, the labels go with them...

drew.avis
Autodesk
Autodesk

@Anonymous, good addition - you could also put the labels on their own layer to easily show/hide.  Lots of potential for fun with this one.



Drew Avis
Content Experience Designer
0 Likes

Alfred.DeFlaminis
Alumni
Alumni

Happy to do whatever I can @Anonymous. Smiley Very Happy  Thanks for the kind words.   Good idea here @Anonymous and thank you very much @drew.avis for your awesome code.  

 

I made a small addition as well, adding a tiny bit of extrude to the lettering so when zoomed out the faces don't overlap.  (Default setting of textplus.)

 

-- label everything in the scene w/ a textplus

fn label_it obj = (

	str = obj.name

	t = TextPlus size:10
	t.SetFont "Arial" 0
	t.ResetStyle()
	t.ResetString()
	t.AppendString str
	t.pos = obj.pos
	bb = nodeLocalBoundingBox obj
	t.pos.z = bb[2].z
	t.parent = obj   -- link label to object
        t.extrudeamount = 0.025
)

allObjects = $*
for obj in allObjects do (
	
	print obj.name
	-- don't label textplus objects, that would be silly
	if (classOf obj != TextPlus) do (
		label_it obj
	)
)

Best Regards,

0 Likes