How to load a text-resource from a bundle (Plugin)

Aya Koshigaya Aya at animes.de
Fri Dec 28 17:46:26 PST 2007


Hi,

I have developed a plugin for Autodesk Maya for Windows. I now want to  
port this plugin to OSX.. and here i have some problems :(

I opened one of the Maya-ExamplePlugins in xCode and then just  
replaced all the files with my own. So far, no problem.. but I'm using  
some resources that I included to my plugin.

In Windows I used the WinAPI functions "FindResource" and  
"LoadResource".. and here's the problem, I have no idea how to port  
this to osx.

In xCode I added my Resource (It's a textfile "data.txt") and put it  
in the Resources-Folder so it will be copied to the bundle when  
building.

I now tried to load the file via Cocoa:
NSString *nsResource = [[NSBundle mainBundle]pathForResource:@"data"  
ofType:@"txt"];

But the resource wasn't found, I found out, the problem is  
"mainBundle" is the Maya-Bundle, not my plugin...


After this I tried to find my bundle, but with no result.. :(
When  I use this:
[NSBundle bundleForClass:[self class]];

I get a compile-error that says "self is undeclared", because my  
plugin is still written in C, not ObjC... and I'm using the ObjC  
functions inside my normal C-functions = no self.

Next try was:
[NSBundle bundleWithIdentifier:@"de.koshigaya.test"];

the result was NULL.. no bundle with this identifier was found :(

As last thing I tried to list ALL bundles and see if my own one is  
found with this:

	NSArray *bundles = [NSBundle allBundles];
	for (int i = 0; i < [bundles count]; i++) {
		NSBundle *b = [bundles objectAtIndex:i];
		NSString *vident = [b bundleIdentifier];
		printOut([vident UTF8String]);
	}

and... It only listed ONE bundle.. the same as "mainBundle".. ->  
com.alias.Maya.2008

So... no I have no idea what to do more.. I'm totally helpless..
Maybe Maya isn't realy "loading" my Bundle..? I mean, maybe Maya uses  
a way to load the bundle so it's not registered or something.. don't  
know.. :/

Does anyone know what I can do? Help...

Kind regards,
  Aya


More information about the MacOSX-dev mailing list