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 field error

    Cinema 4D SDK
    python 2024
    4
    9
    1.5k
    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
      SweepingMotion
      last edited by

      When add the default python field and increase the number of subdivs I'm getting this error. What gives?

      Traceback (most recent call last):
        File "<Python Field_0>", line 22, in Sample
      BaseException: The input list is not long enough (need 400)
      

      Just to reiterate this happens with the default unedited python field.

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

        I must've been half asleep when writing this yesterday. I now realize I didn't explain myself too well.
        Just to explain the problem a bit better:
        The setup - plane primitive with a vertex map applied, python field added.
        Now everything is great until the number of points on the plane exceeds 400 - this is where the error crops up. Seems like the number of points in input list is capped at 400... but not the output list.

        bacaB 1 Reply Last reply Reply Quote 0
        • bacaB
          baca @SweepingMotion
          last edited by

          Hi @SweepingMotion ,
          Would be helpful if you'll provide sample project, or at least code for the python field.

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

            Here's what's happening.
            I think I understand now - the input data is given in blocks of 400 points. And I need to traverse those blocks to get all the points.

            ferdinandF bacaB 2 Replies Last reply Reply Quote 0
            • ferdinandF
              ferdinand @SweepingMotion
              last edited by ferdinand

              Hey @SweepingMotion,

              Thank you for reaching out to us. We have seen your question, understood it, and will answer here soon. Please also make sure to consolidate your observations and explanations for a question into a singular posting in the future. It does not help a thread when the question alone is split over multiple postings.

              PS: It will not be me answering this.

              Cheers,
              Ferdinand

              MAXON SDK Specialist
              developers.maxon.net

              1 Reply Last reply Reply Quote 0
              • bacaB
                baca @SweepingMotion
                last edited by

                @SweepingMotion nice finding
                Yes, there are quite a few issues in the sample codes everywhere.
                To fix the Python Field, I think it's required to change

                    outputs._value = [
                        c4d.utils.RangeMap((~mgEffector * mgInput * p).GetLength(), 100., 0., 0., 1., True)
                        for p in inputs._position
                    ]
                

                to

                    outValues = outputs._value
                
                    for index, p in enumerate(inputs._position):
                        outValues[index] = c4d.utils.RangeMap((~mgEffector * mgInput * p).GetLength(), 100., 0., 0., 1., True)
                
                    outputs._value = outValues
                
                1 Reply Last reply Reply Quote 0
                • S
                  SweepingMotion
                  last edited by

                  Yep that seems to do it.

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

                    Hi thanks for this topic, as you may or not know Field sampling is multi-threaded and for a given list of inputs defined in the FieldInput there is an equivalent FieldOutput with the same data count.
                    In order to Multi-thread fields, FieldInput that you receive in the Sample function, is just a "Block" aka a part of the initial list of inputs, and the output is an FieldOutputBlock which also represent just a part of the final list.
                    The default size for blocks are 400 entries and when there is leftover the input size adapt while the output size does not for the moment (due to a bug) and still is 400.

                    As an example, if you have 405 inputs in total. The sample function will be called 2 times with:

                    • 400 inputs and 400 outputs to feed.
                    • 5 inputs and for the moment 400 outputs to feed.

                    So in order to fix the issue the best workaround I see right now is to compensate to also provide a list of 400 entries, even if theses values will be unused.

                        outputs._value = [
                            c4d.utils.RangeMap((~mgEffector * mgInput * p).GetLength(), 100., 0., 0., 1., True)
                            for p in inputs._position
                        ] + ([0.0] * (outputs.GetCount() - inputs.GetCount()))
                    

                    A fix is coming in one of the next version of Cinema 4D, so that OutputBlockSize == InputBlockSize and therefor you will not need to add this "useless" values at the end to fullfill the outValues.

                    Cheers,
                    Maxime.

                    MAXON SDK Specialist

                    Development Blog, MAXON Registered Developer

                    S 1 Reply Last reply Reply Quote 2
                    • S
                      SweepingMotion @m_adam
                      last edited by

                      @m_adam said in Python field error:

                      A fix is coming in one of the next version of Cinema 4D, so that OutputBlockSize == InputBlockSize and therefor you will not need to add this "useless" values at the end to fullfill the outValues.

                      That's great news. I'll hold off till then.

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