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

    DATETIME in RES file

    Scheduled Pinned Locked Moved PYTHON Development
    8 Posts 0 Posters 628 Views
    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.
    • H Offline
      Helper
      last edited by

      On 06/05/2013 at 12:52, xxxxxxxx wrote:

      I'm using the DATETIME GUI within a res file and it shows ok.
      However, is there a standard way to get/set the DATETIME GUI, like self.SetDateTime / self.GetDateTime?

      At this moment I use the following code to init and read the DATETIME GUI.
      I have the feeling it is not the optimal / best way?

      RES file:
      		DATETIME SOLAR_DATE_TIME {NOW_BUTTON;}
        
      INIT:
        
          def Init(self, node) :
              tag = node
              data = tag.GetDataInstance()
        
              dtr = data[SOLAR_DATE_TIME]
              td=datetime.strptime('01.01.2010 00:00:00',"%d.%m.%Y %H:%M:%S")
              
              dtd=DateTimeData()
              dtd.SetDateTime(td)
              data.SetData(SOLAR_DATE_TIME,dtd)
              return True
        
      GETTING THE INPUT:
        
          def Execute(self, tag, doc, op, bt, priority, flags) :
              
              data = tag.GetDataInstance()                    #get GUI data
              dtr = data[SOLAR_DATE_TIME]
              datetime = dtr.GetDateTime ()
              print datetime
              .....
      

      Note: It is a TagPlugin
      Note: I had to add "import time", else strptime gave me an error.

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 06/05/2013 at 13:18, xxxxxxxx wrote:

        Hi pgroof,

        why do you think this is not optimal? I don't see much space for improvements.

        Best,
        -Niklas

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 06/05/2013 at 13:47, xxxxxxxx wrote:

          you have to import time, as the DateTime description element is just a front end for
          the time module. it is an second/epoche based format originated in c. there is also the
          DateTime module in python (not to confuse with the DateTime description element)
          which offers a more object oriented approach on time and date management.

          the time module has some drawbacks, but what i really liked about it is, as it is seconds 
          based, you can simply do time0 - time1. you can convert between time and datetime and 
          there are also more methods than just strptime() in the time module.

          http://docs.python.org/2/library/time.html
          http://docs.python.org/2/library/datetime.html#module-datetime

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            On 06/05/2013 at 13:52, xxxxxxxx wrote:

            Am I missing something obvious? Why would you need to import the time module? You are not
            referencing the time module from anywhere in the code you have posted.

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              On 06/05/2013 at 14:04, xxxxxxxx wrote:

              he is , but I did mix up datetime and time, following the ops mixup 😉 he is using datetime.

              td=datetime.strptime('01.01.2010 00:00:00',"%d.%m.%Y %H:%M:%S")

              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

                On 06/05/2013 at 14:08, xxxxxxxx wrote:

                Ah, I really wondered why everyone was talking about the "time" module.. 😄
                But then he had to write "from datetime import datetime".

                1 Reply Last reply Reply Quote 0
                • H Offline
                  Helper
                  last edited by

                  On 06/05/2013 at 14:12, xxxxxxxx wrote:

                  well their methods output is the same both return time.somethingblah_structs. hard to spot 😉

                  1 Reply Last reply Reply Quote 0
                  • H Offline
                    Helper
                    last edited by

                    On 06/05/2013 at 23:12, xxxxxxxx wrote:

                    Originally posted by xxxxxxxx

                    Hi pgroof,

                    why do you think this is not optimal? I don't see much space for improvements.

                    Best,
                    -Niklas

                    It seems a lot of code. I was hoping there was something as the Link Gui.
                    E.g. self.linkCityObject = self.AddCustomGui(MY_CITYLINKBOX, c4d.CUSTOMGUI_LINKBOX, "", c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT, 0, 0)

                    Originally posted by xxxxxxxx

                    Ah, I really wondered why everyone was talking about the "time" module.. 😄
                    But then he had to write "from datetime import datetime".

                    Yes, you are correct. Using "from datetime import datetime" is enough, no need for time.

                    Thanks for all the comments.
                    Regards, Pim

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