Dynamically create blocks

Permalink
Is there some way in the code to create a block and add it to an area dynamically? We're trying to display a different guestbook based on the user id url parameter. The area is being generated like this:
$areaName = 'Guestbook-'.$profile->uID;
$a = new Area($areaName);
$a->display($c);


But is there a similar way to create and attach a block to this area just after it's generated?

 
martinboi replied on at Permalink Best Answer Reply
Here's something in case anyone ever needs it: (It's more for myself to remember)

Worst community ever...

$args = array(
               'requireApproval' => 0,
               'title' => '',
               'dateFormat' => 'M jS, Y',
               'requireApproval' => 0,
               'displayGuestBookForm' => 1,
               'authenticationRequired' => 0,
               'notifyEmail' => ''
            );
            $bt = BlockType::getByHandle('guestbook');
            $b = $c->addBlock($bt, $arHandle, $args);
            $b->setCustomTemplate('melody_chat.php');