ScriptSpot

Forum topic · General Scripting

Display Names Script

By chooj · 2016-02-08

Description

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 (6)

error

sketchupmaster · 2022-12-07

Hi

When Daylight system active in view-port then showing message
"Unkonwn property: "po" in $Daylight System"

.

miauu · 2022-12-07

Try this. The text will be displayed at the object's center.


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.center grpHead.name color:yellow
			)
			else
			(				
				gw.text o.center o.name color:yellow				
			)
			gw.enlargeUpdateRect #whole
		)
	)
 
	registerRedrawViewsCallback GW_displayObjectNames

.

miauu · 2016-02-09


	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

working

chooj · 2016-02-09

It is working! Thanks!

.

miauu · 2016-02-09

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

toggle . . . . !

sketchupmaster · 2022-12-07

Hello sir,

thanks for this. . . .
can we do only selected group toggle?