Skip to main content
panduvittala
Inspiring
March 29, 2013
Answered

AIUID save in dictionary

  • March 29, 2013
  • 1 reply
  • 1325 views

AIUIDRef uidref=GetUID(GetArt(range));

sAIDocument->GetDictionary(&dictRef);

if(dictRef)      {

     AIEntryRef entryref=sAIEntry->FromUID(uidref);

     AIDictKey dictkey = sAIDictionary->Key("mykey");

     sAIDictionary->Set(dictRef, dictkey, entryref);

}

This is the code I am using to save the uid in dictionary. The code executes. Not sure if it saves uid or not. But illustrator crashes when document is closed. Any idea what is wrong?  Thanks in advance.

This topic has been closed for replies.
Correct answer A. Patterson

I think you're missing a step, here's what I'm doing:

SetArtUIDValue(AIDIctionaryRef dictionary, const char* entryName, AIUIDRef uid)

{

     AIEntryRef entry = 0;

     try {

          AIUIDREFRef uidRef = 0;

          AIErr error = sUID->NewUIDREF(uid, &uidRef);

          if (kNoErr != error) throw ai::Error(error);

          AIEntry entry = sEntry->FromUIDREF(uidRef);

          AIDictKey key = sDictionary->Key(entryName);

          error = sDictionary->Set(dictionary, key, entry);

          if (kNoErr != error) throw ai::Error(error);

     } catch (...) {

          if (entry) {

               sEntry->Release(entry);

          }

          throw;

     }

     sEntry->Release(entry); // never forget to do this or you leak memory!

}

1 reply

A. Patterson
A. PattersonCorrect answer
Inspiring
April 1, 2013

I think you're missing a step, here's what I'm doing:

SetArtUIDValue(AIDIctionaryRef dictionary, const char* entryName, AIUIDRef uid)

{

     AIEntryRef entry = 0;

     try {

          AIUIDREFRef uidRef = 0;

          AIErr error = sUID->NewUIDREF(uid, &uidRef);

          if (kNoErr != error) throw ai::Error(error);

          AIEntry entry = sEntry->FromUIDREF(uidRef);

          AIDictKey key = sDictionary->Key(entryName);

          error = sDictionary->Set(dictionary, key, entry);

          if (kNoErr != error) throw ai::Error(error);

     } catch (...) {

          if (entry) {

               sEntry->Release(entry);

          }

          throw;

     }

     sEntry->Release(entry); // never forget to do this or you leak memory!

}

panduvittala
Inspiring
April 1, 2013

Thanks, that worked.