def split_by_net_role(obj): # Actor Mixer和Virtual Folder无法被放在SwitchContainer下面 if obj['type'] == 'ActorMixer' or obj['type'] == 'Folder': return original_name = obj['name'] # 拆分结构并重组到SwitchContainer下面 old_parent = WaapiTools.get_parent_objects(obj, False) new_parent = WaapiTools.create_object(original_name + '_Temp', 'SwitchContainer', old_parent, 'rename') WaapiTools.move_object(obj, new_parent) obj_2p = WaapiTools.copy_object(obj, new_parent) obj_3p = WaapiTools.copy_object(obj, new_parent) WaapiTools.rename_object(obj, original_name + '_1P') WaapiTools.rename_object(obj_2p, original_name + '_2P') WaapiTools.rename_object(obj_3p, original_name + '_3P') WaapiTools.rename_object(new_parent, original_name) # 分配bus original_bus = WaapiTools.get_object_property(obj, '@OutputBus') original_bus_name = original_bus['name'] bus_1p = WaapiTools.find_object_by_name(original_bus_name + '_1P', 'Bus') if bus_1p is None: bus_1p = WaapiTools.create_object(original_bus_name + '_1P', 'Bus', original_bus, 'replace') bus_2p = WaapiTools.find_object_by_name(original_bus_name + '_2P', 'Bus') if bus_2p is None: bus_2p = WaapiTools.create_object(original_bus_name + '_2P', 'Bus', original_bus, 'replace') bus_3p = WaapiTools.find_object_by_name(original_bus_name + '_3P', 'Bus') if bus_3p is None: bus_3p = WaapiTools.create_object(original_bus_name + '_3P', 'Bus', original_bus, 'replace') WaapiTools.set_object_property(obj, 'OverrideOutput', True) WaapiTools.set_object_reference(obj, 'OutputBus', bus_1p) WaapiTools.set_object_property(obj_2p, 'OverrideOutput', True) WaapiTools.set_object_reference(obj_2p, 'OutputBus', bus_2p) WaapiTools.set_object_property(obj_3p, 'OverrideOutput', True) WaapiTools.set_object_reference(obj_3p, 'OutputBus', bus_3p) net_role_switch_group = WaapiTools.find_object_by_name( 'Net_Role', 'SwitchGroup') if net_role_switch_group is None: return WaapiTools.set_object_reference(new_parent, 'SwitchGroupOrStateGroup', net_role_switch_group) for switch_obj in WaapiTools.get_children_objects(net_role_switch_group, False): if '1P' in switch_obj['name']: assign_switch_mapping(obj, switch_obj) WaapiTools.set_object_reference(new_parent, 'DefaultSwitchOrState', switch_obj) if '2P' in switch_obj['name']: assign_switch_mapping(obj_2p, switch_obj) if '3P' in switch_obj['name']: assign_switch_mapping(obj_3p, switch_obj)
def copy_selection_to_active_objects(self): if WaapiTools.Client is None: return selection = WaapiTools.get_selected_objects() if len(selection) > 0: self.batchProcessor = BatchProcessor( self.activeObjects, lambda obj: WaapiTools.copy_object(selection[0], obj)) self.batchProcessor.start()