Skip to main content
Dan_Korn
Inspiring
April 10, 2014
Answered

InDesign CC Mac: "Cannot open resource file" popup message when loading a Nib in my plugin

  • April 10, 2014
  • 1 reply
  • 1279 views

We have a fairly simple plug-in to InDesign, which we have been maintaining since the pre-CS days.  We’re porting it to CC now.  Everything is working on both Windows and Mac, with one problem.

The plug-in shows a File Save dialog, which is customized with a couple of extra controls to get additional information from the user about the file being exported.  As far as I know, there’s no way to do this with the InDesign SDK directly, so we do it with platform-specific code and resources.  On Windows, we do this by calling GetSaveFileName in the Windows API and setting a custom .rc resource and “hook” function with OFN_ENABLETEMPLATE and OFN_ENABLEHOOK.  On Mac, up until InDesign CC, we’ve been calling the Carbon function NavCreatePutFileDialog, with an old-style .r file and an event proc handling kNavCBCustomize et al.  This has all worked great for a long time.

However InDesign CC on Mac is 64-bit only, and Carbon won’t work with that.  So, we’ve taken the leap into Cocoa and implemented this with [NSSavePanel setAccessoryView:], where we load a custom NSView from a Nib embedded in our plug-in bundle.  And this works just fine too.  However, when the plug-in code calls [NSNib initWithNibNamed:bundle:], InDesign CC pops up an alert box saying, “Cannot open resource file.”  Yet, the resource (the Nib) is obviously being loaded just fine.  So the user has to dismiss this seemingly spurious alert box before being able to proceed.  Once the alert is dismissed, the NSSavePanel works fine, with our custom NSView.

I can tell that the popup alert is coming from InDesign itself, rather than from some underlying Mac subsystem such as Cocoa, because it has the title “Adobe InDesign” and the dark gray background like the rest of InDesign CC, and the OK button has an orange highlight around it.  It’s clearly not a standard Mac thing like an NSAlert.  And if I make the same calls to [NSSavePanel setAccessoryView:] et al in a standalone application, obviously no such popup is shown.

It seems that somehow our call to load the Nib file is triggering some kind of hook in InDesign.  My guess is that it’s a hook set up for InDesign to load its own resources, which is erroneously hooking into our plug-in’s functionality. 

I’ve tried both of the approaches to loading the Nib file listed here:

http://stackoverflow.com/a/5855561/3207828

And they both work, and the Nib is loaded, and we can get our NSView from it and use it in the NSSavePanel.  But whether we call  [NSNib initWithNibNamed:bundle:], or [NSViewController initWithNibName:bundle:], InDesign CC shows the message box as soon as the call to load the Nib is made.

Why is InDesign CC showing the “Cannot open resource file” message, and how can it be prevented?

Thanks,

Dan

This topic has been closed for replies.
Correct answer Dan_Korn

I figured it out.  The problem was that the plug-in code creates a ResourceEnabler object, which is needed by the older (CS*) versions of the plug-in on Mac to locate  .rsrc resources for the Carbon NavCreatePutFileDialog call with the custom Carbon resource.   I #ifdef'd it out so that the ResourceEnabler object is not created in the 64-bit Cocoa build for CC, and the offending popup message no longer appears.

I do understand why the ResourceEnabler object is needed for Carbon, to bring the plug-in's resources to the top of the resource stack, but I don't completely understand why the presence of the ResourceEnabler object would have any effect on a Cocoa call to [NSNib initWithNibNamed:bundle:], which otherwise works fine.

Note that simply creating the ResourceEnabler object doesn't trigger the popup, even though the plug-in bundle doesn't contain any Carbon resources for it to move to the top of the stack.  It's only when I actually go to load the Nib file that the ResourceEnabler seems to want to involve itself and complain that it can't find something.

So if anyone from Adobe is reading this, I would suggest that you fix the ResourceEnabler functionality so that it doesn't interfere with the loading of Cocoa Nibs.  Perhaps it's best to simply make the ResourceEnabler a no-op in InDesign CC.

1 reply

Dan_Korn
Dan_KornAuthorCorrect answer
Inspiring
April 11, 2014

I figured it out.  The problem was that the plug-in code creates a ResourceEnabler object, which is needed by the older (CS*) versions of the plug-in on Mac to locate  .rsrc resources for the Carbon NavCreatePutFileDialog call with the custom Carbon resource.   I #ifdef'd it out so that the ResourceEnabler object is not created in the 64-bit Cocoa build for CC, and the offending popup message no longer appears.

I do understand why the ResourceEnabler object is needed for Carbon, to bring the plug-in's resources to the top of the resource stack, but I don't completely understand why the presence of the ResourceEnabler object would have any effect on a Cocoa call to [NSNib initWithNibNamed:bundle:], which otherwise works fine.

Note that simply creating the ResourceEnabler object doesn't trigger the popup, even though the plug-in bundle doesn't contain any Carbon resources for it to move to the top of the stack.  It's only when I actually go to load the Nib file that the ResourceEnabler seems to want to involve itself and complain that it can't find something.

So if anyone from Adobe is reading this, I would suggest that you fix the ResourceEnabler functionality so that it doesn't interfere with the loading of Cocoa Nibs.  Perhaps it's best to simply make the ResourceEnabler a no-op in InDesign CC.

Inspiring
September 15, 2014

Dan, Thanks for posting your answer. After porting my Mac CC plug-ins, I had the same message appearing in my dialogs dialogs that used ordered panels. Your answer saved me countless debugging hours. It is always helpful when someone, who solves their own problem, reports the solution. Thanks again.

Dan_Korn
Dan_KornAuthor
Inspiring
September 24, 2014

No problem.  I'm glad my post was helpful.  Of course, it would be even more helpful if someone from Adobe would at least acknowledge what seems to be a bug in InDesign CC, but I'm not holding my breath.