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
    • Recent
    • Tags
    • Users
    • Login

    Export Camera Coordinates

    Scheduled Pinned Locked Moved PYTHON Development
    11 Posts 0 Posters 809 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 16/05/2013 at 08:37, xxxxxxxx wrote:

      please post your existing code or describe your problems specifically (or hire someone if you
      do not have any idea where to start). all your data can be found in the cameras bc. you could
      write a script which searches the documents active selection for cameras with c4datom.checktype()
      and then prints the desired BaseContainer data elements to the console.

      writing a string to a file is pretty simple in python. search the python docs for fileobject.

      with open(myFilePath, 'w') as f:
      f.write('My fancy Text.\n')

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

        On 16/05/2013 at 11:53, xxxxxxxx wrote:

        I think you can put me in the category of "I don't even know where to start", but looking at the values, they are clearly visible in the UI, so I thought that was a simple task to get them to show ordered in some way.

        I'll try to document myself better, for now I was testing this code:

        import c4d  
        #Welcome to the world of Python  
          
          
        def main() :  
          pos = op.GetMg()  
          FOV = op[c4d.CAMERA_FOCUS]  
          print pos  
          print FOV  
          
        if __name__=='__main__':  
          main()
        

        That give me what I need for the selected object only, but then if I try something like

        import c4d  
        #Welcome to the world of Python  
          
          
        def main() :  
          Camera = c4d.BaseObject(5103)  
          pos = Camera.GetMg()  
          print pos  
          
        if __name__=='__main__':  
          main()
        

        The coordinates have all 0 values.

        So I need to get this working with all the objects in the scene (I can copy only the cameras with target in a blank project to simplify the code), there is some documentation that explain this?

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

          On 16/05/2013 at 13:23, xxxxxxxx wrote:

          it would have taken longer to explain everything, so instead i wote a little script, doing
          more or less what you want. added quite a lot of comments, hope it helps.

          import c4d
          from c4d import storage
            
          def main() :
              data = ['CameraData (Name : Position, FocusDistance, TaregetPosition)\n\n']  # empty list with just the header
              selection = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN) # selected objects in the document -> list
              
              path = c4d.storage.SaveDialog(type = c4d.FILESELECTTYPE_ANYTHING, force_suffix = 'txt') # ask for path
              
              for obj in selection: #loop selection
                  if obj.CheckType(c4d.Ocamera) : # check for cam
                      target = obj[c4d.CAMERAOBJECT_TARGETOBJECT] # get target
                      if target : target = shortVec(target.GetMg().off) # if target is not none get pos
                      # add string name, pos, focus, target.pos
                      data.append('{0} : {1}, {2}, {3}\n'.format(obj.GetName(), 
                                                                 shortVec(obj.GetMg().off), 
                                                                 obj[c4d.CAMERAOBJECT_TARGETDISTANCE],
                                                                 target))
            
              with open(path, 'w+') as f: # save to file
                  for string in data:
                      f.write(string)
            
          # little helper method for a short vector repr
          def shortVec(vector) :
              return '{0},{1},{2}'.format(vector.x,vector.y,vector.z)
            
          if __name__=='__main__':
              main()
          

          edit : codepad version http://codepad.org/o37su6IU

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

            On 16/05/2013 at 14:07, xxxxxxxx wrote:

            Thanks a lot! Really, this will help me.

            I've only to find why the exporter doesn't picks the Target NULL position

            CameraData (Name : Position, FocusDistance, TaregetPosition)  
              
            Camera : 814.368783498,171.015353366,-1053.32218525, 2000.0, None
            

            The Target should be at 0,445.885,215.832, I've tried to put it as a child of the camera, and the camera as a child of it, but none of them seams to work, selecting multiple cameras do work.

            Thanks again.

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

              On 16/05/2013 at 14:19, xxxxxxxx wrote:

              not sure what you do mean with target. a target expression ? the script reads the focus object 
              as target its called CAMERAOBJECT_TARGETOBJECT. to read a target expression tag target
              object you have to get the basetag and read the linked object.

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

                On 16/05/2013 at 14:28, xxxxxxxx wrote:

                Yeah, the Target Tag, I mean the actual NULL object position, but I couldn't get it to work:

                Is it a different Cinema 4D version problem? I'm using R14.

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

                  On 16/05/2013 at 14:33, xxxxxxxx wrote:

                  as i tried to explain in my previous posting, the script does read the focus object of the camera
                  not the target expression. the focus object is called target in c4d.

                  use something like that for reading target expressions instead :

                  http://codepad.org/Dy8Rr5KY

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

                    On 16/05/2013 at 14:41, xxxxxxxx wrote:

                    Now I'm getting:

                    Traceback (most recent call last) :  
                      File "'scriptmanager'", line 33, in <module>  
                      File "'scriptmanager'", line 15, in main  
                    IndexError: string index out of range
                    

                    I had already tried the TARGETEXPRESSIONTAG_LINK and didn't worked (by dragging the Tag on the console to get the actual name)

                    I could also solve this by simply create another camera, rename it Target (to difference it from the Cameras), parent it to the Target NULL, and use the Center to Parent command, then export and I get the data I need

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

                      On 16/05/2013 at 15:39, xxxxxxxx wrote:

                      its has to be tobj = tag[c4d.TARGETEXPRESSIONTAG_LINK] instead of tobj = target[c4d.TARGETEXPRESSIONTAG_LINK]

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

                        On 17/05/2013 at 06:16, xxxxxxxx wrote:

                        Thank you, it works smoothly now.

                        I've edited a little bit your script to get the right formatting and the FOV as an additional parameter

                        import c4d
                            from c4d import storage
                            
                            def main() :
                                data = ['']  # empty list
                                selection = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN) # selected objects in the document -> list
                                
                                path = c4d.storage.SaveDialog(type = c4d.FILESELECTTYPE_ANYTHING, force_suffix = 'txt') # ask for path
                                
                                for obj in selection: #loop selection
                                    if obj.CheckType(c4d.Ocamera) : # check for cam
                                        tag = obj.GetTag(c4d.Ttargetexpression) # get target expression
                                        target = 'None'
                                        if tag:
                                            tobj = tag[c4d.TARGETEXPRESSIONTAG_LINK]
                                            if tobj: target = shortVec(tobj.GetMg().off)
                                        # add string name, pos, focus, target.pos
                                        data.append('{1} {3} {4}\n'.format(obj.GetName(), 
                                                                                   shortVec(obj.GetMg().off), 
                                                                                   obj[c4d.CAMERAOBJECT_TARGETDISTANCE],
                                                                                   target,
                                                                                   obj[c4d.CAMERA_FOCUS]))
                            
                                with open(path, 'w+') as f: # save to file
                                    for string in data:
                                        f.write(string)
                            
                            
                            # little helper method for a short vector repr
                            def shortVec(vector) :
                                return '{0} {1} {2}'.format(vector.x,vector.y,vector.z) 
                            
                            if __name__=='__main__':
                                main()
                        

                        http://codepad.org/2ree0mMM

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