# Set the command name so that DarkRadiant recognises this file __commandName__ = 'test_targets' # should not contain spaces __commandDisplayName__ = 'Test for Missing Targets' # should not contain spaces def execute(): g_targets = {} # entityname : [targets] g_missing = {} # entityname : [missingtargets] class TargetFinder(SceneNodeVisitor) : def pre(self, node): if node.isEntity(): n = node.getEntity() name = n.getKeyValue('name') targs = [t.second for t in n.getKeyValuePairs('target')] g_targets[name] = targs return 1 # Instantiate a new walker object and get list of entities/targets walker = TargetFinder() GlobalSceneGraph.root().traverse(walker) # Find any targets that don't exist, and count all targets entities = g_targets.keys() targetcount = 0 for ent in entities: targetcount += len(g_targets[ent]) missing = [] for targ in g_targets[ent]: if targ not in entities: missing.append(targ) if missing: g_missing[ent] = missing # generate report msg = '' msg += '%d entities found with %d targets' % (len(entities), targetcount) + '\n' if not g_missing: msg += 'No missing targets found\n' else: msg += 'Missing targets:\n' for ent in g_missing.keys(): for targ in g_missing[ent]: msg += '%s -> %s\n' % (ent, targ) # display report dialog = GlobalDialogManager.createMessageBox('Missing targets', msg, Dialog.CONFIRM) print(msg) dialog.run() if __executeCommand__: execute()