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

    Python. Cinema4d. All iterations in the Text value

    Cinema 4D SDK
    4
    9
    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.
    • S
      SmetK
      last edited by

      Hi all. Tell me, what I need to do with the code so that each iteration is displayed in a separate line in the 3D text? Only the last one is shown. Second screenshot is a result i want!
      2fec99be-a3ed-4065-b50d-dd0e7b6c34d7-image.png
      12.JPG

      iplaiI B 2 Replies Last reply Reply Quote 0
      • B
        bentraje
        last edited by

        That's because you only have one text object.
        You need to also have multiple text object corresponding to the number of items you loop.

        S 1 Reply Last reply Reply Quote 0
        • S
          SmetK @bentraje
          last edited by

          @bentraje thx for answer!
          Is it physically impossible to enter random numbers within one text? I, without a script, can drive several lines of text or numbers into one text. Is it possible to do the same with Python? maybe other mechanics, not through iterations?

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

            I mean you can input all those numbers in one text if you don't mind foregoing individual controls.
            You just need to output multiple line of text/str.

            1 Reply Last reply Reply Quote 0
            • iplaiI
              iplai @SmetK
              last edited by

              @smetk
              You need line break character to join the items.

              from random import random
              def main() -> None:
                  global Output1
                  Output1 = "\n".join(f"{random()*10:.6f}" for i in range(6))
              

              Cheers.

              C4DJSON -- a useful module to load an dump c4d objects in python dict format (similar to standard python json module).
              Examples on Notion.

              S 1 Reply Last reply Reply Quote 0
              • B
                bentraje @SmetK
                last edited by

                @smetk

                something like this

                34c3f042-521e-4feb-8665-84ca85099305-image.png

                1 Reply Last reply Reply Quote 0
                • S
                  SmetK @iplai
                  last edited by

                  @iplai @bentraje Thanks guys, you are the best!

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

                    Hello @smetk,

                    thank you for reaching out to us. A big thank you also for the community answers given by @bentraje and @iplai. There is not much to add for us here, the solutions provided here are the correct solution.

                    It is a bit of a question of taste, but you could also write what you want to do in a more compressed and modern Python style. There is also the small problem that when you always append the line break character, this will also happen for the last line where this might not be intended. Find an example below which avoids this.

                    Cheers,
                    Ferdinand

                    The file: string_stuff.c4d
                    The result (I also added justification/null-padding for the decimal places):
                    Screenshot 2022-10-17 121521.png

                    The code:

                    import c4d
                    import random
                    
                    def main() -> None:
                        global text
                        # Compute n random numbers between minValue and maxValue, and round them each to three places.
                        numbers: list[float] = [round(random.uniform(n, n + 1), 3) for n in range(minValue, maxValue)]
                        # Convert them to strings while padding zeros to numbers which do not have three decimal places,
                        # e.g., 3.1 -> "3.100"
                        strings: list[str] = [f"{i}.{d.ljust(3, '0')}" for i, d in [str(n).split(".") for n in numbers]]
                        # Join them into a singular string using the line break character as the concatenation character.
                        text = "\n".join(strings)
                    

                    MAXON SDK Specialist
                    developers.maxon.net

                    S 1 Reply Last reply Reply Quote 1
                    • S
                      SmetK @ferdinand
                      last edited by

                      @ferdinand thx very much! ill save this

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