setup dictionary after save as
Copy link to clipboard
Copied
Hello everyone,
I try to fill some document dictionary values after a "save as" action, and that fails.
My process (CS5 yes CS5!, Windows):
- open a template OK
- save as document (new name and location) via actions OK
- add artboards OK
- fill dictionary values FAIL (even skips the instruction in the debugger)
Exception non gérée à 0x008D74B1 dans Illustrator.exe : 0xC0000005 : Violation d'accès lors de l'écriture à l'emplacement 0xE032B50E.
when executing :
AIDictionaryRef theDictionary = NULL; | ||
sAIDocument->GetDictionary(&theDictionary); |
Any clue? is there a current document after a save as action?
Thanks
Christian
Explore related tutorials & articles
Copy link to clipboard
Copied
Maybe its a timing thing. Where are you doing the dictionary saving? Are you reacting to a notifier? If not, try responding to the kAIMetadataSyncNotifier notifier and doing it there.
Copy link to clipboard
Copied
Thanks for answering,
I was trying towrite into the document dictionary at different places, with and without notifiers (docchange, action complete,, etc..), including your suggestion kAIMetadataSyncNotifier
My subroutine is as follows
void ecrireChaineDansDicoDoc(const char* name, char * value)
{
AIErr error;
AIDictionaryRef dictionary = 0;
AIAppContextHandle context = 0;
SPPluginRef pluginRef; // this needs to be picked up and stored from one of your load messages
pluginRef = gPluginRef;
// plus de mal que de bien worse than better
// error = sAppContext->PushAppContext(pluginRef, &context);
error = sAIDocument->GetDictionary(&dictionary);
// check error
if (dictionary)
{
AIDictKey key = sAIDictionary->Key(name);
error = sAIDictionary->SetStringEntry(dictionary, key, value);
// check error
sAIDictionary->Release(dictionary);
}
It hangs on the SetStringEntry instruction.
Any clue?
Copy link to clipboard
Copied
Not sure, but I'd also make sure to check the returned error value from
error = sAIDocument->GetDictionary(&dictionary);
Just to make sure to catch unmet assumptions (i.e. I think you're assuming that if the call fails, dictionary will be NULL. That assumption is probably correct, but I would not bet on it, and I'd check the error code first).
Often the error codes have valuable info in them. For myself, I've compiled a list of various error codes by GREP-ping the SDK folder, which I found very useful. I am not sure whether there is a proper list available somewhere - I haven't found it, but I also haven't looked very hard.
Copy link to clipboard
Copied
I do check (via the debugger) that err is set to 0, and the dictionaryRef is not NULL.
Maybe the call to SetStringEntry is badly written? (but I do not see the mistake).
Copy link to clipboard
Copied
I don't see anything wrong with your code, particularly the SetStringEntry. I use the unicode version, but there's no reason the non-unicode version shouldn't work (they're still fully supported). That it hangs is very strange, and a shame -- an error code would at least tell us something. That said, a hang usually indicates that one of the parameters is horribly wrong in some way. You look like you're checking the dictionary ref correctly, presumably there's nothing wrong with the value or the key?
Copy link to clipboard
Copied
for the value and the key, I have tried something like SetStringEntry(doc, sAIDictionary->Key("test"),"test"), without success!
Is the appcontext importatnt in this case?
Copy link to clipboard
Copied
The app context is only necessary if you're not responding to a message from Illustrator in some way; if you are, the context will already be set. You said you were doing this in a variety of places, so its possible one or more of them might require an app context, though usually when that's the problem you don't get a hang, you get a strange error result from an API call.
Copy link to clipboard
Copied
finally, it worked by putting the write into the kAIDocumentChangedNotifier notification, which I receive twice on my saveas procedure (?).
Thanks for your help.