Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    Import sub-folder modules dynamically

    Scheduled Pinned Locked Moved PYTHON Development
    4 Posts 0 Posters 551 Views
    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.
    • H Offline
      Helper
      last edited by

      On 15/11/2017 at 08:07, xxxxxxxx wrote:

      Hi guys,

      I'm trying to import modules dynamically inside sub-folders of the plugin and can't seem to make it work. My current hierarchy looks as follow:

      /plugin
         |_plugin.pyp
         |_modules
         |  |_folder_A
         |    |   |
         |    |   |_file_A.py
         |    |
         |    |_folder_B
         |    |   |
         |    |   |_file_B.py
         |    |
         |    |_folder_C
         |        |
         |        |_file_C.py
         |
         |_res
              |_icons
                  |_icon.tif
              |_c4d_symbols.h

      Would like to be able to access the file_A, file_B and file_C. Do you have to include an empty __init__ file inside each folder?

      Apologies if this has been replied before. Just can't seem to find an answer.

      Thank you very much in advance! 🙂

      Andre

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 15/11/2017 at 08:28, xxxxxxxx wrote:

        Yes do it like you will do for any python module, make an empty __init__.py
        And then after that you could use from .modules._folder_A._file_A import MyClassA

        Moreover I'm sure you already read it but I suggest you to read https://developers.maxon.net/forum/topic/8229/10727_best-practice-for-imports

        Here a exemple of my plugin RefractiveIndexImporter https://github.com/gr4ph0s/RefractiveIndex-Importer wich use Niklas py-localimport class in order to make safe import.

        Hope it's help

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 15/11/2017 at 08:34, xxxxxxxx wrote:

          Hi graphos,

          Many thanks for your quick and awesome reply!

          Will give it a try and come back with a conclusion.

          Thanks again! 🙂

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            On 15/11/2017 at 09:06, xxxxxxxx wrote:

            Graphos you're a star! Worked like a treat :).

            Thank you very much again and hopefully this will help others! 😄

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