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

    C++ -> Python of DOCUMENTSETTINGS_GENERAL & DOCUMENT_STATEX

    Cinema 4D SDK
    3
    4
    433
    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
      mogh
      last edited by

      I found this C++ code to retreive the Axis State of C4D

      axisstate.x = doc->GetData(DOCUMENTSETTINGS_GENERAL).GetBool(DOCUMENT_STATEX) ? 1 : 0;
      

      I am trying to translate this to python including the weird syntax of ? 1:0

      what does this do ? Set True to 1 and false to 0 ?

      The Documentation only gave me this which didn't enlighten me.

      Thank you for your time.
      mogh

      1 Reply Last reply Reply Quote 0
      • C4DSC
        C4DS
        last edited by C4DS

        result = <statement> ? 1 : 0;
        When the statement before the question mark evaluates to true, then the part before the colon is assigned, else the right part is assigned.
        In your case when the flag of DOCUMENTSETTINGS_GENERAL is set (= true) then the value 1 is assigned to axisstate.x, if flag is cleared (= false) then value 0 is set.

        in other words, it is a shortcut for

        if (doc->GetData(DOCUMENTSETTINGS_GENERAL).GetBool(DOCUMENT_STATEX))
          axisstate.x = 1;
        else
          axisstate.x = 0;
        1 Reply Last reply Reply Quote 1
        • M
          m_adam
          last edited by

          Hi @mogh This is a ternary operation,

          python support it this way.

          axisstate.x = 1 if doc.GetData(c4d.DOCUMENTSETTINGS_GENERAL).GetBool(DOCUMENT_STATEX) else 0
          

          but regarding the statement, it could also be used without the ternary operator, since True == 1 as an integer so it will produce the same result

          axisstate.x = int(doc.GetData(c4d.DOCUMENTSETTINGS_GENERAL).GetBool(DOCUMENT_STATEX))
          

          Cheers,
          Maxime

          MAXON SDK Specialist

          Development Blog, MAXON Registered Developer

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

            thanks to all of you, got it working with
            axisstate.x = int(doc.GetData(c4d.DOCUMENTSETTINGS_GENERAL).GetBool(c4d.DOCUMENT_STATEX))

            kind regards mogh

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