How to get the full texture path using python?

How to get the full texture path using python?

kristoffer.helander
Explorer Explorer
1,359 Views
6 Replies
Message 1 of 7

How to get the full texture path using python?

kristoffer.helander
Explorer
Explorer

If I select a material in the material editor and look for the path to one of it's texture I see a relative path like this:

../../../../path/to/texture/subfolder/texture_bump.png

I tried to access the path using this script

mat = findMaterial("myMaterial")
image = vrFieldAccess(mat.fields().getFieldContainer("bumpMap"))
print image.getString("name")

but it generates the same output.

../../../../path/to/texture/subfolder/texture_bump.png

How do I get the full path? Even if it is a network path? Something like this:

N:\path/to/texture/subfolder/texture_bump.png

or this:

\\netdrv/path/to/texture/subfolder/texture_bump.png

I know that VRED sees the full path because the textures are rendering properly in the viewport.

 

0 Likes
Accepted solutions (1)
1,360 Views
6 Replies
Replies (6)
Message 2 of 7

Christian_Garimberti
Advisor
Advisor
Accepted solution

Hi,

have you tried this?

 

from os.path import abspath

filename = abspath('../../mypath/myfile.txt')

print(filename)

 

every ../ should be a folder a step up from the current vpb file location

 

Best

Chris

Christian Garimberti
Technical Manager and Visualization Enthusiast
Qs Informatica S.r.l. | Qs Infor S.r.l. | My Website
Facebook | Instagram | Youtube | LinkedIn

EESignature

Message 3 of 7

michael_nikelsky
Autodesk
Autodesk

While I don´t know how this path was created just note that VRED doesn´t care about the path by default since all textures are inlined. So unless you have explicitly turned the inlining of textures off in the preferences before saving the file VRED will render correctly even if you delete the texture file on disk.



Michael Nikelsky
Sr. Principal Engineer
Message 4 of 7

kristoffer.helander
Explorer
Explorer

Do you mean that the textures are stored inside the .vpb-file? That would explain some of the confusion I've been experiencing that some texture does not show up in the folders that are specified in the material editor after I've copied the .vpb-file to anther directory, yet it was still rendering properly. 

Thank you for pointing that out!

0 Likes
Message 5 of 7

Christian_Garimberti
Advisor
Advisor

Keeping in mind the above considerations, note that the functions i wrote can returns a path that not exists.

Best

Chris

Christian Garimberti
Technical Manager and Visualization Enthusiast
Qs Informatica S.r.l. | Qs Infor S.r.l. | My Website
Facebook | Instagram | Youtube | LinkedIn

EESignature

Message 6 of 7

michael_nikelsky
Autodesk
Autodesk

Yes, by default the textures are always embedded in the vpb so you can easily take the vpb with you and don´t need to care about textures. What is not embedded are HTML files if you use them and image sequences if you have not set the inline sequence option in the material.



Michael Nikelsky
Sr. Principal Engineer
Message 7 of 7

kristoffer.helander
Explorer
Explorer

Thank you for that code it does the job! But as has been pointed out to me, the textures are stored in the scene file so the path is not always correct, especially not if you move the scene file around. But still, you gave me a solution to my problem. Thanks!

0 Likes