Community
Maya Forum
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to create file path attribute in maya using Python API

2 REPLIES 2
Reply
Message 1 of 3
subing85
220 Views, 2 Replies

How to create file path attribute in maya using Python API

I want to create a new attribute to set the file path, for example in the file node attribute called "fileTextureName". 

 

subing85_0-1654181044302.png

 

 

I tried to swap from file node fileTextureName to one transform node,  I am looking for better way to create file path attribute.

 

This is the experiment source code

 

from maya import OpenMaya

 

node = "locator1"
attribute = "file1.fileTextureName"


# get the mobject from locator1
mselection = OpenMaya.MSelectionList()
mselection.add(node)
mobject = OpenMaya.MObject()
mselection.getDependNode(0, mobject)

 

# get the plug from file1.fileTextureName
mplug = OpenMaya.MPlug()
mselection = OpenMaya.MSelectionList()
mselection.add(attribute)
mselection.getPlug(0, mplug)

 

# add the attribute to locator1
depNode = OpenMaya.MFnDependencyNode(mobject)
depNode.addAttribute(mplug.attribute())

 

Anyone helps, that should be appreciable.

Tags (1)
2 REPLIES 2
Message 2 of 3
subing85
in reply to: subing85

I got the solution for this, just ignore my question

Message 3 of 3
zewt
in reply to: subing85

It's always nice to mention what the solution was, since other people also searching for it will find this question--and be frustrated when it just says "nevermind got it" without giving any more info 🙂

 

(The answer was probably using MFnAttribute::setUsedAsFilename to mark the attribute as a filename)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report