| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import wrappers.modelverse as mv
- def _get_nodes_with_type(model, typ):
- """ Returns a list of nodes in model model with type typ """
- all_nodes = mv.all_instances(model, "Node")
- ret = [node for node in all_nodes if mv.read_attrs(model, node)["type"] == typ]
- return ret
- def _get_all_models():
- """ Returns a list of paths of all example- and instance models """
- example_models = mv.model_list("models/example")
- example_models_full = ["models/example/"+exm for exm in example_models]
- instance_models = mv.model_list("models/instance")
- instance_models_full = ["models/instance/"+m for m in instance_models]
- return example_models_full + instance_models_full
- def retype_node(model, node, new_type, local):
- """
- Retype the node in model to new_type.
- If local is true, the change only affects the single node.
- If local is false, the change affects all nodes in all models.
- """
- if local:
- mv.attr_assign(model, node, "type", new_type)
- else:
- node_type_old = mv.read_attrs(model, node)["type"]
- all_models = _get_all_models()
- for m in all_models:
- nodes = _get_nodes_with_type(m, node_type_old)
- for node in nodes:
- mv.attr_assign(m, node, "type", new_type)
- def add_node(model, node_type, local):
- """
- Add a new node with ID node and type node_type to model model.
- If local is true, the node is only added to the passed model.
- If local is false, the node will be added to all models.
- """
- if local:
- ID = mv.instantiate(model, "Node")
- mv.attr_assign(model, ID, "type", node_type)
- else:
- all_models = _get_all_models()
- for m in all_models:
- ID = mv.instantiate(model, "Node")
- mv.attr_assign(model, ID, "type", node_type)
|