3 Replies Latest reply on Jun 20, 2017 5:41 AM by A. Patterson

    Storing ITextRange/TextRangeRef in dictionary

    alam_84 Level 1

      HI All,

       

      Is it possible to store selected text range reference i.e TextRangeRef in a dictionary? It would  help me if some one can explain this with a code snippet.

       

      I tried following to get UIDRef but api GetUID complains type mismatch error

      ====

      AIUIDRef uidref;

      sUIDRef->GetUID(textRange.GetRef(), &uidref);

      ====

       

       

      I have found same unanswered query at https://forums.adobe.com/message/5182873#5182873

       

       

       

      Regards,

      Alam

        • 1. Re: Storing ITextRange/TextRangeRef in dictionary
          A. Patterson Level 4

          Unanswered? I answered all the questions in that thread!

           

          It does sound like you're interested in the same thing, why exactly don't the answers I posted there work for your situation?

          • 2. Re: Storing ITextRange/TextRangeRef in dictionary
            alam_84 Level 1

            Thanks Patterson for quick reply

             

            I see your replies in that thread but you have explained getting art uidRef from textRange

            ===

            AIArtHandle GetArt(ATE::ITextRange range)

            {

                 ATE::ITextFramesIterator iter = range.GetTextFramesIterator();

                 AIArtHandle result = 0;

             

                 if (!iter.IsEmpty()) {

                      ATE::ITextFrame frame = iter.Item();

                      AIErr error = sAITextFrame->GetAITextFrame(frame.GetRef(), &result);

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

                 }

             

                 return result;

            }

            ===

             

            in above code you had explained of getting art UIDRef from textRange but I need the example that will store textRange UIDRef.

            • 3. Re: Storing ITextRange/TextRangeRef in dictionary
              A. Patterson Level 4

              You need to combine that code with the earlier post in the thread:

               

              AIUIDRef GetId(AIArtHandle handle, bool forceCreate = true)
              {
                   AIUIDRef result = 0;
                  
                   // forceCreate causes the art to generate an id, if it doesn't already have one; this can cause an undo & the document to become modified, so be careful
                   AIErr error = sUIDUtils->GetArtUID(handle, forceCreate ? 1 : 0, &result);
                   if (kNoErr != error) throw ai::Error(error);
              
                   return result;
              }
              
              AIArtHandle GetHandle(AIUIDRef uid)
              {
                   AIUIDREFRef uidRef;
                   AIErr error = sUID->NewUIDREF(uid, &uidRef);
                   if (kNoErr != error) throw ai::Error(error);
                  
                   AIArtHandle result = 0;
                  
                   error = sUIDUtils->GetReferencedArt(uidRef, &result);
                   if (kNoErr != error) throw ai::Error(error);
              
                   // if the art referenced by uid no longer exists result will be 0
              
                   sUIDRef->Release(uidRef);
              
                   return result;
              }
              

               

              Then, like so:

               

              AIArtHandle handle = GetArt(textRange);
              AIUIDRef uid = GetId(handle);
              

               

              There's no such thing as getting an AIUIDRef for a text range directly. Only AIArtHandles can have AIUIDRefs, but fortunately all text ranges have an associated AIArtHandle.