Skip to content

Instantly share code, notes, and snippets.

@rdapaz
Created March 30, 2022 18:35
Show Gist options
  • Save rdapaz/c55edcf36a427acce649657e497617c7 to your computer and use it in GitHub Desktop.
Save rdapaz/c55edcf36a427acce649657e497617c7 to your computer and use it in GitHub Desktop.
VisioAutomation
import os
import win32com.client
import re
import pprint
def pretty_print(o):
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(o)
from win32com.client import gencache
# from win32com.client import constants
ROOT = r'C:\Users\W54168\Documentum'
# vsd = win32com.client.gencache.EnsureDispatch('Visio.Application')
vsd = win32com.client.Dispatch('Visio.Application')
vsd.Visible = True
doc = vsd.Documents.Open(os.path.join(ROOT, 'C9500 port map template - switch B.vsd'))
doc_page = doc.Pages("PortMap")
# data = {
# "Te1/1/5":"VNGU-PCN-ALER-SW01 TE1/1/8",
# "Te1/1/4":"VNGU-PCN-CLER-SW03 Te1/1/8",
# "Te1/0/8":"SWV DAD Link",
# "Te1/0/7":"ESXi-HOST-1 O/B NIC PORT 2",
# "Te1/0/6":"ESXi-HOST-1 O/B NIC PORT 1",
# "Te1/0/5":"ESXi-HOST-1 O/B NIC PORT 0",
# "Te1/0/2":"SAN01-CTR-A-Port2",
# "Te1/0/15":"SWV Virtual Link Pair",
# "Te1/0/16":"SWV Virtual Link Pair",
# "Te1/0/14":"VNGU-PCN-CLER-FW01B",
# "Te1/0/13":"VNGU-PCN-CLER-FW01A",
# "Te1/0/11":"ESXi-HOST-2 O/B NIC PORT 2",
# "Te1/0/10":"ESXi-HOST-2 O/B NIC PORT 1",
# "Te1/0/1":"SAN01-CTR-A-Port0",
# }
data = {
"Te2/0/1":"SAN01-CTR-B-Port0",
"Te2/0/10":"ESXi-HOST-2 PCI-E NIC PORT 1",
"Te2/0/11":"ESXi-HOST-2 PCI-E NIC PORT 2",
"Te2/0/13":"VNGU-PCN-CLER-FW01A",
"Te2/0/14":"VNGU-PCN-CLER-FW01B",
"Te2/0/15":"SWV Virtual Link Pair",
"Te2/0/16":"SWV Virtual Link Pair",
"Te2/0/2":"SAN01-CTR-B-Port2",
"Te2/0/5":"ESXi-HOST-1 PCI-E NIC PORT 0",
"Te2/0/6":"ESXi-HOST-1 PCI-E NIC PORT 1",
"Te2/0/7":"ESXi-HOST-1 PCI-E NIC PORT 2",
"Te2/0/8":"SWV DAD Link",
"Te2/1/4":"VNGU-PCN-CLER-SW03 Te2/1/8",
"Te2/1/5":"VNGU-PCN-ALER-SW01 Te2/1/8",
"Te2/1/8":"UNUSED",
}
all_layers = [u'Te2/0/{}'.format(x) for x in range(1,17)]
all_layers = all_layers + [u'Te2/1/{}'.format(x) for x in range(1,9)]
layers_to_hide = [x for x in all_layers
if x not in
data.keys()]
pretty_print(layers_to_hide)
vsd.ScreenUpdating = False
for layer in all_layers:
print(layer)
doc_page.Layers(layer).CellsC(4).FormulaU = "1"
doc_page.Layers(layer).CellsC(5).FormulaU = "1"
for layer in layers_to_hide:
if doc_page.Layers(layer).Name == layer:
doc_page.Layers(layer).CellsC(4).FormulaU = "0"
doc_page.Layers(layer).CellsC(5).FormulaU = "0"
else:
doc_page.Layers(layer).CellsC(4).FormulaU = "1"
doc_page.Layers(layer).CellsC(5).FormulaU = "1"
for ifce, desc in data.items():
for idx in range(1, doc_page.Shapes.Count+1):
shp = doc_page.Shapes(idx)
if shp.Name == ifce:
if re.search(r'Te\d/0', shp.Name):
shp.Text = "{}: {}".format((desc.upper()), ifce)
else:
shp.Text = "{}: {}".format(ifce, (desc.upper()))
vsd.ScreenUpdating = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment