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

    Creating a Script to Automatically Change Asset File Paths

    Cinema 4D SDK
    2
    2
    565
    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.
    • K
      ktheorin1
      last edited by

      Hi, I work between a Mac and PC and because of this, getting texture paths to work is less than ideal since both OS's don't use the same paths. I can reconnect the paths manually by going into the Project Asset Manager and doing a find and replace. But this can get tedious. Is there a way to automate this process with a script? So that it will detect the OS and change all relevant file locations to the correct ones? I know nothing about coding so any help would be appreciated!

      1 Reply Last reply Reply Quote 0
      • r_giganteR
        r_gigante
        last edited by

        Hi @ktheorin1, thanks for reaching out us and welcome to the Forum.

        To find all the assets in a given scene you can use the BaseDocument::GetAllAssetsNew() which returns you a list of dictionaries with all the assets contained in a document.

        The example below retrieves all the textures in the active document and append the string "_replaced" at the end of it

        def main():
            textures = list()
            
            # execute the GetAllAssetsNew for the current document
            c4d.documents.GetAllAssetsNew(doc, False, "", c4d.ASSETDATA_FLAG_TEXTURESONLY, textures)
            
            for t in textures:
                textureOwner = t["owner"]
                textureURL = maxon.Url(t["filename"])
                
                # get the texture suffix
                textureSuffix =  textureURL.GetSuffix()
                # remove the suffix from the URL
                textureURL.ClearSuffix()
                # replace the name by adding the word "_replaced"
                textureURL.SetName(textureURL.GetName() + "_replaced")
                # set again the suffix to the URL
                textureURL.SetSuffix(textureSuffix)
                
                #update the textureOwner parameter
                textureOwner[c4d.BITMAPSHADER_FILENAME] = textureURL.GetSystemPath()
                
            # notify Cinema about the changes
            c4d.EventAdd()
        

        It's also worthy having a look at the maxon::Url to handy manage the path of the retrieved textures.

        Cheers, R

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