Closed hideo213 closed 2 years ago
Hi there - I was just looking through the remove_page_by_index() method to see why this might be failing. I think there are two possible reasons:
[1] Your code is looping through vis.pages
and inside that loop calling vis.remove_page_by_index()
which itself updates vis.pages list. You can mitigate this by wrapping list() around the vis.pages ie.. for page in list(vis.pages):
so that you are looping through a new instance of the list.
[2] if the pages in the vsdx file do not contain a /docProps/app.xml file then the current version of package was leaving a remnant of the page xml which Visio would then re-create the page from. I'll make a change to more thoroughly remove the page contents to resolve this issue.
I'll also add a vis.remove_page_by_name() to make it easier to do that.
Hello @hideo213 - changes have been tested and updated package v0.5.6 released. Hope this and the comments above help
Hy dave Thanks for your answer. Yes the list() wrapping solved the problem. Thanks a lot. Now after you explained i understand my logic failure. ah and shape.remove() seems to work, thanks.
Nice one - I'll close this issue in that case
I have an issue, that if i try to delete several pages at once, the deleted pages do not match my selection:
for eg.: for file in visios: with VisioFile(file) as vis: for page in vis.pages: if not 'LAN' in page.name and not 'Background' in page.name: vis.remove_page_by_index(page.index_num) vis.save_vsdx(file)
and then then there are still pages, not containing LAN or Background in the file name, present. Especially the first page (by appearance and not by index_num) never gets deleted.
ah and by the way: Is there something like a shape.remove() method?