Reputation: 57
I'm using pywin32 to manipulate Visio files automatically. Is there any way to embed an image into a Visio document using pywin32 or some other library? I haven't been able to find any documentation on this.
I know the code to create a new Visio document looks something like this:
import win32com.client as win32
visio = win32.Dispatch("Visio.Application")
doc = visio.Documents.Add("Basic Diagram.vst")
doc.SaveAs("C:\\Users\\"username"\\Desktop\\test.vsdx")
But I don't know where to go from here.
Any advice would be appreciated.
Upvotes: 0
Views: 525
Reputation: 2698
Here's a Python modification of the code over here:
def dropImage(vPag, imageFile):
if vPag is not None:
shpNew = vPag.Import(imageFile)
#Set position
shpNew.CellsU("PinX").FormulaU = "75mm"
shpNew.CellsU("PinY").FormulaU = "175mm"
#Set size
shpNew.CellsU("Width").FormulaU = "100mm"
shpNew.CellsU("Height").FormulaU = "80mm"
targetPage = appVisio.ActivePage
dropImage(targetPage, r"C:\SomeImage.jpg")
Upvotes: 1