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

    Save Project - Missing Assets

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 891 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 27/01/2018 at 09:27, xxxxxxxx wrote:

      Hi guys!

      I'm trying to recreate the "Save Project with Assets" function from menu and I have some doubts about it, here is my actual code:

      import c4d
        
      def get_targetPath() :
          
          targetPath = c4d.storage.SaveDialog()
        
          if targetPath[-4:] == ".c4d":
              targetPath = targetPath[:-4]
          else:
              None   
        
          return targetPath     
        
      def saveProject() :
        
          doc=c4d.documents.GetActiveDocument()
          docpath=doc.GetDocumentPath() #this would be the last path of the get assets function?
          
          targetPath = get_targetPath()
        
          assets=c4d.documents.GetAllAssets(doc, True, docpath) #list of assets to copy
              
          missingAssets = None #list of missing assets
          
          flags = c4d.SAVEPROJECT_ASSETS | c4d.SAVEPROJECT_SCENEFILE | c4d.SAVEPROJECT_DIALOGSALLOWED #collect flags
          
          c4d.documents.SaveProject(doc, flags, targetPath, assets, missingAssets) #do collect, what i need to put in missing assets?
              
          c4d.EventAdd()
          
      if __name__=='__main__':
          saveProject()
      

      -What I need to assign to lastPath before to execute the function "c4d.documents.GetAllAssets(doc, allowDialogs, lastPath)"? 
      -How can I get the missingAssets list for the "c4d.documents.SaveProject(doc, flags, targetPath, assets, missingAssets)" function? Because if I have missing assets from the "GetAllAssets" the function return None and not the missing assets.

      Thanks!

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

        On 29/01/2018 at 06:06, xxxxxxxx wrote:

        Hi,

        actually the "assets" and "missingAssets" parameters of SaveProject() as well as the "lastPath" parameter of GetAllAssets() are output parameters.

        Additionally to the list of assets in parameter "assets" SaveProject() sets missingAssets (e.g. textures not found under the specified path), but only if flag SAVEPROJECT_DIALOGSALLOWED is not set.

        GetAllAssets() will set lastPath to the path chosen by a user, if an asset was missing.

        So, you don't need to call GetAllAssets() before SaveProject(), it is used internally anyway.

        But you need to provide empty lists for these parameters.
        Roughly like so:

            missingAssets = []
            assets = []
            targetPath = "some path"
            res = c4d.documents.SaveProject(doc, c4d.SAVEPROJECT_ASSETS | c4d.SAVEPROJECT_SCENEFILE, targetPath, assets, missingAssets)
        

        We will try to improve (and fix) both C++ and Python API documentation on this topic.

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

          On 04/02/2018 at 08:42, xxxxxxxx wrote:

          Hi Andreas!

          Great, now I understand how work this parameters. And if I set the flag SAVEPROJECT_DIALOGSALLOWED, is there a method to get the missing assets? Because if I set this flag the missing assets appears in the assets list.

          Thanks!

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

            On 05/02/2018 at 04:30, xxxxxxxx wrote:

            I'm afraid, you can't. The logic is probably "if the user decided an asset path is pointing nowhere, then it's no longer missing, but rather deliberately set defunct.

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

              On 05/02/2018 at 06:42, xxxxxxxx wrote:

              Alright, thanks a lot for your help.

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