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

    string format

    Cinema 4D SDK
    3
    4
    1.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.
    • J
      Jvos
      last edited by Jvos

      how come that my string formatting is not working in C4D.

      exposure = lamp[c4d.REDSHIFT_LIGHT_PHYSICAL_EXPOSURE]
      

      this works like it should and give's me the exposure

      x = 'REDSHIFT_LIGHT_PHYSICAL_EXPOSURE'
      exposure = lamp[c4d.'{}'.format(x)]
      

      but this give's an invalid syntax.

      I want to format because I need a dict comprehension where I get each attribute from a list. like this

      attributes = ['REDSHIFT_LIGHT_PHYSICAL_INTENSITY', 'REDSHIFT_LIGHT_PHYSICAL_EXPOSURE']
      lamps = doc.GetActiveObjects(0)
      dict_variable = [{attr: lamp[c4d.'{}'.format(attr)] for attr in attributes} for lamp in lamps]
      

      is there maybe like a C4D slack? got always question, but also quick answers for other people. a forum is sometimes a bit slow.
      My thanks!

      1 Reply Last reply Reply Quote 0
      • mikeudinM
        mikeudin
        last edited by

        You trying to create name of the variable with formatting.
        But format is only for strings.
        Maybe 'eval()' can help you.

        Checkout my python tutorials, plugins, scripts, xpresso presets and more
        https://mikeudin.net

        J 1 Reply Last reply Reply Quote 0
        • J
          Jvos @mikeudin
          last edited by

          @mikeudin seems to work. maybe because it needs to have c4d.REDSHIFT_LIGHT_PHYSICAL_EXPOSURE as an expression and not as a string.

          thanks a lot man!

          1 Reply Last reply Reply Quote 1
          • M
            m_adam
            last edited by m_adam

            Hi @Jvos,

            First of all, (no worry at all) I would like to remind you to read How to Post Questions especially the part about categories.
            Since your topic is related to Cinema 4D please next time create a topic within cinema 4d development. (I've moved it).

            Regarding your issue, pretty much all parameters in Cinema 4D are stored in a BaseContainer.
            A BaseContainer is a dictionary which links an ID (Int) to a Data.
            When you are doing Object[Something] you access the value within this BaseContainer.

            If you write in the console c4d.REDSHIFT_LIGHT_PHYSICAL_INTENSITY, it will print you the ID of this parameter.
            Then to get the value of a parameter which is stored in the object's BaseContainer, you don't have to pass a string, but the ID, which is registered with a SYMBOL NAME because it's easier to remember than an arbitrary number (In some case there is no SYMBOL equivalent for an ID).

            So as @mikeudin suggested the eval function is the right way to go, or you can directly store the ID in your list.

            attributes = [c4d.REDSHIFT_LIGHT_PHYSICAL_INTENSITY, c4d.REDSHIFT_LIGHT_PHYSICAL_EXPOSURE]
            

            Finally, there is no official C4D slack/discord or chat.
            Cheers,
            Maxime.

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

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