Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

load resources from a folder inside my plugin folder?

load resources from a folder inside my plugin folder?

Anonymous
Not applicable
676 Views
3 Replies
Message 1 of 4

load resources from a folder inside my plugin folder?

Anonymous
Not applicable

Good evening,

 

I'm shortly before releasing my plugin for everyone. I have created a folder named Circlelizer. In that folder, I have other folders called "html", "resources" and "themes". So how do I reference them correctly within my plugin?  I could just place all the resources etc. inside a Maya folder but I don't want to mix those files. It also doesn't look clean for me. 

 

So my structure looks like this: 

 

Circlelizer

  • html
  • resources
  • themes
  • circlelizer.py

 

So If I load the plugin while the folder is let's say on my desktop, the working directory is .../maya/bin. If I now would reference my resources inside my script like /resources/image.png it would immediately throw an error message.

 

Regards,

 

Life

 

 

 

0 Likes
Accepted solutions (1)
677 Views
3 Replies
Replies (3)
Message 2 of 4

cheng_xi_li
Autodesk Support
Autodesk Support
Accepted solution

Hi LifeArtist,

 

You can use MFileObject to get files from a relative path to the plugin folder. Like below:

 

	MString testLocation("./testFolder/test.txt");

	MFileObject fileObject;
	fileObject.setRawFullName(testLocation);
	fileObject.setResolveMethod(MFileObject::kRelative);

Yours,

Li

0 Likes
Message 3 of 4

Anonymous
Not applicable

Thanks! It worked perfectly for me. I forgot to mention that I am developing using python.

 

So the correct code for python would be:

 

path = "themes/default-theme.qss"

fileObject = om.MFileObject()
fileObject.setRawFullName(path)
print(fileObject.resolvedFullName())

In case another one needs it for python 😉

 

 

 

Regards,

 

Life

0 Likes
Message 4 of 4

Anonymous
Not applicable
And of course you need to add:

fileObject.resolveMethod = om.MFileObject.kRelative
0 Likes