<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Extract/save textures from materials using python? in VRED Forum</title>
    <link>https://forums.autodesk.com/t5/vred-forum/extract-save-textures-from-materials-using-python/m-p/11231700#M2128</link>
    <description>&lt;P&gt;In the material editor there is a nifty little feature to Save Texture that allows you to extract an embedded texture file from the .vpb file. But I would like to do this via script instead on all materials in my scene, is that possible?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the Node Editor I can see the path for the textures but that path is usually a local path that I don't have access to, so I can't copy the texture from there. I've also tried exporting the scene as an .fbx file, but that only extracts some of the texture and that is a problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So is there a way to extract all the textures (diffuse, normal, specular, etc.) via script? Is this, or will it be, possible with the new material API in VRED 2023 or can it be done in previous versions (e.g. 2021.3) of VRED as well?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Jun 2022 14:07:41 GMT</pubDate>
    <dc:creator>KristofferHelander</dc:creator>
    <dc:date>2022-06-13T14:07:41Z</dc:date>
    <item>
      <title>Extract/save textures from materials using python?</title>
      <link>https://forums.autodesk.com/t5/vred-forum/extract-save-textures-from-materials-using-python/m-p/11231700#M2128</link>
      <description>&lt;P&gt;In the material editor there is a nifty little feature to Save Texture that allows you to extract an embedded texture file from the .vpb file. But I would like to do this via script instead on all materials in my scene, is that possible?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the Node Editor I can see the path for the textures but that path is usually a local path that I don't have access to, so I can't copy the texture from there. I've also tried exporting the scene as an .fbx file, but that only extracts some of the texture and that is a problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So is there a way to extract all the textures (diffuse, normal, specular, etc.) via script? Is this, or will it be, possible with the new material API in VRED 2023 or can it be done in previous versions (e.g. 2021.3) of VRED as well?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2022 14:07:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vred-forum/extract-save-textures-from-materials-using-python/m-p/11231700#M2128</guid>
      <dc:creator>KristofferHelander</dc:creator>
      <dc:date>2022-06-13T14:07:41Z</dc:date>
    </item>
    <item>
      <title>Re: Extract/save textures from materials using python?</title>
      <link>https://forums.autodesk.com/t5/vred-forum/extract-save-textures-from-materials-using-python/m-p/11232225#M2129</link>
      <description>&lt;P&gt;Without looking into it, I´m pretty sure it is possible with the API in 2023. But the "Save texture" in the material does also work for multiple selected materials now, asking for a folder and saving the image name and format comes that is shown in the path. So, not sure how often you must repeat this but selecting all materials and saving the diffuse-, glossy-, roughness- etc. textures for your selection ...the GUI way... is probably faster than writing a script.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2022 17:41:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vred-forum/extract-save-textures-from-materials-using-python/m-p/11232225#M2129</guid>
      <dc:creator>seiferp</dc:creator>
      <dc:date>2022-06-13T17:41:16Z</dc:date>
    </item>
    <item>
      <title>Re: Extract/save textures from materials using python?</title>
      <link>https://forums.autodesk.com/t5/vred-forum/extract-save-textures-from-materials-using-python/m-p/11236004#M2130</link>
      <description>&lt;P&gt;It is far to many materials and textures to do it manually, it has to be done with script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looking into the documentation for the&amp;nbsp;vrMaterialService in VRED 2023 I can't find any function for saving or extracting textures?&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.autodesk.com/view/VREDPRODUCTS/2023/ENU/?guid=VRED_Python_Documentation_Python_API_V2_class_vrMaterialService_html" target="_blank"&gt;https://help.autodesk.com/view/VREDPRODUCTS/2023/ENU/?guid=VRED_Python_Documentation_Python_API_V2_class_vrMaterialService_html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How is it done?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 07:34:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vred-forum/extract-save-textures-from-materials-using-python/m-p/11236004#M2130</guid>
      <dc:creator>KristofferHelander</dc:creator>
      <dc:date>2022-06-15T07:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: Extract/save textures from materials using python?</title>
      <link>https://forums.autodesk.com/t5/vred-forum/extract-save-textures-from-materials-using-python/m-p/11236256#M2131</link>
      <description>&lt;P&gt;Here is a script that writes all texture in the scene to "c:\vred-snapshots":&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;import os
def saveImage(image, newPath, doNotOverwriteFiles):
    path = image.getAbsolutePath()        
    newFileName = newPath + os.path.basename(path)
    # making sure that existing images are not
    if doNotOverwriteFiles:
        i = 0
        while os.path.exists(newFileName):
            i = i + 1
            newFileName = newPath + str(i) + "_" + os.path.basename(path)    
    # save image
    vrImageService.saveImage(image, newFileName)
def collectImages():
    images = []
    # collect all materials
    mats = vrMaterialService.getAllMaterials()
    handledImages = set()
    for mat in mats:
        # get all materials from texture
        textures = mat.getTextures()
        for texture in textures:
            image = texture.getImage()
            imageId = image.getObjectId()
            # only collect each image once
            if image.isValid() and not imageId in handledImages:
                images.append(image)
                handledImages.add(imageId)
    return images            
# giving the second parameter True or False, to save
doNotOverwriteFiles = True
for image in collectImages():
    saveImage(image, "c:/vred-snapshots/", doNotOverwriteFiles)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 15 Jun 2022 09:41:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vred-forum/extract-save-textures-from-materials-using-python/m-p/11236256#M2131</guid>
      <dc:creator>markus_keller</dc:creator>
      <dc:date>2022-06-15T09:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: Extract/save textures from materials using python?</title>
      <link>https://forums.autodesk.com/t5/vred-forum/extract-save-textures-from-materials-using-python/m-p/11236273#M2132</link>
      <description>&lt;P&gt;Or as a one-liner if you want to save a specific texture (diffuse for example):&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;mat.getDiffuseTexture().getImage().toQImage().save("e:\\test.png")&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 09:48:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vred-forum/extract-save-textures-from-materials-using-python/m-p/11236273#M2132</guid>
      <dc:creator>markus_keller</dc:creator>
      <dc:date>2022-06-15T09:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: Extract/save textures from materials using python?</title>
      <link>https://forums.autodesk.com/t5/vred-forum/extract-save-textures-from-materials-using-python/m-p/11236668#M2133</link>
      <description>Is this for 2023 as well? I tried it in 2021.3 on a UPlasticMaterial but I get the error message:&lt;BR /&gt;"AttributeError: 'vrMaterialPtr' object has no attribute 'getDiffuseTexture'"&lt;BR /&gt;Do I need to convert the material node or something? I did it like this:&lt;BR /&gt;mat = getSelectedNode().getMaterial()&lt;BR /&gt;mat.getDiffuseTexture().getImage().toQImage().save("c:\\temp\\test.png")</description>
      <pubDate>Wed, 15 Jun 2022 12:45:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vred-forum/extract-save-textures-from-materials-using-python/m-p/11236668#M2133</guid>
      <dc:creator>KristofferHelander</dc:creator>
      <dc:date>2022-06-15T12:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: Extract/save textures from materials using python?</title>
      <link>https://forums.autodesk.com/t5/vred-forum/extract-save-textures-from-materials-using-python/m-p/11236694#M2134</link>
      <description>&lt;P&gt;The script is for the 2023 v2 API&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 12:53:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vred-forum/extract-save-textures-from-materials-using-python/m-p/11236694#M2134</guid>
      <dc:creator>seiferp</dc:creator>
      <dc:date>2022-06-15T12:53:25Z</dc:date>
    </item>
    <item>
      <title>Re: Extract/save textures from materials using python?</title>
      <link>https://forums.autodesk.com/t5/vred-forum/extract-save-textures-from-materials-using-python/m-p/11290399#M2135</link>
      <description>&lt;P&gt;I just gave this a go and it looks like it is working nicly - thank you! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2022 19:00:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vred-forum/extract-save-textures-from-materials-using-python/m-p/11290399#M2135</guid>
      <dc:creator>KristofferHelander</dc:creator>
      <dc:date>2022-07-11T19:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: Extract/save textures from materials using python?</title>
      <link>https://forums.autodesk.com/t5/vred-forum/extract-save-textures-from-materials-using-python/m-p/13198633#M2136</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;A href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1273663" target="_self"&gt;&lt;SPAN class=""&gt;KristofferHelander&lt;/SPAN&gt;&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how did you make it work? Did you just copy the code into the script editor? Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Dec 2024 10:27:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vred-forum/extract-save-textures-from-materials-using-python/m-p/13198633#M2136</guid>
      <dc:creator>yellowcab</dc:creator>
      <dc:date>2024-12-07T10:27:08Z</dc:date>
    </item>
  </channel>
</rss>

