Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
783 views
in Technique[技术] by (71.8m points)

vba - Python win32com Visio's GluedShapes type mismatch

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, "")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...