Skip navigation
Currently Being Moderated

Text Range identifier?

Mar 26, 2013 8:50 PM

This is the scenario.

 

I select a text in the doc, then run a command.

The command provides a unique id for the selected text range.

I use that id (may be at later point of time, may be after close/reopen of file) and run another command that selects that range using id and performs some operations.

 

Questions:

 

Is textrange associated with a unique id? (I am guessing yes, atleast internally)

How do I get this id?

Will this id be consistent accross sessions? (even if I close and open the file does it remain same)

 

Thanks!

 
Replies
  • Currently Being Moderated
    Mar 27, 2013 5:16 AM   in reply to Raghav KR

    All art has a handle, but this handle is only safe to refer to during the execution session in which you're running (i.e., starting when you do something and ending when you're done doing that something). The handle may persist, but there's no guarantees.

     

    If you want a much more reliable method, use the AIUIDUtilsSuite in AIUID.h to get the UID for an art. This will modify it, but it lets you use this AIUIDRef to retrieve the handle, if it still exists. If it doesn't you get a NULL handle.

     

    You can store these AIUIDRef values in a dictionary in the document, and the next time you open the document, retrieve them. They will point at the same art (who at this point will DEFINITELY have a different handle). I think that will get you want you need.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 28, 2013 4:38 AM   in reply to Raghav KR

    Here's the basics:

     

    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;

    }

     

    Storing the AIUIDRef is pretty easy, just go look at AIDictionary.h and you'll find the relevant entry APIs.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 28, 2013 6:02 AM   in reply to Raghav KR

    That part's easy

     

    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;

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 1, 2013 7:20 AM   in reply to Raghav KR

    Dictionary entries are stored in the AI file, I don't know the specifics beyond that. I don't believe they're in the XMP. An Illustrator file is a PDF file, but has a huge block of Illustrator-specific binary data -- I think its stored in there. It's 100% in the file though. Note also that the document itself has a dictionary if you're looking for a good place to stash information.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points