I'm writing script to automate Visio documents using Python. I'm using win32com module and so far, I'm doing good. I learned how to play with shapes , masters and stencil etc.; however, I stuck on the connecting shapes. I searched many forums and discussions but I couldn't get any clear explanation myself.
I decided to create an 2 object to connect them from their connection points that I added. Here, I added big picture so that, connection points on the edges can be seen clearly.
Then, I tried to connect them. What I learned from documentation is, first I need to create an connect object. Then I need to create 2 cells from this 1D object, which are begin("BeginX") and end("EndX") points. Then, I need to glue this endpoints to the objects.
Here is my Python code which is taken from VBA documentation(I converted it to Python). However, it's really hard to understand what is "Geometry1.X1" etc.
import win32com.client
app = win32com.client.Dispatch("Visio.Application")
app.Visible = True
doc = app.Documents.Open("d:\\X.vsd")
page = app.ActivePage
...
added_new_shape1 = page.Drop(master_shape_ex, 5, 5)
added_new_shape2 = page.Drop(master_shape_ex, 10, 5)
myConnector = page.Drop(app.ConnectorToolDataObject, 4, 10)
myConnectorBegin = myConnector.Cells("BeginX")
myConnectorEnd = myConnector.Cells("EndX")
vsoCellGlueToObject = added_new_shape1.Cells("Geometry1.X1")
vsoCellGlueToObject2 = added_new_shape2.Cells("Geometry1.X1")
myConnectorBegin.GlueTo(vsoCellGlueToObject)
myConnectorEnd.GlueTo(vsoCellGlueToObject2)
If I run my code, 2 shapes are connected from the corners.
Then I play with X1, I see connection end points are changing but I'm so confused here.
Many questions are coming to mind but if I have the answer of these 2, I believe that I will understand the logic.
- How can I connect shapes by specifying the points on shapes?
- How can I connect shapes using connection points? (In this example, I created shape and added connection points myself. Does it matter to add connection points using script? )
I would be very happy if you could give me advice beyond these two questions.