Hi @mp5gosu,
I can ask, but I doubt that this will added, because it is ultimately something that can be "fixed" relatively easily from the user side (see end of posting for example). The only meaningful explanation I can give is that BaseContainer.Sort
was implemented for a very specific reason. BaseContainer
is not really meant to be a replacement for a sortable collection data type.
Cheers,
Ferdinand
"""A little workaround for the somewhat odd BaseContainer sorting behavior.
"""
import c4d
def cleanSort(bc):
"""A little helper for BaseContainer.Sort().
"""
# Sort the container.
bc.Sort()
# Get out when the IDs 0 and 1 are not of type string.
if (bc.GetType(0) != c4d.DA_STRING or
bc.GetType(1) != c4d.DA_STRING):
return bc
# Save the value of ID 1
valIdOne = bc[1]
# Remove the ID 1 and reinsert it in the "right" place.
if bc.GetIndexId(0) == 1 and bc.RemoveIndex(0):
bc.InsDataAfter(1, valIdOne, bc.GetDataPointer(0))
return bc
def main():
"""
"""
data = {3: "d", 1: "b", 2: "c", 0:"a"}
bc = c4d.BaseContainer()
for eid, value in data.items():
bc.SetString(eid, value)
print ("Before:")
for eid, value in bc:
print(f"id: {eid}, value:{value}")
print ("")
bc = cleanSort(bc)
print ("After:")
for eid, value in bc:
print(f"id: {eid}, value:{value}")
if __name__=='__main__':
main()