Python reading fields issue
-
Dear community,
is it possible that the method c4d.modules.mograph.FieldInfo.Create() is (currently) bugged ie from 2024 onwards?
As an example:
, (and simplified it a little)
I took this script fromimport c4d from c4d.modules.mograph import FieldInput, FieldInfo, FieldOutput def fieldlist_sampling(op, doc, poslist, fields): pCount = len(poslist) sample_flags = c4d.FIELDSAMPLE_FLAG_VALUE | c4d.FIELDSAMPLE_FLAG_COLOR fieldInput = FieldInput(poslist, allocatedCount=pCount) fieldInfo = FieldInfo.Create(sample_flags, None, doc, 0, 1, fieldInput, op) fieldOutput = FieldOutput.Create(pCount, sample_flags) fields.DirectInitSampling(fieldInfo) samplingSuccess = fields.DirectSample(fieldInput, fieldOutput.GetBlock(), fieldInfo) fields.DirectFreeSampling(fieldInfo) return fieldOutput def main(): count =5 distance = 225 fields = op[c4d.ID_USERDATA,1] null = c4d.BaseObject(c4d.Onull) if not count: return null div = ((count-1)/2)*distance poslist = [c4d.Vector((distance*c)-div,0,0) for c in range(0,count)] samp_list = fieldlist_sampling(op, doc, poslist, fields) # samp_list._value for n,p in enumerate(poslist): cube = c4d.BaseObject(c4d.Ocube) cube.SetRelPos(p) value = c4d.utils.RangeMap(value=samp_list._value[n], mininput=0, maxinput=1, minoutput=20, maxoutput=150, clampval=False) cube[c4d.PRIM_CUBE_LEN] = c4d.Vector(value) cube[c4d.ID_BASEOBJECT_USECOLOR] = 2 cube[c4d.ID_BASEOBJECT_COLOR] = samp_list._color[n] cube.InsertUnder(null) return null
It is for a python generator with a field list in user data (id=1), field list contains a linear field.
When the field is moved the cubes change size and colour, the script is not perfect, it's just to demonstrate.The generator works on 2023 and below but not in 2024 and above
This it the running in 2023:
and this is 2025
-
Welcome to the Maxon developers forum and its community, it is great to have you with us!
Getting Started
Before creating your next postings, we would recommend making yourself accustomed with our forum and support procedures. You did not do anything wrong, we point all new users to these rules.
- Forum Overview: Provides a broad overview of the fundamental structure and rules of this forum, such as the purpose of the different sub-forums or the fact that we will ban users who engage in hate speech or harassment.
- Support Procedures: Provides a more in detail overview of how we provide technical support for APIs here. This topic will tell you how to ask good questions and limits of our technical support.
- Forum Features: Provides an overview of the technical features of this forum, such as Markdown markup or file uploads.
It is strongly recommended to read the first two topics carefully, especially the section Support Procedures: Asking Questions.
About your First Question
I can confirm that there is an issue, and there is little that you can do. This goes back to the 2024 API update and how Field sampling changed then in the C++ API. In Python, we postponed things:
Fields sampling have been reworked, however due to time constraint the next methods have not been ported and are not working, we are going to fix it in an upcoming release.
But that apparently somehow got stuck in a backlog and we never picked up on it again. I have moved this topic to the bugs section, there is nothing you can do at the moment.
Cheers,
Ferdinand -
-
Thanks for looking at this. Does this main that it is at least on the "to do" list again?
Does it still work in c++ -
Yes, we will treat it as a bug. Apparently we implemented it, but then someone disabled the implementation (probably because it caused performance issues or something like that), and then we forgot do follow up on that disabled implementation. Generally we cannot give ETA's for fixes but we try to do them in a timely fashion, i.e., within a couple of minor releases such as 2024.1, 2024.2, 2024.3, etc. I am not the dev here so, I can make even less gurantees. We will update this thread when something blocks us from fixing this in the near future.
And yes, it does work in C++. The reason why this is not working in Python is because of the C++ API changes with 2024.0. This link shows how you sample things in C++, the changes revolved around making sampling a field a const operation, i.e., an operation which does not change data on the object. Which was before not the case and now requires that mutable data to be manually passed arround as the
extraData
as shown in the example. The changes were carried out to speed up the core of Cinema 4D.Cheers,
Ferdinand