Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    FormatStatement and maxon DataTypes...

    Cinema 4D SDK
    r20 c++ windows
    2
    5
    991
    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.
    • M
      mp5gosu
      last edited by mp5gosu

      Is there any information available on how the Maxon DataTypes implement ToString()'s FormatStatement?
      And secondly, a maxon::Data with nullptr as argument gives a different result than an unconfigured FormatStatement argument. Is this intended behaviour?

      // Store values
      	template <typename T>
      	void CreateAttribute(maxon::String name, T value)
      	{
      		_attributes.Set(name, value);
      	}
      
      // ........
      
      myElement->CreateAttribute("MyAttributeName"_s, 23.0);
      
      // To print them:
      maxon::String buf;
      maxon::FormatStatement fs;
      buf += " "_s + attrib.first.ToString(nullptr) + "=\""_s + attrib.second.ToString(nullptr) + "\""_s; // This gives another result than
      //buf += " "_s + attrib.first.ToString(nullptr) + "=\""_s + attrib.second.ToString(fs) + "\""_s
      
      DiagnosticOutput("@", buf);
      
      1 Reply Last reply Reply Quote 0
      • S
        s_bach
        last edited by

        Hello,

        there is no information available on how a specific data type implements ToString(). You can find the implementation of some data type's ToString() function in the corresponding header for source file in the framework.

        Could you explain your second question a bit more? What data exactly is stored in maxon::Data? What is stored in attrib.second?

        General information on data types and FormatStatement is available in these manuals:

        • MAXON Data Type
        • FormatStatement Manual

        If you want to combine strings as show in your code you can also use FormatString(). See String Manual.

        best wishes,
        Sebastian

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 2
        • M
          mp5gosu
          last edited by mp5gosu

          Hey Sebastian,

          thanks for
          @s_bach said in FormatStatement and maxon DataTypes...:

          Could you explain your second question a bit more? What data exactly is stored in maxon::Data? What is stored in attrib.second?

          Sure. I'm storing a key value pair of maxon::String and a variable type (Float, String, Int, Vector, etc.).
          for example:

          maxon::DataDictionary dict;
          dict.Set("MyKey"_s, maxon::Float(3.0)); // or simply dict.Set("MyKey"_s, 3.0)
          // and so on...
          

          After that I'm iterating the dictionary and use DiagnosticOutput for printing to IDE console:

          for (const auto& data: dict)
          {
              DiagnosticOutput("Key: @ / Value: @"_s, data.first.ToString(nullptr), 
                  data.second.ToString(nullptr) // If I replace the nullptr here with a dummy FormatStatement, the output changes from `3` to `3.000`
          }
          
          

          I don't understand why the nullptr gives a different result than with given an empty FormatStatement?

          By the way, thanks for pointing me to FormatString (didn't know about that one), that's very helpful. πŸ™‚

          edit: One of the reasons I'm asking this, is because in case of a vector, ToString outputs something like (3.0, 2.5, 11.6) - note the braces.
          I wanted to know if there are some identifiers available that change the output, therefore my initial question. Searched the headers already, no success. πŸ™‚

          1 Reply Last reply Reply Quote 0
          • S
            s_bach
            last edited by

            Hello,

            I can only assume that somewhere deep inside Cinema there is a switch that formats the output depending on the given FormatStatement argument.

            If you want to format a value manually, there are many conversion functions: Conversion

            You can use maxon::String::FloatToString() to define how a float value is formatted.

            The implementation of a vector's ToString() function can be found in the vec.h header file:

            String ToString(const FormatStatement* formatStatement) const
            {
              return "("_s + maxon::ToString(x, formatStatement) + ","_s + maxon::ToString(y, formatStatement) + ","_s + maxon::ToString(z, formatStatement) + ")"_s;
            }
            

            best wishes,
            Sebastian

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

            1 Reply Last reply Reply Quote 1
            • M
              mp5gosu
              last edited by

              Ah, thank you. I didn't take a look at vec.h.
              Meanwhile, I already wrote a conversion unit to handle all sorts of formatting. Thought, it was possible to modify the intern string conversions somehow. But nevermind, all works pretty well. πŸ™‚

              Cheers,
              Robert

              1 Reply Last reply Reply Quote 0
              • First post
                Last post