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

    ParseTupleAndKeywords in R20

    Cinema 4D SDK
    c++ r20 python
    2
    5
    1.3k
    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.
    • V
      victor
      last edited by

      We are adding new Python functions to Cinema and our solution works fine in R19 and previous versions but we are having problems parsing the parameters in R20

      static _PyObject *MyprojectPyAPI_MakeThing(_PyObject *self, _PyObject *args, _PyObject *keywords)
      {
      	PythonLibrary pylib;
      
      	String str;
      
      	const Char *kwlist[] = { "str", nullptr };
      	if (!pylib.ParseTupleAndKeywords(args, keywords, "$", kwlist, &str))
      		return nullptr;
      
        #if API_VERSION < 20000
      	  if (str.Content())
        #else
      	  if (str.IsEmpty()!=false)
        #endif
      	{            
      		Utils::addLog("Parameter is: " + str);
      	}
      	else
      	{
      		Utils::addLog("Cannot parse the parameter correctly.");
      	}
      
      	return pylib.ReturnPyNone();
      }
      

      As you can imagine the problem is that it always throws "Cannot parse the parameter correctly."

      Any idea on what is wrong for R20? something related to PythonLibrary changed?

      Thank you in advance!

      1 Reply Last reply Reply Quote 0
      • Y
        y_puech
        last edited by

        Hi Victor,

        Only minor changes/fixes have been made to the PythonLibrary and its behavior hasn't changed in R20. So parsing a String with $ should still work fine.

        How do you call the function and pass the string? What's the exact error message?

        Former MAXON SDK Engineer

        1 Reply Last reply Reply Quote 0
        • V
          victor
          last edited by

          I didn't change nothing from the version that works ok in R19

          moduleFunctions[0].Init("MakeThing", (PyFn)MyprojectPyAPI_MakeThing, PYFN_FLAGS::KEYWORDS, "MakeThing(str path)");
          
          1 Reply Last reply Reply Quote 0
          • Y
            y_puech
            last edited by y_puech

            Hi Victor,

            There's a logic error in the code you posted from the first post. The condition for R20 if (str.IsEmpty()!=false) returns false if the string has content.
            It makes more sense to call IsPopulated() for the R20 code instead of IsEmpty().

            Former MAXON SDK Engineer

            V 1 Reply Last reply Reply Quote 3
            • V
              victor @y_puech
              last edited by

              @y_puech said in ParseTupleAndKeywords in R20:

              Hi Victor,

              There's a logic error in the code you posted from the first post. The condition for R20 if (str.IsEmpty()!=false) returns false if the string has content.
              It makes more sense to call IsPopulated() for the R20 code instead of IsEmpty().

              You are right, thank you!!!

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