Skip to content

Parallel links creates an error in DrawIO #2

@Gitpear

Description

@Gitpear

When adding links the function addLink creates IDs based on source and destination.
When there are multiple parallel links between two nodes DrawIO throws an error as it cannot handle duplicates.

Solved by creating uniqe IDs.

One solution could be to generate a random string and attach it to the ID.

import random
import string

    def addLink(self,sourceNodeID,destinationNodeID):
        try: 
            for mxCell in self.root:
                print(mxCell.attrib['id'])
                print(type(mxCell.attrib['id']))
                print(sourceNodeID)
                print(type(sourceNodeID))
                if mxCell.attrib['id'] == sourceNodeID:
                    print('Element found' + {mxCell.attrib['id']})
                    break
            return
        except Exception as e:
            print(e)
        random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=4))
        mxCell = ET.SubElement(self.root,
                                'mxCell',
                                id=sourceNodeID+destinationNodeID+random_string,
                                style="endFill=0;endArrow=none;",
                                parent="1",
                                source=sourceNodeID,
                                target=destinationNodeID,
                                edge="1")
        mxGeometry = ET.SubElement(mxCell, 'mxGeometry')
        mxGeometry.set('as','geometry')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions