Title: Why aren't shapes appearing in my generated Visio file using the vsdx
Python library?
Description:
I'm working with the vsdx
Python library to generate a flowchart and export it to Visio. My goal is to add new shapes to the Visio file and update existing ones. I've attempted the following:
- Opened an existing Visio file (
Flowchart_Walmart.vsdx
). - Updated the text of an existing shape using
find_shape_by_text
. - Created and added a new shape with XML using
Element
andSubElement
.
However, the shapes I'm trying to add are not visible in the generated Visio file. Here's the code I used:
filename = "Flowchart_Walmart.vsdx"
new_file = "diagram_with_shapes.vsdx"
# Open the copied Visio file
with VisioFile(filename) as v:
page = v.pages[0] # Get the first page
# Find an existing shape and update its text
existing_shape = page.find_shape_by_text(text="Is the customer new or existing?")
if existing_shape:
existing_shape.text = "Updated: Is the customer new or existing?"
existing_shape.shape_type = "Process"
# Create a new shape
shape_xml = Element("Shape", {"ID": "100", "name": "Process", "type": "Shape"}) # Ensure unique ID
text_element = SubElement(shape_xml, "Text")
text_element.text = "New Shape Added"
# Convert to VisioShape and add to page
new_shape = Shape(xml=shape_xml, parent=page, page=page)
page.shapes.append(new_shape)
# Save the updated Visio file
v.save_vsdx(new_file)
When I open the generated file, the new shape does not appear on the Visio diagram. The updated shape text also doesn't reflect the changes.
Here are the issues I suspect:
- The new shape may not be properly added to the
shapes
list or rendered on the page. - The XML structure for the new shape might be missing required elements or attributes.
- There could be additional steps needed for the
vsdx
library to register and render new shapes.
Could someone please help me understand:
- Why the new shape is not showing up in the generated file?
- If additional steps are required to properly add and render shapes in Visio using the
vsdx
library? - Are there better alternatives or workarounds for creating flowcharts in Python and exporting them to Visio?
I am trying to generate a Visio file that contains flowchart shapes like Process, Decision, etc., along with the connections between nodes. However, the output I generated is a plain Visio file that does not contain any shapes. Can anyone please provide a solution or suggest corrections to my current approach?
Title: Why aren't shapes appearing in my generated Visio file using the vsdx
Python library?
Description:
I'm working with the vsdx
Python library to generate a flowchart and export it to Visio. My goal is to add new shapes to the Visio file and update existing ones. I've attempted the following:
- Opened an existing Visio file (
Flowchart_Walmart.vsdx
). - Updated the text of an existing shape using
find_shape_by_text
. - Created and added a new shape with XML using
Element
andSubElement
.
However, the shapes I'm trying to add are not visible in the generated Visio file. Here's the code I used:
filename = "Flowchart_Walmart.vsdx"
new_file = "diagram_with_shapes.vsdx"
# Open the copied Visio file
with VisioFile(filename) as v:
page = v.pages[0] # Get the first page
# Find an existing shape and update its text
existing_shape = page.find_shape_by_text(text="Is the customer new or existing?")
if existing_shape:
existing_shape.text = "Updated: Is the customer new or existing?"
existing_shape.shape_type = "Process"
# Create a new shape
shape_xml = Element("Shape", {"ID": "100", "name": "Process", "type": "Shape"}) # Ensure unique ID
text_element = SubElement(shape_xml, "Text")
text_element.text = "New Shape Added"
# Convert to VisioShape and add to page
new_shape = Shape(xml=shape_xml, parent=page, page=page)
page.shapes.append(new_shape)
# Save the updated Visio file
v.save_vsdx(new_file)
When I open the generated file, the new shape does not appear on the Visio diagram. The updated shape text also doesn't reflect the changes.
Here are the issues I suspect:
- The new shape may not be properly added to the
shapes
list or rendered on the page. - The XML structure for the new shape might be missing required elements or attributes.
- There could be additional steps needed for the
vsdx
library to register and render new shapes.
Could someone please help me understand:
- Why the new shape is not showing up in the generated file?
- If additional steps are required to properly add and render shapes in Visio using the
vsdx
library? - Are there better alternatives or workarounds for creating flowcharts in Python and exporting them to Visio?
I am trying to generate a Visio file that contains flowchart shapes like Process, Decision, etc., along with the connections between nodes. However, the output I generated is a plain Visio file that does not contain any shapes. Can anyone please provide a solution or suggest corrections to my current approach?
Share Improve this question asked Mar 19 at 10:37 sayen vvsayen vv 111 bronze badge 1- Are you using the free/trial version or the licensed version of the library? It seems the trial version has certain features disabled. I might be wrong here as well. – Naveed Ahmed Commented Mar 19 at 10:58
1 Answer
Reset to default 0Element("Shape", {"ID": "100", "name": "Process", "type": "Shape"}
Where is this shape coming from? Normally with Visio you need to have a stencil open and reference a shape master within that stencil.
On top of that a shape that has been added to a page needs to have a height and width, as well as X and Y coordinates.
Also you have no line style, the shape might be being created but invisible against the background.