• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Getting current insertion point of selection

Explorer ,
Sep 07, 2021 Sep 07, 2021

Copy link to clipboard

Copied

I'm trying to change the text size of the currently selected text frame(s). This works fine if a certain range of text is selected or if a full text frame is selected, but I'm running into issues if the currently selected text is empty, i.e. when there is an insertion point. (In that case the full text frame size should be changed.)

If the cursor is at a certain position inside a text frame without any selection Illustrator will return an invalid range of text. Getting any property of this selection will give an "Invalid range" error. Even getting the class of the current selection.

tell application id "com.adobe.illustrator"

    set selectedItems to selection of current document

    set selectedClass to class of selectedItems
    -- if current selection is an insertion point this will throw an error
    -- "Adobe Illustrator got an error: Invalid range."

    if selectedClass is text then
        -- user selected a text range
    	set size of selectedItems to 26
    else 
        -- user selected text frames
        repeat with selectedItem in selectedItems
            set size of selectedItem to 26
        end repeat
    end if
end tell

 

Is there anyway I can determine if the current selection is an insertion point, such that I can target the container text frame instead to set the point size of the entire container?

 

According to the Illustrator Applescripting guide: "When there is an active insertion point in the contents of a text frame, selection returns a reference to the insertion point." Instead it returns something like:

text from character 2 to character 1 of story 1 of document 1

Which has an incorrect range.

TOPICS
Scripting

Views

110

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation
Adobe