Copy link to clipboard
Copied
Hello everyone,
I'm writing a script where some words should be replaced by anchored images. I can place the images but now I want to apply an object style to those images. I tried to use the method applyObjectStyle but I get the error 'applyObjectStyle is not a function'. I think the prolem lies with the object on which I want to perform the function. If I debug the type of the variable says 'object PDF'. I have no idea why. I'd expect it to be a graphic. This is my code:
app.findTextPreferences = NothingEnum.NOTHING;
app.findTextPreferences.findWhat = textToReplace;
var textObjects = openDoc.findText();
for (var i = 0; i < textObjects.length; i++) {
var file = new File(imagesFolder + "/" + fileName);
if (file.exists) {
var icon = textObjects[i].place(file);
textObjects[i].contents = "";
var objectStyle = openDoc.objectStyles.itemByName(objectStyleName);
icon.applyObjectStyle(objectStyle);
}
}
I've also tried the following, this one gives no error but also does not do anything.
icon.appliedObjectStyle = objectStyle;
The following also returns an object PDF :
textObjects[i].allGraphics[0].appliedObjectStyle = objectStyle;
Hi Nysanna, When you import a .pdf or a .ai file it indesign stores it as a PDF object, so that part is normal. I don't think you can't style a PDF object directly. To apply the object style, try applying it to the PDF's parent, which will be a rectangle in your case.
icon.parent.applyObjectStyle(objectStyle);
- Mark
Copy link to clipboard
Copied
Try applying the object style to icon.parent
Graphic is a superclass of PDF. I assume the placed icon is a PDF? The object style needs to be applied to the graphic's containing frame (ie icon.parent).
Copy link to clipboard
Copied
Hi Nysanna, When you import a .pdf or a .ai file it indesign stores it as a PDF object, so that part is normal. I don't think you can't style a PDF object directly. To apply the object style, try applying it to the PDF's parent, which will be a rectangle in your case.
icon.parent.applyObjectStyle(objectStyle);
- Mark