I am using Python 2.7 with the win32com.client and trying to figure out how to change the font name and color for a Microsoft Visio 2013 shape.
The code below creates a rectangle shape on a Visio document that is already open. This code is working and sets the shape color, text and line width without any problems.
import sys, win32com.client
visio = win32com.client.Dispatch("Visio.Application")
vsoShape1 = visio.ActivePage.DrawRectangle(1,1,2,2)
vsoShape1.Cells("LineColor").FormulaU = 0
vsoShape1.Cells("LineWeight").FormulaU = "2.0 pt"
vsoShape1.FillStyle = "None"
vsoShape1.Text = "This is a test"
vsoShape1.Cells("Char.size").FormulaU = "20 pt"
Different methods were tried to change the font name and font color which resulted in error messages.
Theses two lines of code both result in this error message: pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Drawing4 - Visio Standard', u'\n\nUnexpected end of file.', None, 0, -2032466967), None)
vsoShape1.Cells("Font.Name").FormulaU = "Courier"
vsoShape1.Cells("Font.Bold").FormulaU = "True"
The next three lines of code all resulted in a similar error message without the end of file error: pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Drawing4 - Visio Standard', u'\n\nNAME?', None, 0, -2032466907), None)
vsoShape1.Cells("Char.Font").FormulaU = "Courier"
vsoShape1.Cells("Char.colorIndex").FormulaU = 16
vsoShape1.Cells("Font.Bold").FormulaU = 0
A few more attempts resulted in: DrawRectangle.xxxxx can not be set.
vsoShape1.fontName = "Courier"
vsoShape1.Bold = True
vsoShape1.Bold = 1