Automate VISIO using Python

Bhushan Bapat 21 Reputation points
2022-01-13T16:00:56.897+00:00

In the below sample program, I want to change font size and style when I drop text.
I tried few thing but not able to do that.
Can anyone please guide me.
Thank you

---- Sample program ----

from win32com.client import constants

appVisio = win32com.client.Dispatch("Visio.Application")
appVisio.Visible =1

doc = appVisio.Documents.Add("Basic Diagram.vst")
pagObj = doc.Pages.Item(1)
stnObj = appVisio.Documents("Basic Shapes.vss")
mastObj = stnObj.Masters("Rectangle")

shpObj1 = pagObj.Drop(mastObj, 4.25, 5.5)
shpObj1.Text = "This is some text."

shpObj2 = pagObj.Drop(mastObj, 2, 2)
shpObj2.Text = "This is some more text."

connectorMaster = appVisio.Application.ConnectorToolDataObject

connector = pagObj.Drop(connectorMaster, 0, 0)
connector.Cells("BeginX").GlueTo(shpObj1.Cells("PinX"))
connector.Cells("EndX").GlueTo(shpObj2.Cells("PinX"))

doc.SaveAs(r'e:\temp\MyDrawing.vsd')
doc.Close()

appVisio.Visible =0

appVisio.Quit()

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,426 questions
Visio Management
Visio Management
Visio: A family of Microsoft products used to create diagrams and vector graphics.Management: The act or process of organizing, handling, directing or controlling something.
247 questions
{count} votes

Accepted answer
  1. Anonymous
    2022-01-13T17:00:22.203+00:00

    Hi, you can change font size with code

    shpObj1.Cells("Char.size").FormulaU = "7.40 pt"
    

    What you mean as style ?


2 additional answers

Sort by: Most helpful
  1. Anonymous
    2022-01-14T07:04:02.86+00:00

    Text Style in Visio is a set of settings of text such as font type, font size, font color, line spacing and so on. If you apply text style to shape, this make shape parameters according style settings. But since version 2007 in Visio was added Themes, the Styles have become obsolete, but they still exist, but you have to try very hard to find them in the user interface! May be you mean font type ? ![165027-font-type.png][1] [1]: /api/attachments/165027-font-type.png?platform=QnA

    0 comments No comments

  2. Piyush Jain 1 Reputation point
    2022-07-16T12:19:26.577+00:00

    Hi Bhushna ,

    can you please assit me on visio automation using xl contain to past on visio files

    0 comments No comments