Change Text Color via Powershell Script

Started by cconfused, September 29, 2016, 09:06:25 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

cconfused

hey i want to replace text A with text B and change the font color per script.
i am able to replace the text by script but i do not find a way to change the font color.

here is my script
echo "auto visio edit"
$Visio=New-Object -ComObject Visio.Application
$doc=$Visio.Documents.Add('c:\old.vsd')
$pages = $Visio.ActiveDocument.Pages
$page = $pages.Item(1)
foreach ($shape in $page.Shapes)
{
    if ($shape.Text -like "*TEXTA*")
    {
        $shape.Text="TEXTB"
   echo "replaced"
    }
}
$visio.AlertResponse = 6 #confirm alert with yes
$doc.SaveAs("c:\new.vsd")
$Visio.Quit()


EDIT:
i take a look at the shapesheet and foudn i have to change character.color's value.
this i working for linecolor
$shape.CellsU("LineColor").FormulaU = "=RGB(30, 200, 30)"

i tried this lines but none is working, just throws errors
$shape.CellsU("Color").FormulaU = "=RGB(30, 200, 30)"
$shape.CellsU("Color").FormulaU = 3
$shape.CellsU("Character.Color").FormulaU = "=RGB(30, 200, 30)"
$shape.CellsU("Character.Color").FormulaU = 3

metuemre

Record macro feature will give you something like below;

$shape.CellsSRC(visSectionCharacter, 0, visCharacterColor).FormulaU = "RGB(30, 200, 30)"

cconfused

#2
Fehlende ")" im Methodenaufruf.
Bei Y:\test\test.ps1:16 Zeichen:25
+         $shape.CellsSRC( <<<< visSectionCharacter, 0, visCharacterColor).FormulaU = "RGB(30, 200, 30)"
    + CategoryInfo          : ParserError: (CloseParenToken:TokenId) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingEndParenthesisInMethodCall

I tried the macro recorder it gives me:  $shape.CellsSRC(visSectionCharacter, 0, visCharacterColor).FormulaU = "4"
but when i run the script it says theres a missing close tag ")"

metuemre

Correct syntax to access the text color is "Char.Color". I tried the code below and it works on powershell.

$shape.Cells("Char.Color").FormulaU = "RGB(30, 200, 30)"


cconfused

thanks now i got 2 working methods:

$shape.CellsSRC(3, 0, 1).FormulaU = "2"
and
$shape.Cells("Char.Color").FormulaU = "RGB(30, 200, 30)"

second ones looks much cleaner! thanks!