Skip to content

Commit a70177f

Browse files
authored
Merge pull request #62 from MikeShepard/Develop
Added support for VisioSettings (Import-VisioSettings) and included a…
2 parents ccb678a + 9825821 commit a70177f

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

Examples/DiagramSettings.psd1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@{
2+
StencilPaths='c:\temp'
3+
4+
Stencils=@{Containers='C:\temp\MyContainers.vssx';
5+
Servers='SERVER_U.vssx'}
6+
7+
Shapes=@{WebServer='Servers','Web Server';
8+
DBServer='Servers','Database Server'
9+
}
10+
Containers=@{Domain='Containers','Domain'
11+
}
12+
13+
Connectors=@{SQL=@{Color='Red';Arrow=$true}}
14+
15+
}

Examples/VisioSettingsExample.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Import-Module VisioBot3000 -Force
2+
3+
4+
#start Visio and create a new document
5+
New-VisioApplication
6+
New-VisioDocument C:\temp\TestVisioPrimitives.vsdx
7+
8+
$doc=Get-VisioDocument
9+
Set-VisioDiagramServices -Document $doc -Value $vis.ServiceAll
10+
11+
#adjust path to match the location you put the setting file.
12+
Import-VisioSettings -path C:\Users\mike\Documents\WindowsPowerShell\modules\VisioBot3000\Examples\DiagramSettings.psd1
13+
14+
#draw a container with two items in it
15+
Domain MyDomain {
16+
WebServer PrimaryServer
17+
DBServer SQL01
18+
}
19+
20+
#add a connector
21+
SQL -from PrimaryServer -To SQL01

VisioSettings.ps1

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<#
2+
.SYNOPSIS
3+
Reads a psd1 file with settings for the current diagram.
4+
5+
.DESCRIPTION
6+
Reads a psd1 file with settings for the current diagram. Should be called after a diagram has been opened or created.
7+
Currently supported sections are:
8+
StenciPaths - list of paths to be added to the stencilpath
9+
Stencils - hashtable with name=nickname of stencil, value=filename to stencil
10+
Shapes - hashtable with name=nickname, value=array with stencilname and mastername
11+
Containers - hashtable with name=nickname, value=array with stencilname and mastername
12+
Connectors - hashtable with name=nickname, value=hashtable of parameters splatted to register-visioconnector
13+
14+
.PARAMETER Path
15+
The path to the psd1 file. Must be a full path, not just a filename.
16+
17+
18+
.INPUTS
19+
You cannot pipe anything to Import-VisioSettings
20+
21+
.OUTPUTS
22+
None
23+
24+
.EXAMPLE
25+
Import-VisioSettings c:\Config\DepartmentalDiagramSettings.psd1
26+
27+
28+
#>
29+
function Import-VisioSettings{
30+
[CmdletBinding()]
31+
Param([string]$path)
32+
$dir=Split-Path -Path $path -Parent
33+
$file=split-path -Path $path -leaf
34+
$settings=Import-LocalizedData -FileName $file -BaseDirectory $dir
35+
if($settings.StencilPaths){
36+
$settings.StencilPaths | foreach-object {Add-StencilSearchPath -Path $_}
37+
}
38+
39+
if($settings.Stencils){
40+
$Settings.Stencils.GetEnumerator() | foreach{Register-VisioStencil -Name $_.Key -Path $_.Value}
41+
}
42+
43+
if($settings.Shapes){
44+
$Settings.Shapes.GetEnumerator() | foreach{Register-VisioShape -Name $_.Key -From $_.Value[0] -MasterName $_.Value[1]}
45+
}
46+
if($settings.Containers){
47+
$Settings.Containers.GetEnumerator() | foreach{Register-VisioContainer -Name $_.Key -From $_.Value[0] -MasterName $_.Value[1]}
48+
}
49+
if($settings.Connectors){
50+
51+
$Settings.Connectors.GetEnumerator() | foreach{$options=$_.Value;Register-VisioConnector -Name $_.Key @options}
52+
}
53+
54+
55+
}

0 commit comments

Comments
 (0)