I am trying to analyze a Visio diagram using Python win32com.
I want to go over all connectors in the diagram and find which shapes they are connecting.
I have a working VBA macro for that inside the Visio, which I'm now trying to translate to Python code.
When trying to use shape.GluedShapes(win32com.client.constants.visGluedShapesIncoming2D, "")
(like I do in the VBA code) I get a type_mismatch error: pywintypes.com_error: (-2147352571, 'Type mismatch.', None, 3)
I also tried shape.GluedShapes(win32com.client.constants.visGluedShapesIncoming2D, "", "")
For which I get the Error: TypeError: The Python instance can not be converted to a COM object
The only definition of GluedShapes I found in Python is:
def GluedShapes(self, Flags=defaultNamedNotOptArg, CategoryFilter=defaultNamedNotOptArg, pOtherConnectedShape=defaultNamedNotOptArg):
return self._ApplyTypes_(1610743990, 1, (8195, 0), ((3, 1), (8, 1), (9, 17)), 'GluedShapes', None,Flags, CategoryFilter, pOtherConnectedShape)
And I can't understand from it what I should do differently about the arguments' types.
My Python code is:
for page in opened_doc.Pages:
for shape in page.Shapes:
if str(shape.Master).lower() == "dynamic connector":
arySourceIDs = shape.GluedShapes(win32com.client.constants.visGluedShapesIncoming2D, "")
aryTargetIDs = shape.GluedShapes(win32com.client.constants.visGluedShapesOutgoing2D, "")
My VBA macro (which works):
For Each shape in Visio.ActivePage.Shapes
If shape.OneD Then
arySourceIDs = shape.GluedShapes(visGluedShapesIncoming2D, "")
aryTargetIDs = shape.GluedShapes(visGluedShapesOutgoing2D, "")