Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Get string value from long cycle.

    Cinema 4D SDK
    c++ r21
    2
    3
    591
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • O
      Ogers
      last edited by Ogers

      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.

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @Ogers
        last edited by ferdinand

        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://developers.maxon.net/forum/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
        

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • O
          Ogers
          last edited by Ogers

          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;
          }
          
          1 Reply Last reply Reply Quote 0
          • First post
            Last post