Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.