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

insert inset in anchored frame

Advocate ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

I cannot find the info on how to insert an Inset into an existing AFrame using ExtendScript. Does anyone have experience with this?

Thanks

Jang

TOPICS
Scripting

Views

1.3K

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

correct answers 1 Correct answer

Mentor , Dec 03, 2014 Dec 03, 2014

Hi Jang,

Here is the solution summed up.

To insert a new inset (that is, a new referenced graphic) into an anchored frame, you need to:

- Deselect all graphic objects in the document, then select just the anchored frame (set frame.GraphicIsSelected=true, all other graphics to false).

- Use doc.Import() in a standard manner, except don't worry about a valid textLocP parameter. Just specify doc.TextRange.beg or null.

The result will be a new referenced graphic as a child of the anchored frame. Note tha

...

Votes

Translate

Translate
Mentor ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

Hi Jang,

I thought you'd rather just fire anyone for even thinking up such an idea (inside joke, apologies to the public!)

I'm not sure exactly what your requirements are, but my assumption is that you need to first insert a text frame, then import the inset into that text frame. Here is a basic function that does that, where insetPath is a fully-qualified path to the inset file. I imagine it could be expanded to account for other variations, like importing a different flow, etc.

function importTextInsetToAFrame(doc, aFrame, insetPath)

{

    if(!doc.ObjectValid() || !aFrame.ObjectValid())

    {

        alert("Document or frame object is invalid.");

        return;

    }

   

    //Create a new text frame in the anchored frame

    var textFrame = doc.NewGraphicObject(Constants.FO_TextFrame, aFrame);

    if(textFrame.ObjectValid())

    {

        //Position and size the text frame to fit the anchored frame, with a two-point

        //buffer on all sides.

        textFrame.LocX = (2 * 65536);

        textFrame.LocY = (2 * 65536);

        textFrame.Width = aFrame.Width - (4 * 65536);

        textFrame.Height = aFrame.Height - (4 * 65536);

    }

    //get the first paragraph in the new frame and

    //set up a text location for the import

    var pgf = textFrame.FirstPgf;

    var textLoc = new TextLoc(pgf, 0);

    //set up the prop vals structures and do the import.

    var importParms = GetImportDefaultParams();

    var returnParms = new PropVals();

   

    doc.Import (textLoc, insetPath, importParms, returnParms);

}   

Russ

Votes

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
Mentor ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

By the way, I was assuming you want a text inset created by a file import. For a script-generated inset, I think you would use:

var inset = doc.NewAnchoredTiApiClient(textloc);

If you mean something totally different by "inset", then you'll need to elaborate.

Russ

Votes

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
Advocate ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

Hi Russ,

I know I would have to fire myself, and believe me, I have tried many times. But my boss will not let me go 🙂

What I am doing is this: I walk through a document and find anchored frames. If the anchored frame contains more than one graphic (which includes referenced files, lines, text boxes and such), I convert the entire contents of the anchored frame into a single SVG, which then replaces the contents of the anchored frame. This makes the graphic object, including possible arrows, text boxes etc. suitable for conversion to structured framemaker and/or output to XML. It works fine when there is at least one referenced graphic (Inset) in the anchored frame, as I simply change its InsetFile to the newly created SVG. This works like a breeze, even though FM complains about changed image formats when I reopen the file. The SVGs are displayed correctly, so I am happy. But when I encounter a file that has no referenced graphics, just lines and text boxes and - god forbid - images that were copied in rather than referenced, I have no single Inset to change the InsetFile property of. So I will have to add an Inset to the AFrame at that point and set its InsetFile property.

As you see, there is no text involved and no paragraphs available to set a text location to. If you have a bright idea about this, I would be over the moon. This type of thing has been on my mind ever since I found that FM creates an - Ugh! - CGM out of any AFrame that contains multiple graphic elements. An SVG for that purpose is infinitely better, as it will even allow me to create references to callouts from the text, or have captions inside the text boxes pick up their content from referenced elements in the text flow. Once I have the conversion to SVG perfected, there is no limit to what I can do next.

Let me know if you have the info I need. I know you have been playing around with inserting graphics into an AFrame, but I need to add an Inset right there.

Ciao

Jang

Votes

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
Mentor ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

Hi Jang,

OK, you just want to establish a new imported graphic within an anchored frame? That is, you want your new SVG to replace all current frame contents, as a referenced image? If that's all, I think it might be very simple. After you delete all current contents, just select the frame (frame.GraphicIsSelected = true), then do a doc.Import(<your SVG>). Just like in the GUI. You'll get a new inset as a child of the anchored frame. Just remember to make sure to deselect all other graphics first.

This solution seems so simple that I think I might still be missing something. Let me know.

Russ

Votes

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
Mentor ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

One addendum, again. The Import() method asks for a text location as the first parameter, perhaps that's a source of confusion. If I specify doc.TextSelection.beg or just null, it works fine. Either is invalid and the selected frame takes precedence.

Votes

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
Advocate ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

Hi Russ,

Simple, indeed, and the TextLoc parameter is confusing. If you post your reply to the forum I can award 10 points for the correct answer - and others will be able to see the answer, too. You replied by a message, so I cannot see the replies on the forum.

Ciao

Jang

Votes

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
Mentor ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

Hi Jang,

Here is the solution summed up.

To insert a new inset (that is, a new referenced graphic) into an anchored frame, you need to:

- Deselect all graphic objects in the document, then select just the anchored frame (set frame.GraphicIsSelected=true, all other graphics to false).

- Use doc.Import() in a standard manner, except don't worry about a valid textLocP parameter. Just specify doc.TextRange.beg or null.

The result will be a new referenced graphic as a child of the anchored frame. Note that this methodology follows the GUI-based procedure.

Russ

Votes

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
Community Expert ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

When targeting an existing anchored frame, I usually do this:

1) Create a temporary text frame on the document's first master page. Every document has to have a FirstMasterPageInDoc.

2) Create a TextLoc at the beginning of the temporary frame's first paragraph.

3) Import the graphic at the TextLoc.

4) Find the anchored frame and FirstGraphicInFrame, which is my new inset.

5) Change the new inset's FrameParent to the existing anchored frame object. This "moves" the new inset to the existing anchored frame. Then I can set its LocX, LocY, etc. properties to match that of the original graphic. Then I can delete the original graphic.

6) If you have more than one graphic to import, keep the temporary text frame and just delete its FirstPgf and repeat steps 2-5.

7) When you are done, delete the temporary text frame from the master page.

This may seem complicated, but I have done it in dozens of scripts over the years and have found it to be the most reliable, especially when your target document is invisible. Please let me know if you have any questions or comments. -Rick

Votes

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
Advocate ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

LATEST

OK, I have it working now. There is just one glitch I cannot get to work properly, as it appears to be a bug in the SVG import. When importing the SVG that is built out of all the graphic components in the anchored frame, the height of the SVG is correct but the width is not. There is whitespace on either side of the original graphic and there is no way I can get rid of that. I inspected the SVG in a viewer and it looks fine, without the white space. When importing that file in FM, there is a lot of extra space and this causes FM to scale the image down.

As I do not really need the FM layout to be correct - FM is to be used as the structured editor, not the publishing engine - I won't spend any more time on this right now. I might figure something out in the future and then make the code available as a plug-in. At that point I will want to include references between the text and the callouts in the graphic, and some more goofy stuff that might be useful when publishing to XML and interactive HTML.

Ciao

Jang

Votes

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