@i_mazlov
Thanks for your help. I using visual studio code as you suggested and am getting to grips with the Drag and Drop to assist with parameter getting and setting.
Latest posts made by james.thamesview
-
RE: Python generator
-
Python generator
I am using a python generator to produce sets of splines. I want the code to check the python generator object for a hair tag. Then I want to get the underlying hair material colour gradient and use that as the basis for customer hair textures to be applied to the splines
this is a snippet of what I have so far (mainly using copilot to help me)
for tag in op.GetTags():#print (tag,tag.GetType()) if tag.GetType() == c4d.Thairmaterial: material_tag = tag material = material_tag.GetMaterial() source_gradient = material[c4d.HAIR_MATERIAL_COLOR_GRADIENT] gradient = hair_material[c4d.HAIR_MATERIAL_COLOR_GRADIENT] for i in range(gradient.GetKnotCount()): knot = gradient.GetKnot(i) print(f"Knot {i}: Color = {knot.col}, Position = {knot.pos}") break
This fails with "AttributeError: 'c4d.BaseTag' object has no attribute 'GetMaterial' "
It looks to me like python is not seeing tag as a Hair material and/or I am calling the wrong method to get the underlying material.
So two questions:
1: how do I correct this
2: what should I be searching for in the docs to be able to work this out for myselfThanks in advance
Regards
Jim
-
RE: Python reading fields issue
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++ -
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