【问题标题】:How to get rid of the Shape Label如何摆脱形状标签
【发布时间】:2021-08-26 23:44:18
【问题描述】:

我正在尝试自动化网络图,但我无法摆脱云形状的标签。当我尝试摆脱 -Label 参数时,将不会绘制云。我知道我可以手动删除标签,但是有没有办法在不使用 -Label 参数的情况下绘制云?我在下面提供了我的代码:

#Import-Module Visio
Import-Module VisioBot3000 -Force

## Variables
$Username = $env:USERNAME
$set_x = 2.25
$set_y = 5.5
## Empty CE Router List
$CE_Router_List = @()
## Empty Site Address list
$Site_Address = @()
## Empty arrows list
$arrows = @()
$Gold_Car_List = @()


$Servers = Read-Host 'How many routers do you have?'

## Opens the Visio application
New-VisioApplication
## Opens the Verizon network diagram template
Open-VisioDocument
## Creates a new Visio Page
New-VisioPage

## Register the network shapes stencil (with US measurements)
$CloudStencil = Register-VisioStencil -Name NetworkLocations -Path 'NETLOC_U.VSSX'
$PESwitchStencil = Register-VisioStencil -Name NetworkSymbols -Path 'NETSYM_U.VSSX'
$GoldCarStencil = Register-VisioStencil -Name BasicShapes -Path 'BASIC_U.VSSX'

## Register the PE switch shape
$PE_Switch_Shape = Register-VisioShape -Name 'ATM switch' -StencilName NetworkSymbols -MasterName 'ATM switch'
## Register the CE Router shape
$CE_Router_Shape = Register-VisioShape -Name Router -StencilName NetworkSymbols -MasterName Router
$Cloud_Shape = Register-VisioShape -Name Cloud -StencilName NetworkLocations -MasterName Cloud
## Register the Gold CAR
$Gold_Car = Register-VisioShape -Name Can -Stencil BasicShapes -MasterName Can

## Creates the initial Cloud
$Cloud = New-VisioShape Cloud -Label Cloud -x 5.6296 -y 4.445
## Adjusts the width of the Cloud
$Cloud_Width = $Cloud.CellsU('Width').FormulaU = '3 in'
## Adjusts the height of the Cloud
$Cloud_Height = $Cloud.CellsU('Height').FormulaU = '1.89 in'

<#
.SYNOPSIS
    Sets the color of a shape
.DESCRIPTION
    Sets the color of a shape and subshapes to a given color
.EXAMPLE
    $shape= add-visioshape -stencil BasicShapes -name Square
    Set-ShapeColor -shape $shape -color Red
.INPUTS
    You cannot pipe any objects into Set-ShapeColor
.OUTPUTS
    None
.PARAMETER Shape
    The shape to apply the color to
.PARAMETER Color
    The color you want the shape to be
    #>
function Set-VisioShapeColor {
    [CmdletBinding()]
    Param($Shape,
        [System.Drawing.Color]$Color,
        [ValidateSet('FillForegnd', 'FillBkgnd')]$FillType = 'FillBkgnd'
        )
    $ColorFormula = "=THEMEGUARD(rgb($($Color.R),$($Color.G),$($Color.B)))"


    $shape.CellsU($fillType).FormulaForce = $ColorFormula
    $shape.CellsU('FillGradientEnabled').FormulaForce = 'FALSE'
    $shape.CellsU('FillPattern').FormulaForce = '1'
    $shape.shapes | foreach-object {
        $_.CellsU('FillGradientEnabled').FormulaForce = 'FALSE'
        $_.CellsU($fillType).FormulaForce = $colorFormula 
    }
}

## Set the Cloud color to gray
Set-VisioShapeColor -shape $PIP_Cloud -color Gray

##Creates all of the CE Routers
$num = 0
for ($initial = 1; $initial -le $Servers; $initial++) {
    $CE_Router = New-VisioShape -Master Router -Label '123 Ashwood Drive, Los Angeles, California' -x $set_x  -y $set_y -Name MyRouter
    $CE_Router.CellsU('Width').FormulaU = '0.20 in'
    $CE_Router.CellsU('Height').FormulaU = '0.15 in'
    $CE_Router.CellsU("Char.Size").FormulaU="7 pt"
    $CE_Router_List += $CE_Router
    $num++
}

## The arrows that connect from the Cloud to the CE Router.
Foreach($element in $CE_Router_List)   {
   $arrows+=New-VisioConnector -From $Cloud -To $element -name SQLConnection -Arrow -color Red
}

$page=Get-VisioPage
$Page.PageSheet.CellsSRC(1,24,8).FormulaForceU="6"
$Page.PageSheet.CellsSRC(1,24,9).FormulaForceU="16"
$Page.Layout()
$Page.ResizeToFitContents()

$sel = New-VisioSelection -Objects ($CE_Router_List.Name+$arrows.Name+'Cloud') -Visible

【问题讨论】:

  • 你真的将它用于 ps2、ps3 和 ps4 吗?如果没有,请删除未涉及的标签。
  • @Lee_Dailey 对此感到抱歉。它仅适用于 PS4。我现在就改
  • 酷!很高兴看到真正的要求。 [grin] 既然没有Visio经验,那我就回去潜伏吧……祝你好运!

标签: powershell powershell-4.0 visio


【解决方案1】:

你想要的语法来自:

https://www.powershellstation.com/2016/04/29/introducing-visiobot3000-part-2-superman/

因此,在页面上放置形状的代码行的语法是:

New-VisioShape -master WebServer -name PrimaryServer -x 5 -y 5

您的代码未遵循此格式。

【讨论】:

  • 嗨,保罗,感谢您回答我的问题!不幸的是,您提供给我的上述代码不起作用。它向我显示了这个错误:“Set-VisioText:无法处理参数'Map'的参数转换。无法将类型“System.String”的“”值转换为类型“System.Collections.Hashtable”
  • 好吧,我不知道 Powershell 语法(对我来说看起来很可怕),但我知道 Visio。我通过谷歌找到了 Set-VisioText。一旦你在页面上有了形状,那么你只需要正确的命令来设置形状的文本。
  • 感谢您再次尝试,但不幸的是它仍然返回相同的错误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多