dave-howard / vsdx

vsdx - A python library for processing .vsdx files
BSD 3-Clause "New" or "Revised" License
70 stars 25 forks source link

Multiple Geometries in shape not supported? #69

Open kempeng opened 10 months ago

kempeng commented 10 months ago

Hi Dave,

Is my understanding from the shapes.py code correctly that you currently do not support the reading of multiple geometry sections defined in a single shape record?

I have come across several examples of such cases.

Geert

torinsapp commented 10 months ago

I ran into the same problem. I modified the code so it would: shapes.py starting at line 151: geometrys = self.xml.findall(f'{namespace}Section[@N="Geometry"]') for geometry in geometrys: if type(geometry) is Element:

print(f"geometry({type(geometry)}):{geometry}")

            self.geometry = vsdx.Geometry(xml=geometry, shape=self)
            if geometry.attrib.get('IX') is not None:
                self.geometry.index = geometry.attrib['IX']
            else:
                self.geometry.index = 0
            for r in geometry.findall(f"{namespace}Row"):
                row_type = r.attrib['T']
                if r.attrib.get('IX') is not None:
                    row_type = f"{row_type}/{r.attrib['IX']}"
                else:
                    row_type = f"{row_type}/0"
                if row_type:
                    for e in r.findall(f"{namespace}Cell"):
                        cell = vsdx.Cell(xml=e, shape=self)
                        key = f"Geometry/{self.geometry.index}/{row_type}/{cell.name}"
                        self.cells[key] = cell

so if you have:

you can modify the different values as so: shape.set_cell_value("Geometry/2/LineTo/2/Y", '1.51770027') This will handle multiple Geometries and Rows. For dave: I can provide more context if ya want, but I think this can be applied to all sections, rows, and even cells with dupe names
torinsapp commented 10 months ago

Keep in mind this will break certain functions like line_to_x, but if you've gotten this far, just call the cell_val yourself