Automatically creating child nodes using the Rules module

Recently I developed a site for viewing switch maps. Basically, each switch was it's own node, each module within the switch was it's own node, and each individual port within each module was it's own node - all linked using node reference fields. Using the module views_attach (although I could have accomplished the same thing using node templates) and a lot of CSS, I display all the associated modules with all associated ports on each switch node.

However - this is a LOT of content. Thousands and thousands of individual port nodes. No one would have time to enter all that. So - I created a shortcut using the rules module, some PHP, and the editablefields module.

When a module node is created, the user creating it enters the range of port numbers, how those ports are aligned (numbered vertically or horizontally) and any breaks in the numbering. I created a rule that is triggered after a node of type 'module' is saved that creates all the associated port nodes based on the properties of the individual module. (I also created a rule that deletes all associated port nodes when a module is deleted, but that's another story.)

To use PHP with the rules module, make sure the core PHP module is enabled. Somehow I missed that initially. After loading the switch associated with the module that was just created, the following variables are available:
$switch_node = the switch node
$node = the module node

The critical lines for creating these nodes are:
<?php
if( ! function_exists("node_object_prepare")) {
include_once(drupal_get_path('module', 'node') . '/node.pages.inc');
}
$my_node = new stdClass();
$my_node->is_new = TRUE;
$my_node->type = 'port';
node_object_prepare($my_node);
//Set all field values in here
$my_node = node_submit($my_node);
node_save($my_node);
content_insert($my_node);
?>

As an added trick, I use taxonomy to tag individual port nodes for more detailed theming (for example around breaks in the module pattern).
$my_node->taxonomy[] = 1; //Where 1 is the term id for the taxonomy term I'm adding