@mfersaoui
I thought it was possible to automatically get all elements ids inside an group and then enable/disable them.
Hi,
I am not sure if this is a question, but it is possible. I am too lazy to get up and get my laptop, but it could look something like this (in a sort of very detailed pseudo code):
def get_group_children_data(node, groups_to_collect):
''' Returns group to element relations of the description of the
passed node as a dictionary.
Args:
node (c4d.C4DAtom): The node to evaluate the description of.
groups_to_collect (list[c4d.DescID]): A list of DescIDs of
the groups we want to collect all children for.
Returns:
dict: A hash map of the group to children relations.
key (str): The string representation of the DescID of the group.
value (list): The DescIDs of all children.
'''
data = {}
# GetDescription() is a member of C4DAtom, returning the description
# of a node. The Description type has a __iter__ implementation which
# provides all we need in this case (the blanked out first element
# of the __iter__ triple is the actual element description, but we
# won't need it), desc_id is the DescID of an element and group_id the
# DescID of the container it is parented to.
for _, desc_id, group_id in node.GetDescription(c4d.DESCFLAGS_DESC_NONE):
# Step over group ids we are not interested in
if group_id not in groups_to_collect:
continue
# Initialize a bin when we encounter a group id the first time
if str(group_id) not in data:
# This is sort of an ugly hack here, almost all (all?) types of
# c4d are not hashable (do not implement __hash__()), which means
# that they cannot be use as keys in hash maps among other things.
# You could also use DescID.GetHashCode() instead of str() here.
data[str(group_id)] = []
# Add the element.
data[str(group_id)] += [desc_id]
return data
def GetDEnabling(self, node, id, t_data, flags, itemdesc):
"""
"""
# _group_data is the result of the function above.
for group_id, element_ids in self._group_data.items():
if group_id == str(should_be_disabled_id) and id in element_ids:
return False
...
Cheers
zipit