in reply to How do I dicern and pull data elements from a Visio

I had a look at the Visio module (if that is indeed the one you use) and the Visio::Shape package has the following code to set some text in a Visio-file:
sub set_text { my $self = shift; my $text = shift; my $opts = shift; my $textN = Visio::generic_create_node($self->{shapeNode}, 'Text' ); my $textNode = $self->{xmldoc}->createTextNode($text); $textN->removeChildNodes(); $textN->appendChild($textNode); }
However, there doesn't seem to be a corresponding get_text method.

Also as you will see from the above code, it expects to get some options(?) in $opts which however are never used. Strange, definitely alpha code ...

Update: You will find the official info for the XML-schema used for Visio, here. If everything else fails, you can indeed still use the various XML-tools on cpan to directly access the XML-nodes and attributes and change them.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^2: How do I dicern and pull data elements from a Visio
by eggmatters (Initiate) on Feb 27, 2008 at 23:53 UTC
    Interesting. I've looked at the shapes module in CPAN and there certainly doesn't seem to be any 'get' methods for this. I've also found literally no compendium of OLE documentation for this available. The xml schema is well-formed enough for the purposes of Visio but not for parsing. It appears that they engage some strange encoding and it's a mess trying to escape it all. If I am successful, I will append a module to CPAN once all is said and done.
      If anybody is still tracking this thread: Ok, easy enough to answer. It was yet another thread on this site where I found it. Here is some code that got me started:
      use strict; use warnings; use Win32::OLE; $Win32::OLE::Warn = 3; my $path = "c:\\Documents and Settings\\eggmatters\\Desktop\\VisioProj +ect\\"; my $file = "viSamp.vsd"; my $Visio = Win32::OLE->new('Visio.Application', 'Quit'); my $VDocs = $Visio->Documents; my $VDoc = $VDocs->Open("$path$file"); my $VPage = $VDoc->Pages->Item(1); my $VShapes = $VPage->Shapes; my $VShape = $VShapes->Item(1); $VShape->{Text} = "New Name"; print $VShape->{Text}; $VDoc->SaveAs($path."test2.vsd");
      Here, I've assigned the text before dicerning it but that doesn't matter. To 'get' the text, you just need to call $VShape->(Text); and there you have it. For people like me who have to rely on Visio modeling of Web sites and applications, This will definitely be a huge bonus in implementing validation tools and chart editors.