Skip to content

How to set custom properties using "directed graph from code"  #117

@tcox8

Description

@tcox8

I am attempting to set custom properties when building shapes via the "directed graph from code" example. Note: the shapes don't exist yet so I can't use set-visiocustomproperty function. I have tried the code below plus multiple variations:

This code will create the "DisplayName1234" custom property but the value is always 0.

$g1 = $d.AddShape("g1", "webserver", "Servers.vss", "Server")
$cpDic = New-Object VisioAutomation.Shapes.CustomPropertyDictionary
$cpCellsName = New-Object VisioAutomation.Shapes.CustomPropertyCells
$cpCellsName.Value = "testVal"
$cpDic.Add("DisplayName1234",$cpCellsName)
$g1.CustomProperties = $cpDic

I've also tried:

$cpCellsName = New-Object VisioAutomation.Shapes.CustomPropertyCells
$cpCellsName.Value = "testVal"
[VisioAutomation.Shapes.CustomPropertyHelper]::Set($g1.VisioShape,"displayname",$cpCellsName)

but it results in:

[VisioAutomation.Shapes.CustomPropertyHelper]::Set($g1.VisioShape,"DisplayName",$cpCellsName)
Exception calling "Set" with "3" argument(s): "
#NAME?"
At line:1 char:1
+ [VisioAutomation.Shapes.CustomPropertyHelper]::Set($g1.VisioShape,"Di ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : COMException

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions