SOLVED Get string value from long cycle.

Is there any way to get the string value of the selected option from a cycle parameter? I tried to use shader's description (as I am testing on a shader) but it does not give the right result.
Thank you.

I came up with this solution which is working fine. Thanks for your help.

std::string
getDropDownName(Description* const description,
	Int32 group_id,
	Int32 SelectedItem)
{
	const DescID* singleid = description->GetSingleDescID();
	const DescID cid = DescLevel(group_id, DTYPE_LONG, 0);
	std::string selected_name = "";

	if (!singleid || cid.IsPartOf(*singleid, nullptr)) 
	{
		AutoAlloc<AtomArray> arr;
		BaseContainer* selectionParameter =
			description->GetParameterI(DescLevel(group_id, DTYPE_LONG, 0), arr);

		if (selectionParameter != nullptr) 
		{
			BaseContainer* items =
				selectionParameter->GetContainerInstance(DESC_CYCLE);

			if (items != nullptr) 
			{
				selected_name =
					items->GetData(SelectedItem).GetString().GetCStringCopy();
			}
		}
	}
	return selected_name;
}

Hello @ogers,

thank you for reaching out to us.

About your question: Yes, that is possible. It would have been better if you have shared what you tried, so that we would have a better idea what there did not give you the right result, but in principle you must get the cycle container for that description element in question and then read out its values. See Python example at the end of my posting for details. The example translates almost directly to C++, the only thing that is a little bit different in C++ is the fact that we do not have such a convenient auto-iteration for BaseContainer there.

Cheers,
Ferdinand

The code:

"""Example for how to read out the labels for a cycle description element.

The example is a Python Script Manger script which will read out the strings
of all cycle elements of the currently selected Extrude Object and its 
Direction parameter.

As discussed in:
    https://plugincafe.maxon.net/topic/13553/
"""

import c4d

def main():
    """
    """
    if not isinstance(op, c4d.BaseObject) or op.GetType() != c4d.Oextrude:
        raise RuntimeError("Please select an Extrude Object.")

    description = op.GetDescription(c4d.DESCFLAGS_DESC_NONE)
    directionContainer = description.GetParameter(c4d.EXTRUDEOBJECT_DIRECTION)
    print (f"Localized direction label:", directionContainer[c4d.DESC_NAME])
    
    cycleContainer = directionContainer[c4d.DESC_CYCLE]
    if not cycleContainer:
        raise  RuntimeError("Could not access cycle container.")
    
    for key, value in cycleContainer:
        print (key, value)

if __name__=='__main__':
    main()

The output:

Localized direction label: Direction
0 Auto
1 X
2 Y
3 Z
4 Custom
5 Absolute

I came up with this solution which is working fine. Thanks for your help.

std::string
getDropDownName(Description* const description,
	Int32 group_id,
	Int32 SelectedItem)
{
	const DescID* singleid = description->GetSingleDescID();
	const DescID cid = DescLevel(group_id, DTYPE_LONG, 0);
	std::string selected_name = "";

	if (!singleid || cid.IsPartOf(*singleid, nullptr)) 
	{
		AutoAlloc<AtomArray> arr;
		BaseContainer* selectionParameter =
			description->GetParameterI(DescLevel(group_id, DTYPE_LONG, 0), arr);

		if (selectionParameter != nullptr) 
		{
			BaseContainer* items =
				selectionParameter->GetContainerInstance(DESC_CYCLE);

			if (items != nullptr) 
			{
				selected_name =
					items->GetData(SelectedItem).GetString().GetCStringCopy();
			}
		}
	}
	return selected_name;
}