Hello @krfft,
here the promised code. It is an extension of the Search Assets example which can be found in the Asset API Handbook.
I hope this helps and cheers,
Ferdinand
The result:

The code:
static Int32 g_max_materials = 10;
/// ------------------------------------------------------------------------------------------------
/// Loads in the first ten material assets into the active document which can be found in the user
/// prefs repository.
///
/// I did remove most of the comment fluff here, assuming you are already familiar with the rest.
/// ------------------------------------------------------------------------------------------------
maxon::Result<void> LoadAssets()
{
iferr_scope;
// Get the active document and do some setup stuff to search for all materials in the user prefs
// repository. See FindAssets() example function in the Assets API exmaples for details.
BaseDocument* doc = GetActiveDocument();
if (doc == nullptr)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION, "No active document."_s);
const maxon::AssetRepositoryRef& repository = maxon::AssetInterface::GetUserPrefsRepository();
const maxon::AssetType assetType = maxon::AssetTypes::File();
const maxon::Id assetFindId = {};
const maxon::Id assetVersion = {};
maxon::BaseArray<maxon::AssetDescription> results;
repository.FindAssets(
assetType, assetFindId, assetVersion, maxon::ASSET_FIND_MODE::LATEST, results) iferr_return;
// Iterate over the results until we have found ten materials.
maxon::Int counter = 0;
for (maxon::AssetDescription assetDescription : results)
{
if (counter == g_max_materials)
break;
maxon::AssetMetaData metadata = assetDescription.GetMetaData();
maxon::Id subTypeId = metadata.Get(maxon::ASSETMETADATA::SubType) iferr_return;
// This is a material asset.
if (subTypeId == maxon::ASSETMETADATA::SubType_ENUM_Material)
{
// With a valid url.
maxon::Url url = assetDescription.GetUrl() iferr_return;
if (url.IsEmpty())
continue;
// The url of the asset is in case of material assets a c4d file. So, we merge that asset
// document with the active document.
ApplicationOutput("@| Type: @, Url: @", counter, subTypeId, url);
maxon::String* error = {};
maxon::Bool didMerge = MergeDocument(
doc, MaxonConvert(url), SCENEFILTER::MATERIALS, nullptr, error);
ApplicationOutput("@: Merged: @, Error: @", counter, didMerge, error);
if (didMerge)
counter++;
}
}
return maxon::OK;
}