Python pywin32 module Visio automation

Started by bailofwZ, May 13, 2021, 06:22:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bailofwZ

Hello everyone,
I'm very new in this forum.
I hope my question is in the format you like :)

First of all, I wrote my script in Python language. I have a Visio template which has its own stencil(library of shapes). Imagine, I have stencil which has more shapes; therefore, I want to delete the stencil of the template Visio, and want to add mine. I searched this a lot on the internet but couldn't find a solution. I can simply add my shapes to template document stencil, however, I want to do this using Python since I want to automate things, and in every template I don't want to do this.

In office VBA page, I found this but couldn't implement to my script. (Adding a document object based on both template and stencil.)

Here is the link: https://docs.microsoft.com/en-us/office/vba/api/visio.documents.add

Public Sub AddDocument_Example()

Dim vsoDocument As Visio.Document

'Add a Document object based on the Basic Diagram template.
Set vsoDocument = Documents.Add("Basic Diagram.vst")

'Add a Document object based on a drawing (creates a copy of the drawing).
Set vsoDocument = Documents.Add("Myfile.vsd ")

'Add a Document object based on a stencil (creates a copy of the stencil).
Set vsoDocument = Documents.Add("Basic Shapes.vss")

'Add a Document object based on no template.
Set vsoDocument = Documents.Add("")

End Sub


I don't know maybe deleting current stencil might be a problematic because template Visio has already shapes from that stencil.

I'm open to new ideas or solutions. If you help me, I would be very appreciated.

My current code:

import win32com.client

app = win32com.client.Dispatch("Visio.Application")
app.Visible = True

doc = app.Documents.Open("d:\\X.vsd") #Open template document
custom_stencil = app.Documents.Add("d:\\custom_stencil.vssx") #Trying to add custom stencil

page = app.ActivePage

#Show the all items in stencil
for shape in doc.Masters:
    print(shape)

Surrogate

#1
Sorry for necro-posting  :)
https://github.com/Surrogate-TM/surrogate-tm.github.io/blob/master/jupyterlab/bailofwZ.ipynb
Quote from: Yacine on March 07, 2022, 07:28:17 AM
So you are still having troubles with jupyter lab?
I install Pycharm Community and pypiwin32, after these changes i can use Jupyter Notebook/Jupyter Lab at my notebook  8)

Yacine

 :) :) :) :) :)


... and learned a new word "necroposting".
Yacine