My script works and I got what I want, but there are two problems.
-
maxon.AssetManagerInterface.LoadAssets
always return False event the asset loaded successfully. -
I set the parameters of Geometry Axis by find the param's name. Is there a better way to change the parameters?
import maxon, c4d
def loadGeometryAxis(x=0, y=0, z=0, parent: c4d.BaseList2D = None):
repository = maxon.AssetInterface.GetUserPrefsRepository()
if not repository:
raise RuntimeError("Could not access the user preferences repository.")
# Geometry Axis asset id
assetid = maxon.Id("net.maxon.neutron.asset.geo.geometryaxis")
assetsToLoad = [(assetid, ""), ]
sceneNodesHook = doc.FindSceneHook(c4d.SCENENODES_IDS_SCENEHOOK_ID)
if not sceneNodesHook:
raise RuntimeError("Could not retrieve Scene Nodes scene hook.")
sceneNodesHook.Message(maxon.neutron.MSG_CREATE_IF_REQUIRED)
sceneNodes = sceneNodesHook.GetNimbusRef(maxon.neutron.NODESPACE)
if not sceneNodes:
raise RuntimeError("Could not retrieve Scene Nodes graph model.")
graph = sceneNodes.GetGraph()
didLoad = maxon.AssetManagerInterface.LoadAssets(repository, assetsToLoad, graphModelRef=graph)
if not didLoad:
# `didLoad` is always False, event the asset loaded successfully.
# What's wrong?
# raise RuntimeError(f"Could not load assets for the ids: {assetsToLoad}")
...
obj = doc.GetFirstObject()
# Is there is a better way to change the parameters?
for bc, descid, _ in obj.GetDescription(c4d.DESCFLAGS_DESC_0):
name = bc[c4d.DESC_NAME]
if name == "Axis X":
obj[descid] = x
if name == "Axis Y":
obj[descid] = y
if name == "Axis Z":
obj[descid] = z
if parent is not None:
obj.InsertUnderLast(parent)
if __name__ == "__main__":
cube = c4d.BaseObject(c4d.Ocube)
loadGeometryAxis(y=1, parent=cube)
doc.InsertObject(cube)