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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Modular plugin programming

    General Talk
    python
    2
    6
    2.0k
    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.
    • R
      Rage
      last edited by s_bach

      Hi All,

      I'm writing a plugin that imports, processes and exports 3d files (whatever cinema4d supports). It has two way of working:

      1. using parameter -scene, it checks merges all the top level objects and check if there are duplicates, and then checks if the object is already stored in a database
      2. using parameter -object, it just merges everything in the scene (removing cameras lamps etc) and then exports the object

      I wanted to keep the code in modules, storing the first part in a scene_exporter.py and the second one in object_exporter.py and here comes the problems. I don't know if it's because the plugin is in a .pyp file, but the import just doesn't work.
      What should I do to keep the code modular?

      1 Reply Last reply Reply Quote 0
      • S
        s_bach
        last edited by

        Hello,

        there should be no problem importing *.py files form a *.pyp file. What do you mean with "import just doesn't work."?

        For example: you can have a formulas.py file (next to your *.pyp) that looks like this:

        def SomeCalculation():
        
            return 5
        

        you can import int in your *.pyp just with

        import formulas
        

        and then use

        number = formulas.SomeCalculation()
        

        It gets a little bit more complicated if you want to register plugins in your sub-modules. In that case you would have to hand over the __res__ structure to these modules.

        best wishes,
        Sebastian

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 1
        • R
          Rage
          last edited by Rage

          Let me share you an example.

          This is a simple hello world program.
          In 'hello.pyp' I have (how do I format the text to code?):

          import c4d
          import sys
          import hello_function
          
          def PluginMessage(id, data):
              if id==c4d.C4DPL_COMMANDLINEARGS:
                  hello_function.say('Hello World')
                  return True
              return False
          

          In 'hello_function.py' I have:

          def say(word):
              print(word)
          

          When I run this from commandline, in the console I get the error that the hello_function package has not being found. They're on the same folder. I don't see any reason why this is not working

          1 Reply Last reply Reply Quote 0
          • S
            s_bach
            last edited by

            Hello,

            you find information on how to format code in this thread: How to Post Questions.

            best wishes,
            Sebastian

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

            1 Reply Last reply Reply Quote 1
            • R
              Rage
              last edited by

              Thanks

              Any hint why the hello world code I wrote is not working?

              1 Reply Last reply Reply Quote 0
              • S
                s_bach
                last edited by s_bach

                Hello,

                you might have to add the pyp file path to the system path using:

                sys.path.append(os.path.dirname(__file__))
                

                so

                import sys
                import os
                sys.path.append(os.path.dirname(__file__))
                
                
                import hello_function
                

                best wishes,
                Sebastian

                MAXON SDK Specialist

                Development Blog, MAXON Registered Developer

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