Is it possible to create a panalized node in code?
Make sure that your content type is panelized (you've panelizer link at /admin/structure/types).
Double check the Panelizer settings of that content type, for instance whether to 'Provide an initial display named "Default"' (at /admin/structure/types/manage/%).


Above 2 steps can be achieved programatically by either exporting panelizer_defaults component into Features code:

features[panelizer_defaults][] = node:my_content_type:default


or define them using hook_panelizer_defaults manually.

At this point all your created nodes should be panelized automatically and the settings should be available in node object at $node-&gt;panelizer['page_manager'].

Still not sure if your node is panelized or not? Run this via drush (where 123 is your node id):

$ drush eval "print_r(node_load(123)-&gt;panelizer['page_manager']);"


and if you'll see an object printed out, your node is panelized.

Then if you would like to create/re-create panel display associated with the node, try the following code:

$node = node_load($nid);
$old_display = $node-&gt;panelizer['page_manager']-&gt;display;
$new_display = panels_save_display($display);
$node-&gt;panelizer['page_manager']-&gt;display = &amp;$new_display;
$node-&gt;panelizer['page_manager']-&gt;display_is_modified = TRUE;
node_save($node);
// Clear caches just in case.
ctools_include('object-cache');
ctools_object_cache_clear('panels_node_display_cache', $node-&gt;nid);
$did = is_numeric($new_display-&gt;did) ? $new_display-&gt;did : FALSE; // Your display id.


The same thing can be achieved on newly created code by creating a panels_new_display(); instead and assign it to $node-&gt;panelizer['page_manager']-&gt;display.  Also note that the display should be only saved once (not on every node save), then it can be modified based on your needs.

See also:


How to attach node into panelized node?
Updating Panelizer content programmatically