Display Names Script

I took this code from Autodesk Help, the code is displaying names of objects in viewport, and I have two questions about how to improve it.
The first question is: I have a group of objects, script shows me the names of every object in this group, but I want it to show me just the name of the group, how to do this?
And the second question is: When script displays the name of camera, it also displays the name of camera target, but I don't want it. How to exclude taget name? I tried something like "if o != Targetobject", but it not helped.

And here is the code:

unregisterRedrawViewsCallback GW_displayObjectNames

fn GW_displayObjectNames =
(
gw.setTransform (matrix3 1)
for o in objects where not o.isHiddenInVpt do
gw.text o.pos o.name color:yellow
gw.enlargeUpdateRect #whole
)

registerRedrawViewsCallback GW_displayObjectNames

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
miauu's picture

.

	unregisterRedrawViewsCallback GW_displayObjectNames
 
	function FindTopMostGroupHead obj = 
	(
		while obj != undefined and (not isGroupHead obj or isGroupMember obj) do
			(obj = obj.parent)
		obj
	)
 
	fn GW_displayObjectNames =
	(
		gw.setTransform (matrix3 1)
		for o in objects where not o.isHiddenInVpt and classof o != Targetobject do
		(
			if isGroupHead o or isOpenGroupHead o or isGroupMember o or isOpenGroupMember o then
			(
				grpHead = FindTopMostGroupHead o
				gw.text grpHead.pos grpHead.name color:yellow
			)
			else
			(				
				gw.text o.pos o.name color:yellow				
			)
			gw.enlargeUpdateRect #whole
		)
	)
 
	registerRedrawViewsCallback GW_displayObjectNames
chooj's picture

working

It is working! Thanks!

miauu's picture

.

This is more compact version and will show the names of the nested groups.

unregisterRedrawViewsCallback GW_displayObjectNames
 
	fn GW_displayObjectNames =
	(
		gw.setTransform (matrix3 1)
		for o in objects where not o.isHiddenInVpt and classof o != Targetobject do
		(
			if isGroupHead o or isOpenGroupHead o then
			(
				gw.text o.pos o.name color:yellow
			)
			else
			(
				if not isGroupMember o and not isOpenGroupMember o do
					gw.text o.pos o.name color:yellow				
			)
			gw.enlargeUpdateRect #whole
		)
	)
 
	registerRedrawViewsCallback GW_displayObjectNames

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.