Created
January 14, 2021 23:53
-
-
Save rdapaz/49e0f14dc3a595bc3c458eda52fbb14f to your computer and use it in GitHub Desktop.
Visio Updater
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
gencache.EnsureModule('{00021A98-0000-0000-C000-000000000046}', 0, 4, 16) | |
from win32com.client import constants | |
SWITCH = '3320WS061' | |
ROOT = r'E:\Projects\MAC PCN Remediation\31. Drawings' | |
vsd = win32com.client.Dispatch('Visio.Application') | |
vsd.Visible = True | |
doc = vsd.Documents.Open(os.path.join(ROOT, 'Master Pack', '860-E-NEW02.vsdm')) | |
doc_page = doc.Pages("Page-1") | |
xls = win32com.client.Dispatch('Excel.Application') | |
xls.Visible = True | |
wkb = xls.Workbooks.Open(os.path.join(ROOT, 'MAC Switches.xlsx')) | |
sht = wkb.Worksheets(SWITCH) | |
data = [] | |
EOF = sht.Range('M65536').End(-4162).Row | |
for row in range(14, EOF+1): | |
hidden = sht.Range('N{}'.format(row)).Value2 | |
pl = sht.Range('M{}'.format(row)).Value2 | |
desc = sht.Range('C{}'.format(row)).Value2 | |
if hidden == 'No': | |
data.append([pl, desc]) | |
layers_to_hide = [u'PL{}'.format(x) for x in range(1,25) | |
if 'PL{}'.format(x) not in | |
[y[0] for y in data]] | |
pretty_print(layers_to_hide) | |
for layer in layers_to_hide: | |
if doc_page.Layers(layer).Name == layer: | |
doc_page.Layers(layer).CellsC(4).FormulaU = "0" | |
else: | |
doc_page.Layers(layer).CellsC(4).FormulaU = "1" | |
for _pl, desc in data: | |
for idx in range(1, doc_page.Shapes.Count+1): | |
shp = doc_page.Shapes(idx) | |
m1 = re.search(r'Interconnect Info\.(.*)', shp.Name, re.IGNORECASE) | |
if m1: | |
pl = str(m1.group(1)) | |
if pl == _pl: | |
shp.Text = desc | |
m2 = re.search(r'Label\.(.*)', shp.Name, re.IGNORECASE) | |
if m2: | |
pl = str(m2.group(1)) | |
if pl == _pl: | |
shp.Text = "{}-{}".format(SWITCH, _pl) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment