Copy link to clipboard
Copied
I have text handle (myTextHandle) and I'm trying to select text programatically, but the following does not help
sAIArt->SetArtUserAttr(myTextHandle, (kArtFullySelected | kArtSelected), (kArtFullySelected | kArtSelected));
Is there a way to select text art, not textReange programatically?
Calling sAIDocument->SyncDocument(); before sAIArt->SetArtUserAttr helped to solve the issue.
Copy link to clipboard
Copied
Hi Syuzie, maybe you're looking for something more specific than this, but here's how I select all text objects.
AIErr error = noErr;
AIArtHandle **matches;
long count;
long i;
long attributes;
AIBoolean isEditable, isVisible;
AILayerHandle layer = nil;
error = unselect_selection();
if (error) goto error;
error = get_text_objects( &matches, &count );
if (error) goto error;
for ( i = 0 ; i < count ; i++ ) {
error = sAIArt->GetLayerOfArt( (*matches)[i], &layer );
if ( (error) || ( !layer ) ) goto error; // if no next layer, split
error = sLayer->GetLayerEditable( layer, &isEditable );
if (error) goto error;
if ( !isEditable )
continue;
error = sLayer->GetLayerVisible( layer, &isVisible );
if ( error ) goto error;
if ( !isVisible )
continue;
error = sAIArt->GetArtUserAttr( (*matches)[i], kArtLocked | kArtHidden, &attributes);
if ( error ) goto error;
if ( attributes )
continue;
error = sAIArt->SetArtUserAttr( (*matches)[i], kArtSelected, kArtSelected );
}
return kNoErr;
error:
return error;
Copy link to clipboard
Copied
Thanks for the answer Rick, but setting kArtSelected doesn't work for me. I'm not sure is it related or no, my text is created as point text and is in the group.
Copy link to clipboard
Copied
I think I may see the problem. Are you calling it this way?
sAIArt->SetArtUserAttr(myTextHandle, (kArtFullySelected | kArtSelected), (kArtFullySelected | kArtSelected));
I may be wrong, but as I understand it you can check an attribute with GetArtUserAttr and (kArtFullySelected | kArtSelected) (OR'ing the two states, which gives a binary result that's not the same as either of the values you OR'ed), but you must choose one or the other when setting the attribute. I'd use only kArtSelected to set the attribute. If you use kArtSelected on a group or other art that has child art, all child art should become selected (fully selected) as well.
Please try it using only kArtSelected. I may have been doing it wrong for the last 30 years, but it's been working for me.
Copy link to clipboard
Copied
It is really strange kArtSelected attribute value is 1 but it is actually not selected. Probably something wrong in my plugin
Copy link to clipboard
Copied
Calling sAIDocument->SyncDocument(); before sAIArt->SetArtUserAttr helped to solve the issue.