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

    Pause for user input

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 371 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

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 13/06/2012 at 11:33, xxxxxxxx wrote:

      Is there a way to have Python pause for user input and then act on that input?

      For example I would like to start a script, press a number, then a comma, then another number and then 'shift' to set the render frame range.  Maybe not the most useful example, but you get the idea.

      Here is a bit of code to look for the shift part, but I still don't know how to capture the number input first:

      # Check for modifier keys
          bc = c4d.BaseContainer()
          if c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD,c4d.BFM_INPUT_CHANNEL,bc) :        
              if bc[c4d.BFM_INPUT_QUALIFIER] & c4d.QSHIFT:
                  shiftMod=1
          if shiftMod==1:
      .....

      I would also like to start a script, get the current snap settings, let the user create a two point spline, then use that splines point data to print out a distance measure, and finally delete the spline.  This would make a quicker measure tool.

      I'm starting to be fairly proficient at manipulating the data with Python, but am falling short at interactivity with the user.  Anyone?

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

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 14/06/2012 at 10:54, xxxxxxxx wrote:

        The Py4D Console in Cinema 4D is only for stdout and does not accept input while running a script. You
        can however use a dialog for this. There are built-in methods that show various dialogs.

        import c4d  
        input = c4d.gui.InputDialog()
        

        I don't know if it's a bug, but you will not be able to recognize when the user clicks 'Cancel' on this
        dialog. Just cancel your script if the user enters nothing.

        import c4d  
          
        def main() :  
          input = c4d.gui.InputDialog()  
          if not input:  
              c4d.gui.MessageDialog("Script canceled.")  
              return # actually only necessary if code follows this if-clause  
          else:  
              c4d.gui.MessageDialog("You've entered: %s" % input)  
          
        main()
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 14/06/2012 at 12:09, xxxxxxxx wrote:

          Thanks Nik.  I have been learning about dialogs today and have run a couple scripts that hung C4D because of no 'cancel' button.  Maybe it's because I'm using R12?  I will be using your 'cancel' code.  Anyways I'm currently struggling with trying to make tabs such as with:

          import c4d
          from c4d import gui
            
          def main() :
           
          gui.GeDialog.TagGroupBegin(id=5670,BFH_LEFT[,tabtype=TAB+TABS])
            
          if __name__=='__main__':
              main()
          

          I know that I'm missing some important code to initialize the tabbed dialog, but since I'm a beginner, I'm not sure what.  Do you suggest looking into the C++ SDK for more info?  Edit:  I'm checking out the SDK now trying to figure out how to translate the C++ code to Python.  Are there any resources for learning to do this that you know of?

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

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 15/06/2012 at 07:15, xxxxxxxx wrote:

            Hi visualride,

            What do you mean with "no cancel button"? I guess you are using a Mac? May you post a screenshot of the dialog that does not own a cancel button, please?

            So, you want to make your own dialog?

            There are some examples in the SDK that should at least give you a hint how to use it. There are also various posts on the forum on dialogs. Here is a little example:

            # author: Niklas Rosenstein <[email protected]>  
              
            import c4d  
              
            class InputDialog(c4d.gui.GeDialog) :  
              
              INPUT = 10000  
              BTNOK = 10001  
              BTNCNCL = 10002  
              
              def __init__(self, title=None, input_text=None) :  
                  self.title = title or "User Input"  
                  self.input_text = input_text or ""  
                  self.result = None  
              
              def CreateLayout(self) :  
                  FULLFIT = c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT  
              
                  self.AddEditText(self.INPUT, FULLFIT)  
                  self.GroupBegin(0, FULLFIT)  
                  self.AddButton(self.BTNOK, FULLFIT, name="OK")  
                  self.AddButton(self.BTNCNCL, FULLFIT, name="Cancel")  
                  self.GroupEnd()  
              
                  return True  
              
              def InitValues(self) :  
                  self.SetTitle(self.title)  
                  self.SetString(self.INPUT, self.input_text)  
                  return True  
              
              def Command(self, id, msg) :  
                  if id == self.BTNOK:  
                      close = True  
                      self.result = self.GetString(self.INPUT)  
                  elif id == self.BTNCNCL:  
                      close = True  
                      self.result = None  
                  else:  
                      close = False  
              
                  if close:  
                      self.Close()  
              
                  return True  
              
            def open_input_dialog(default=None, title=None, width=200) :  
              dialog = InputDialog(title, default)  
              dialog.Open(c4d.DLG_TYPE_MODAL, defaultw=width)  
              return dialog.result  
              
            def main() :  
              value = open_input_dialog("Enter Text.",  
                                        "I'm waiting for your input.")  
              
              if value is None:  
                  print "Cancelled."  
              else:  
                  print "Input:", value  
              
            main()
            
            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 15/06/2012 at 15:32, xxxxxxxx wrote:

              Thanks Niklas.  This will be a big help.  I haven't found those snippets of code that I used yesterday that brought up a dialog with the 'cancel' and 'minimize' buttons greyed out, but since it happened more than once I assume it was because of my version (R12) or that the code was written on a PC (I am using a Mac).  If I do come across it again I will post it.

              As I'm learning (I started sporadically about a month ago) I gain many more questions than I answer but it is fun, and hopefully it will even be practical soon.

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