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

    Using Console Variable in the Script Manager?

    Cinema 4D SDK
    r21 python
    3
    4
    409
    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.
    • B
      bentraje
      last edited by

      Hi,

      Is it possible to use Console Variable in the Script Manager?
      You can see what I am after in this video:
      https://www.dropbox.com/s/13cma0qm8h7w4gn/c4d273_console_variable_in_script_manager_python.mp4?dl=0

      I don't mind if the method is "not ideal". I'm only using this on few isolated operations.
      My use case is defining the variable from Document B but using that same variable in Document A

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

        Hi,

        I am not quite sure if I understand you correctly here, but generally speaking, no, you cannot access attributes of the module of Cinema's live interpreter from some other module. The usual way to send something from document A to document B would be using Cinema's message system. But if you do not want to do this, you can simply insert your data into the interpreter. There are multiple places you can choose from and they are all equally bad. Here is an example for inserting data as fake modules into the modules dictionary of the interpreter, which at least looks somewhat gracefully. But this is generally a bad idea, you have been warned.

        Cheers,
        zipit

        """Put this into the script manager and run it twice. The first time it
        will say that it did not find any data and instead stored some, and the
        second time it will retrieve this data.
        
        You should keep in mind that this data is only as long present as long
        Cinema does not restart its Python Virtual Machine (which to my knowledge
        does not happen, but you never know). This (obviously) also means that 
        this won't work with running c4dpy from the console in any fashion.
        
        Cinema's message system or simply writing the data to file would be much
        more suitable solutions. If you are using this, you should at least clean
        up the module dictionary after you are done.
        """
        
        # We try to access our data by importing them.
        try:
            import some_string
            import some_object
        
            print "Found data:"
            print some_string
            print some_object
        # If no data is present, we write into the system module dictionary.
        except:
        
            import types
            import sys
            # Some data floating around we want to pass around in the interpreter.
            SOME_STRING = "Bob is your uncle."
            SOME_OBJECT = [3, 1, 4, 1, 5]
        
            # Now comes the really, really, really, ..., really bad stuff. We 
            # just insert our data into the module dictionary.
        
            for name, data in (("some_string", SOME_STRING),
                               ("some_object", SOME_OBJECT)):
                # Make sure we do not overwrite anything important.
                if name not in sys.modules:
                    sys.modules[name] = data
                # The assumption here is that if something is there and it is not a
                # module, we probably put it there ourselves.
                elif not isinstance(sys.modules[name], types.ModuleType):
                    sys.modules[name] = data
            # From now on we can import this data from anywhere, as long as the
            # interpreter instance is kept alive.
            print "No data was present, inserted data into the module dictionary."```

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 1
        • ManuelM
          Manuel
          last edited by

          hi,

          there's no possibilities to do it. The console and the script manager doesn't share the same context.

          What you want to achieve is not clear to me. Maybe doing something like a copy/paste ?

          The only place inside cinema4D where you can share data between document is the world Container but it's not really the right place to do it neither.

          Cheers,
          Manuel

          MAXON SDK Specialist

          MAXON Registered Developer

          1 Reply Last reply Reply Quote 1
          • B
            bentraje
            last edited by

            @m_magalhaes
            Thanks for the confirmation. Although what zipit provided also works for my use case (i.e. defining the variable from Document B but using that same variable in Document A)

            @zipit

            Thanks for the code. It works as expected 🙂

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