$resource = $modx->newObject('modResource');
// set some fields...
$resource->fromArray($someFields);
// modResource::cleanAlias
// Transform a string into a valid URL representation
$alias = $resource->cleanAlias('My dirty URL_alias');
$resource->set('alias', $alias);
$resource->save();
I know it's an old thread but if anyone is still looking for a code example here it is.