I was really delighted to hear that svg import is now supported natively in S25. But the only method I am aware of so far is via drag and drop.
I would like to import an svg file using only its path as input in a python script. Is there a way to do that?
thank you for reaching out to us. You can just use the existing loading and merging functions in c4d.documents. The snippet below will open a file dialog where you must select a SVG file, and it will then load that SVG file into a new scene. The example will also suppress the options dialog of the importer. There are many options with c4d.documents.LoadDocument and c4d.documents.MergeDocument; to not suppress these options dialogs, to merge with specific documents, etc. If necessary, you could also get hold of the SVG importer plugin first to set the import settings. See our documentation for details on c4d.documents.LoadDocument. And in our GitHub Python SDK repository, in the Files & Media section, you can find examples for manipulating the im- and exporter plugins.
"""Loads an svg file from a file dialog.
You can just replace `file` with any path you would like.
file = c4d.storage.LoadDialog(title='Select a file')
if not file or os.path.splitext(file).lower() != ".svg":
raise RuntimeError("Please select a svg file.")
doc = c4d.documents.LoadDocument(file, c4d.SCENEFILTER_NONE)
if doc is None:
raise RuntimeError("Failed to load svg file.")
Thank you so much!