How to Force relative path with python with setAttr in .filename ?

How to Force relative path with python with setAttr in .filename ?

tomp.jar
Explorer Explorer
1,613 Views
7 Replies
Message 1 of 8

How to Force relative path with python with setAttr in .filename ?

tomp.jar
Explorer
Explorer

Hi, I try to write relative path with cmds.setAttr(diff + '.filename', './sourceimages/image.png', type = 'string')

But the string is always automatically replaced by the full path (E:// etc)

 

Any idea of whats wrong ? 

0 Likes
Accepted solutions (1)
1,614 Views
7 Replies
Replies (7)
Message 2 of 8

Kahylan
Advisor
Advisor

Hi!

 

What kind of node do you want to set this attr on?

It looks like you want to set a texture, but the nodes that use texture paths I know all use either ".imageTextureName" or ".imageName"

 

It would be helpful if I knew the exact node type you are talking about, so I can reproduce the issue.

0 Likes
Message 3 of 8

tomp.jar
Explorer
Explorer

Hey thanks for the answer, the node is a PxrTexture; also I made an error in the command, it's  cmds.setAttr(diff + '.filename', './sourceimages/'image.png', type = 'string')  were image.png is just a placeholder text for the real image name

 

I also tryed $PROJPATH/sourceimages ... but only the maya viewport understand this way of relative path but renderman give me the pink missing color error

 

thanks !

Message 4 of 8

Kahylan
Advisor
Advisor

Ah ok. Afaik Renderman defines the relative project location as "<ws>"

 

So this command should do what you want:

cmds.setAttr(diff + '.filename', '<ws>/sourceimages/image.png', type = 'string')

 

I hope it helps!

0 Likes
Message 5 of 8

tomp.jar
Explorer
Explorer

Thanks !

I tried but unfortunately, it auto replace also this with the full path as you can see 😞

 

 

tompjar_0-1664819738433.png

 

0 Likes
Message 6 of 8

tomp.jar
Explorer
Explorer

tompjar_0-1664819944200.png

Here is the string that gets input in the filename

 

0 Likes
Message 7 of 8

Kahylan
Advisor
Advisor
Accepted solution

I see, sorry I wasn't at my workingmachine and couldn't try it out myself. Now I had the chance, but I didn't find a way to stop the PxrTexture from automatically changing the path from relative to absolute when setting the filepath, neither with python or by setting it by hand... However, I found a way to force renderman to keep the path relative.

I created a network node and added a string attribute to it, then I set the string to "<ws>/sourceimages/image.png" and connected it to the PxrTexture nodes filename attribute:

ntw = cmds.createNode("network")
cmds.addAttr(ntw, ln = "localString", dt = "string")
cmds.setAttr("{0}.localString".format(ntw), '<ws>/sourceimages/image.png', type = "string")


cmds.connectAttr("{0}.localString".format(ntw),'{0}.filename'.format(diff), f = True)

 

It's not pretty, but it seems to work, since a normal string attribute doesn't know what a path is and has no ambitions to override any characters and the filename attribute gets automatically locked when there is a connection on it.

 

But I also should mention, that I haven't used Renderman in quite some time and there probably is a better way of doing this that someone knows who uses it frequently.

 

Anyway, I hope it helps!

 

Message 8 of 8

tomp.jar
Explorer
Explorer
Thanks you very much ! This will do the trick for sure ! If I somehow discover a way to force it directely in the pxrtexture I'll send an update here !

Thanks you once again !
0 Likes