Python field error
-
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.
-
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. -
Hi @SweepingMotion ,
Would be helpful if you'll provide sample project, or at least code for the python field. -
-
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 -
@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 changeoutputs._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
-
Yep that seems to do it.
-
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. -
@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.