Hello Forum.
You can find hereafter the code that i made with your help .
(Sorry i don't know how to insert code in code frame).
var aFrame = null;
var MM = 65536 * 2.834645669; // VAR to convert in milimetres
var doc = app.ActiveDoc;
var insetPath= "C:\\Nouveau template\\Logo_AF_3cm.png";
firstRef = doc.FirstRefPageInDoc;
doc.CurrentPage = firstRef;
NettoieFrame(doc);
ImportLogoAF(doc);
// 23jan18 updateManuelNbrVAR(doc);
// On revient sur la premiere page (Body Page)
// Come back to the first body page
firstRef = doc.FirstBodyPageInDoc ;
doc.CurrentPage = firstRef;
function ImportLogoAF(DZGdoc){
var refFrame = DZGdoc.GetNamedUnanchoredFrame ("Logo");
// On crée une nouvelle page reference-
// New ref page insert after the last ref page
var NwPageRef= DZGdoc.NewNamedObject(Constants.FO_RefPage, "Swap_Logo1");
//$.writeln ("NwPageRef.id1=" +NwPageRef.id);
var page = DZGdoc.LastRefPageInDoc;
//On crée une nouvelle unanchored frame-
// New unanchored frame inserted
aFrame = DZGdoc.NewUnanchoredFrame (page.PageFrame);
aFrame.Width = 50 * MM;
aFrame.Height = 50 * MM;
//On crée un nouveau textframe dans l'unchoredframe-
//New textframe inserted in the unanchored frame
var textFrame = DZGdoc.NewGraphicObject(Constants.FO_TextFrame, aFrame);
if(textFrame.ObjectValid())
{
//Position and size the text frame to fit the anchored frame
textFrame.LocX = (2 * 65536);
textFrame.LocY = (2 * 65536);
textFrame.Width = 40 * MM;
textFrame.Height = 40* MM;
}
//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 props = new PropVals();
props = GetImportDefaultParams();
var index = GetPropIndex(props, Constants.FS_HowToImport);
if(index > -1) props[index].propVal.ival = Constants.FV_DoByCopy; //import by copy
var returnParms = new PropVals();
// on importe le nouveau logo dans la textframe -
// Logo imported in the texframe
DZGdoc.Import (textLoc, insetPath, props, returnParms);
// on selectionne le logo et on le deplace-
//Logo selected and moved to the LOGO frame
var oGraphic = textFrame.FirstAFrame;
var oGraphic = oGraphic.FirstGraphicInFrame;
oGraphic.FrameParent = refFrame;
// on recadre le logo dans le nouvel emplacement-
// Logo fit to the new place
oGraphic.LocX=43.28*MM;
oGraphic.LocY=1*MM;
oGraphic.InsetDpi = 150;
//On supprime les emplacements provisoires -
//Temporary frame deleted
aFrame.Delete();
oGraphic.GraphicIsSelected=true;
aFrame.Delete();
var RefPageToDelete=DZGdoc.GetNamedObject(Constants.FO_RefPage, "Swap_Logo1");
RefPageToDelete.Delete();
// On revient sur la premiere page (Body Page)
//-Come back to the body page
firstRef = DZGdoc.FirstBodyPageInDoc ;
DZGdoc.CurrentPage = firstRef;
// Fin de l'import du Logo -END
}
function NettoieFrame (DZGdoc2) {
//Suppression du logo
// Celui ci est composé d'une multitude d'objets graphics comme des elipses, Groups,polygon
// This function cleans the logo frame
var DZG_Frame = DZGdoc2.GetNamedUnanchoredFrame ("Logo");
var graphic, frames = [], objType;
graphic = DZG_Frame.FirstGraphicInFrame;
while (graphic.ObjectValid () === 1) {
objType = graphic.constructor.name;
$.writeln ("objtype="+objType);
if (objType === "Arc" ||
objType === "Ellipse" || objType === "Group" ||
objType === "Inset" || objType === "Line" ||
objType === "Math" || objType === "Polygon" ||
objType === "Polyline" || objType === "Rectangle" ||
objType === "RoundRect") {
frames.push (graphic);
}else if (objType === "TextFrame"){
// Delete the first paragraph in the text frame.
graphic.FirstPgf.Delete ();
//Add the new text.
var textLoc = new TextLoc (graphic.FirstPgf, 0);
doc.AddText (textLoc, "THIS MANUAL");
}
graphic = graphic.NextGraphicInFrame;
}
deleteFrames( frames);
}
function deleteFrames (frames) {
$.writeln ("Nb frame to delete="+frames.length);
for (var i = 0; i < frames.length; i += 1) {
frames.Delete ();
}
}