Copy link to clipboard
Copied
Hello fellows,
I am trying to set a permanent bottom padding between an anchored frame and a graphic object (embedded Visio) that is inside the anchored frame.
However, instead of getting that padding below the graphic, the aframe becomes really small, and only 20% of the graphic is exposed.
The code goes like this:
...
SET vFrame = vCurrentDoc.FirstGraphicInDoc;
Loop While(vFrame)
IF vFrame.ObjectName = 'AFrame'
SET vFrame.AnchorType = AnchorBelow;
SET vFrame.GraphicIsSelected = 1;
SET vGraphic = vFrame.FirstGraphicInFrame // Select the 1st graphic in the frame
SET vFrame.Width = vFrame.TextLoc.InTextObj.Width;
SET vFrame.Height= vGraphic.Height + 5mm; //Here is the padding of 5mm
Set vGraphic.LocY = 0mm;
Set vGraphic.LocX = (vFrame.Width - vGraphic.Width) / 2;
ENDIF
...
Please, advise!
Thank you!
Copy link to clipboard
Copied
This works for me:
// Set a variable for the active document.
Set oDoc = ActiveDoc;
// Set a variable for the selected anchored frame.
Set oAFrame = oDoc.FirstSelectedGraphicInDoc;
// Update the anchored frame's position.
Set oAFrame.AnchorType = AnchorBelow;
// Set the width of the anchored frame to match the containing text column.
Set oAFrame.Width = oAFrame.TextLoc.InTextObj.Width;
// Get the first graphic in the anchored frame.
Set oGraphic = oAFrame.FirstGraphicInFrame;
// Make the anchored frame's height 5 mm taller than the graphic.
Set oAFrame.Height = oGraphic.Height + 5mm;
// Move the graphic to the top of the anchored frame.
Set oGraphic.LocY = 0;
// Center the graphic horizontally in the anchored frame.
Set oGraphic.LocX = (oAFrame.Width - oGraphic.Width) / 2;
After you get it tested, then put it in a function:
Set oDoc = ActiveDoc;
Set oAFrame = FirstSelectedGraphicInDoc;
Set iResult = AdjustAFrameAndGraphic{oAFrame};
Function AdjustAFrameAndGraphic oAFrame
//
Local oGraphic(0);
// Update the anchored frame's position.
Set oAFrame.AnchorType = AnchorBelow;
// Set the width of the anchored frame to match the containing text column.
Set oAFrame.Width = oAFrame.TextLoc.InTextObj.Width;
// Get the first graphic in the anchored frame.
Set oGraphic = oAFrame.FirstGraphicInFrame;
If oGraphic
// Make the anchored frame's height 5 mm taller than the graphic.
Set oAFrame.Height = oGraphic.Height + 5mm;
// Move the graphic to the top of the anchored frame.
Set oGraphic.LocY = 0;
// Center the graphic horizontally in the anchored frame.
Set oGraphic.LocX = (oAFrame.Width - oGraphic.Width) / 2;
EndIf
//
EndFunc // -------------------------------------------------------------------
-Rick
Copy link to clipboard
Copied
Hi Rick,
I appreciate your response!
My questions:
1. Why do you prefer to put the code into a function?
2. Why do you declare oGraphic as a local var and set it to 0?
3. I need to loop through all anchored frames with graphics, so oAFrame must be defined as FirstGraphicInDoc and not FirstSelectedGraphicInDoc, right?
Thank you again and have a great day!
Copy link to clipboard
Copied
Hi Roman,
1) You should always organize your scripts into functions. Each function can represent a small task. This keeps your scripts more organized and easy to follow. It makes the code easier to test and troubleshoot. And functions make it easier to reuse code in other scripts. You can easily copy/paste this function into another script and make changes to it that would be appropriate for that script.
2) All variables that are used inside of functions should be declared local so they don't interfere with any variables used outside of the function (or in another function). You don't have to set it to 0, but I usually do as a matter of preference.
3) The reason I use FirstSelectedGraphicInDoc is so I can test the function with a selected anchored frame to make sure it works. I don't want to use a loop before making sure it works on a single anchored frame. Once the function is developed and tested, then I can use a loop:
Set oGraphic = oDoc.FirstGraphicInDoc;
Loop While(oGraphic)
If oGraphic.ObjectName = 'AFrame'
// Adjust the anchored frame size and graphic position.
Set iResult = AdjustAFrameAndGraphic{oGraphic};
EndIf
Set oGraphic = oGraphic.NextGraphicInDoc;
EndLoop
This is another advantage of using functions: I can follow the flow of my script and get a general idea of what it does by looking at my function calls (lines 4-5). I don't have to get bogged down with the details inside of the functions.
The biggest scripting mistake that I see is in scripts where all the code is in one big long block. When something doesn't work, it is difficult to troubleshoot. When the code is developed as a series of small tasks that are put into functions, the whole process is easier.
-Rick
Copy link to clipboard
Copied
Hi Rick,
Thank you for your explanations and guidance!
My best regards,
Roman