Programmatically Build a Profile2 Form

Here is a snippet which sets up a profile2 form array, pre-populated with the appropriate account data.

// Load the user's profile. "main" is the profile2 type (or bundle)
$profile = profile2_load_by_user($account, 'main');
$profile2_form = array();
// Add profile data to $form_state
$profile2_form_state = array(
  'profiles' => array('main' => $profile),
);
profile2_attach_form($profile2_form, $profile2_form_state);

Now you can access the entire form array, or specific form elements from $profile2_form.

This could be useful for situations where you want to inject specific elements from a profile2 form into a custom form.