lohriialo / indesign-scripting-python

Scripting in InDesign is used to automate a wide variety of repetative task or as complex as an entire new feature
145 stars 26 forks source link

Insert image into selected frame #5

Closed robertjiang77 closed 4 years ago

robertjiang77 commented 4 years ago

Hi Lohrrialo,

I need to insert an image (png/jpg) into a frame. But I am struggling with how to read the image in. Could you kindly review the below code and show me a way to fix it?

app = win32com.client.Dispatch('InDesign.Application.CC.2019') myInddFile = r'C:\Users\zhijia\Documents\Robertjiang\Tracker\In-Design Project\Tracker Template_test_old.indd' myDocument = app.Open(myInddFile) myPage = myDocument.Pages.Item(1)

myRectangle = myPage.Rectangles.Add() myRectangle.GeometricBounds = ["6p", "6p", "18p", "18p"] myRectangle.StrokeWeight = 0 myRectangle.place('C:\Users\zhijia\Documents\Robertjiang\Tracker\In-Design Project\AA.jpg'')

The problem occurred at the end line of the above code. What I need is to

  1. place a picture into the rectangle frame
  2. and then fit content to frame.

Could you kindly teach me how to achieve both in python please?

Great thanks!

robertjiang77 commented 4 years ago

Hi Lohrii, could you kindly show me how to solve the problem? I tried to read in the image by Plotly but the place function doesn't work. Should I use the PlaceIntoFrame function? Please help, thanks!

lohriialo commented 4 years ago

@robertjiang77 the place method should start with an upper case myRectangle.Place() See, scripting reference line #64592

lohriialo commented 4 years ago

And to fit content to frame

idContentToFrame = 1668575078   # from enum idFitOptions
myRectangle.Fit(idContentToFrame)

See, scripting reference line #802