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

Inline text from text into frame

Explorer ,
Jan 15, 2020 Jan 15, 2020

Here's a Peter Kahrel script to create text frame from selected text:

(function(){
  var width = app.selection[0].endHorizontalOffset - app.selection[0].horizontalOffset;
  var frame = app.selection[0].textFrames.add();
  app.selection[0].move (LocationOptions.AFTER, frame.insertionPoints[0]);
  var gb = frame.geometricBounds;
  gb[3] = gb[1]+width
  frame.geometricBounds = gb;
}());

Is it possible to have a script to reverse this situation? So this is the starting point:

Schermata 2020-01-15 alle 18.05.39.png

and this should be the final one:

Schermata 2020-01-15 alle 18.05.55.png

Thanks.

TOPICS
Scripting
1.3K
Translate
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

correct answers 2 Correct answers

Community Expert , Jan 15, 2020 Jan 15, 2020

Hi Kremisi,

yes of course.

 

First select the text that contains the anchored text frames, then run the script code:

// Select the text that contain the anchored text frames:

var selectedText = app.selection[0].texts[0];

var anchoredTextFrames = selectedText.textFrames.everyItem().getElements();
var frameLength = anchoredTextFrames.length;

for( var n=frameLength-1; n >= 0; n-- )
{
	anchoredTextFrames[n].texts[0].move
	( LocationOptions.AFTER , anchoredTextFrames[n].parent.insertionPoints[0] )
...
Translate
Advocate , Jan 17, 2020 Jan 17, 2020

If you are really need to go with object style only, then in first script instead of assigning label apply an object style.

frame.appliedObjectStyle = app.documents[0].objectStyles.item('inlineFrameForCharacter');

And then find object with that object style names and reverse the process:

app.findObjectPreferences = NothingEnum.NOTHING;
app.findObjectPreferences.appliedObjectStyles = 'inlineFrameForCharacter';
var allInlineFrame = app.documents[0].findObject();
for(var i = 0; i < allInlineFrame.l
...
Translate
Community Expert ,
Jan 15, 2020 Jan 15, 2020

Hi Kremisi,

yes of course.

 

First select the text that contains the anchored text frames, then run the script code:

// Select the text that contain the anchored text frames:

var selectedText = app.selection[0].texts[0];

var anchoredTextFrames = selectedText.textFrames.everyItem().getElements();
var frameLength = anchoredTextFrames.length;

for( var n=frameLength-1; n >= 0; n-- )
{
	anchoredTextFrames[n].texts[0].move
	( LocationOptions.AFTER , anchoredTextFrames[n].parent.insertionPoints[0] );
	anchoredTextFrames[n].parent.contents = "";
};

 

Regards,
Uwe Laubender

( ACP )

Translate
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
Explorer ,
Jan 15, 2020 Jan 15, 2020

Uwe,

it runs like a charm! Thank you. Is there a way to select by scripting the text containing the frame, if the frame has an object style? 

Translate
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
Advocate ,
Jan 15, 2020 Jan 15, 2020

Instead while adding these frame, add a script lable for this reverse process.

////////////////////////////////////////////////////////////////////////////////

(function(){
    var width = app.selection[0].endHorizontalOffset - app.selection[0].horizontalOffset;
    var frame = app.selection[0].textFrames.add();
    frame.label = "inlineFrameForCharacter";
    app.selection[0].move (LocationOptions.AFTER, frame.insertionPoints[0]);
    var gb = frame.geometricBounds;
    gb[3] = gb[1]+width
    frame.geometricBounds = gb;
}());

////////////////////////////////////////////////////////////////////////////////

//~      Reverse process

////////////////////////////////////////////////////////////////////////////////

var allStories = app.documents[0].stories;
for(var st = 0; st < allStories.length; st++){
    var textFrames = allStories[st].textFrames;
    for(var tf = 0; tf < textFrames.length; tf++){
        if(textFrames[tf].label == 'inlineFrameForCharacter'){
            textFrames[tf].texts[0].move(LocationOptions.AFTER, textFrames[tf].parent.insertionPoints[0]);
            textFrames[tf].remove();

            textFrames = allStories[st].textFrames;
            tf = -1;
            }
        }
    }

////////////////////////////////////////////////////////////////////////////////

Best

Sunil

Translate
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
Explorer ,
Jan 16, 2020 Jan 16, 2020

Sunil,

I'm not able to see any results running the script! I'm surely doing something wrong... Thanks anyway!

Translate
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
Advocate ,
Jan 16, 2020 Jan 16, 2020

I think you are running entire script altogether.

My post has two script.

1. Peter kahrel's script (which you already have), just added lable to the frames which is getting added to make it inline.

2. Reverse process: which then for reversing whole thing altogether, finding all stories and textframes inside the stories because all are anchored, then checking for the label which we added in first process. If found then move it's text out side and remove that frame.

 

You can apply any choosen object style instead of label on that frame while adding those inline frame.

And find them using find object and reverse that process.

 

I choose label to avoid any kind of object style because I don't want to put effort on creating object style instead assigning a unique label doesn't change anything.

 

P.S. Do not run entire code altogether, they are two different codes.

 

Best

Sunil

Translate
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
Explorer ,
Jan 17, 2020 Jan 17, 2020

Sunil,

I've got the point, if I run your script in a fresh doc, I mean, select the text > perform the 1st script and > perform the second script everything is ok. The problem is that the script runs on text frames created by it, it does not run on text frames with a given object style I can find in a document.

 

So this line:

    if(textFrames[tf].label == 'inlineFrameForCharacter'){

returns a textFrame named 'inlineFrameForCharacter', right? Your script does not recognize the text frames with a (previous) given object style. Maybe the problem is that I do not know what is the difference between label and objectStyle... Thank you again!

Translate
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
Community Expert ,
Jan 17, 2020 Jan 17, 2020

Hi Kremisi,

wrong. Name is a different property.

If an object would be named you would be able to see the name in the Layers Panel.

 

Whereas the label holds the text that you can see with the Scripts Label Panel in InDesign if you e.g. select an object on the page and go to: Window > Utilities > Script Label

 

More on this:

https://helpx.adobe.com/indesign/using/scripting.html

 

Regards,
Uwe Laubender

( ACP )

 

// EDITED

Translate
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
Advocate ,
Jan 17, 2020 Jan 17, 2020

If you are really need to go with object style only, then in first script instead of assigning label apply an object style.

frame.appliedObjectStyle = app.documents[0].objectStyles.item('inlineFrameForCharacter');

And then find object with that object style names and reverse the process:

app.findObjectPreferences = NothingEnum.NOTHING;
app.findObjectPreferences.appliedObjectStyles = 'inlineFrameForCharacter';
var allInlineFrame = app.documents[0].findObject();
for(var i = 0; i < allInlineFrame.length; i){
    allInlineFrame[i].texts[0].move(LocationOptions.AFTER, allInlineFrame[i].parent.insertionPoints[0]);
    allInlineFrame[i].remove();
    app.documents[0].recompose();
    allInlineFrame = app.documents[0].findObject();
    }

Best

Sunil 

Translate
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
Explorer ,
Jan 20, 2020 Jan 20, 2020
LATEST

Thank you Sunil,

that's the perfect solution! Best, K.

Translate
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
Community Expert ,
Jan 16, 2020 Jan 16, 2020

Kremisi said:

Is there a way to select by scripting the text containing the frame, if the frame has an object style?

 

Hi Kremisi,

all doable by scripting. Even giving the script a user interface where you can choose the object style etc.pp.

But, I think, all this is out of the scope of the InDesign User Forum.

 

You could hire a scripter.

Or you could learn how to script and come back with some code, if you are in trouble.

 

Regards,
Uwe Laubender

( ACP )

Translate
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
Explorer ,
Jan 16, 2020 Jan 16, 2020

Yes, you're right! Anyway thanks again, your answer was very precious for me! K.

Translate
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