Hi @wen I've moved your topic to the bug section since it's indeed a bug, I will ping you on this topic once the fix is available, it should come in one of the next update.
The issue is that the internal cache is not properly updated and therefor this is failing.
With that's said there is a ugly workaround which consist of calling it twice so the cache is properly updated.
Find bellow a version that is going to work in all versions
import c4d
import maxon
import os
def CreateRepFromUrl(url: maxon.Url) -> maxon.UpdatableAssetRepositoryRef:
"""Create a new repository from a given database URL.
If there is no valid database at the given URL, it creates a database at the URL.
It always create a new repository and the associated database asset, even if there
are existing repositories for that database.
"""
# Make type checks
if not isinstance(url, maxon.Url):
raise TypeError("First argument is not a maxon.Url")
# Create a unique identifier for the repository.
rid = maxon.AssetInterface.MakeUuid(str(url), True)
# Repositories can be composed out of other repositories which are called bases. In this
# case no bases are used to construct the repository. But with bases a repository for all
# user databases could be constructed for example.
bases = maxon.BaseArray(maxon.AssetRepositoryRef)
# Create a writable and persistent repository for the database URL. If #_dbUrl would point
# to a location where no database has been yet stored, the necessary data would be created.
if c4d.GetC4DVersion() < 2025200:
try:
repository = maxon.AssetInterface.CreateRepositoryFromUrl(
rid, maxon.AssetRepositoryTypes.AssetDatabase(), bases, url, True, False, False, None)
except Exception as e:
repository = maxon.AssetInterface.CreateRepositoryFromUrl(
rid, maxon.AssetRepositoryTypes.AssetDatabase(), bases, url, True, False, False, None)
else:
try:
repository = maxon.AssetInterface.CreateRepositoryFromUrl(
rid, maxon.AssetRepositoryTypes.AssetDatabase(), bases, url, True, False, False)
except Exception as e:
repository = maxon.AssetInterface.CreateRepositoryFromUrl(
rid, maxon.AssetRepositoryTypes.AssetDatabase(), bases, url, True, False, False)
if not repository:
raise RuntimeError("Repository construction failed.")
return repository
if __name__ == '__main__':
if not maxon.AssetDataBasesInterface.WaitForDatabaseLoading():
raise RuntimeError("Could not load asset databases.")
dbPath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "testdb")
print(CreateRepFromUrl(maxon.Url(dbPath)))
Cheers,
Maxime.