Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    How to import svg in S25 from path

    Cinema 4D SDK
    python
    2
    3
    836
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • I
      InterfaceGuy
      last edited by ferdinand

      Hello,

      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

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @InterfaceGuy
        last edited by ferdinand

        Hello @InterfaceGuy,

        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.

        Cheers,
        Ferdinand

        The result:
        d7a200e5-ae4f-4d9d-97ed-4337d4cda711-image.png

        The script:

        import c4d
        import os
        
        def main():
            """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)[1].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.")
            
            c4d.documents.InsertBaseDocument(doc)
            c4d.documents.SetActiveDocument(doc)
            
        if __name__=='__main__':
            main()
        

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • I
          InterfaceGuy
          last edited by

          Thank you so much!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post