testmodel("texttest5");
findLocalClient().HUDTable = trim(findLocalClient().HUDTable SPC test.getId());
if(isObject(test2)) test2.delete();
new StaticShape(test2) { dataBlock = "testdata" @ $testinc;};
test.mountObject(test2, 0);
test.hideNode("ALL");
test.unHideNode("ca1");
test.setNodeColor("ALL", "1 0 0 1");

hiname = "nothing";
lastHighest = 0
for obj in bpy.data.objects:
	if obj.type == 'MESH':
		if obj.dimensions[0] > lastHighest:
			hiname = obj.name
			lastHighest = obj.dimensions[0]

print("longest is " + hiname)

# Set all objects to blank material group
mat = bpy.data.materials.get("blank")
for obj in bpy.data.objects:
	if obj.type == 'MESH':
		obj.data.materials[0] = mat

# Set all objects to root parent
for obj in bpy.data.objects:
	if obj.type == 'MESH':
		obj.parent = bpy.data.objects['root']

# Set all objects to detail group
for obj in bpy.data.objects:
	if obj.type == 'MESH':
		obj.select = True
		grp = bpy.data.groups.get('detail100')
		badgrp = bpy.data.groups.get('detail100.001')
		#
		try:
			badgrp.objects.unlink(obj)
		except:
			print("not in group")
		try:
			grp.objects.link(obj)
		except:
			print("already in group.")
		obj.select = False


for obj in bpy.data.objects:
	# Select the object
	if obj.type == 'MESH':
		obj.select = True
		#
		# Go into edit mode
		bpy.ops.object.mode_set(mode='EDIT')
		#
		# Select all verticies
		bpy.ops.mesh.select_all(action='SELECT')
		#
		# Set cursor position to center
		try:
			bpy.ops.view3d.snap_cursor_to_selected()
		except:
			print("Retarded context error:")
			print(bpy.context.mode)
		#
		# Set 3D position to center and then go into object mode
		bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
		bpy.ops.object.mode_set(mode='OBJECT')
		#
		# Set 3D Cursor to center
		bpy.ops.view3d.snap_cursor_to_center();
		#
		obj.location[0] = obj.dimensions[0] / 2
		obj.location[2] = -obj.dimensions[1] / 2
		#
		bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
		obj.select = False
		bpy.context.scene.objects.active = 0

bpy.context.area.type = 'CONSOLE'