How to get explicit import node space?
-
Hey community,
I want to get the explicit render engine name of the default import plugin but not the index, can I do this?
e.g. I want to set the importor to Standard or Redshift, but if I remove some renderer like CentiLeo, the index of Standard will changed.
Cheers~
DunHou -
Hey @Dunhou,
Thank you for reaching out to us. This subject comes up from time to time, and the answer is that you have to eval the description at runtime. I probably should write a more prominent example for that. In case you have already considered this option and deemed it unsafe, there is no safer route.
Cheers,
Ferdinand"""Demonstrates how to evaluate a dynamically built description at runtime. Things like cycles (Cinema slang for a combo box) are often built at runtime in Cinema 4D. I.e., there is no resource where one could look up all the cycle elements in advance. And this of course makes sense, because something like all the installed render engines cannot be known in advance. The solution to this to evaluate the description of the item at runtime, to figure out what cycle index corresponds to which string label. This is of course a bit unsafe, but there is no better way for dynamic elements as their defining characteristics is that they do not have a static identifier. """ import c4d import mxutils doc: c4d.documents.BaseDocument # The currently active document. op: c4d.BaseObject | None # The primary selected object in `doc`. Can be `None`. def main() -> None: """Called by Cinema 4D when the script is being executed. """ # Get the import/export preferences plugin. pref: c4d.plugins.BasePlugin = mxutils.CheckType( c4d.plugins.FindPlugin(c4d.PREFS_IMPORTEXPORT, c4d.PLUGINTYPE_PREFS)) # Get its description and there the container for `PREF_IMEXPORT_NODESPACE`. desc: c4d.Description = pref.GetDescription(c4d.DESCFLAGS_DESC_NONE) param: c4d.BaseContainer = mxutils.CheckType(desc.GetParameter(c4d.PREF_IMEXPORT_NODESPACE)) # Get the cycle element in the parameter container and print all values. cycle: c4d.BaseContainer = mxutils.CheckType(param[c4d.DESC_CYCLE]) for i, v in cycle: print(f"Cycle element {i}: {v}") # Build a translation map from string labels to indices. This assumes that there are no exactly # identical render engine labels in the cycle. Which is reasonable but not a hard guarantee. engineMap: dict[str, int] = {v: i for i, v in cycle} # Now set the render engine in the settings using a string and a fallback value in case an # engine with our string is not present. pref[c4d.PREF_IMEXPORT_NODESPACE] = engineMap.get("CentiLeo", 0) if __name__ == '__main__': main()
-
Thanks @ferdinand for your great solution!
Cheers~
DunHou