in reply to WIN32::OLE interface to Mathcad

You're on the right track, but you'll find that there's not a huge amount of resources for what you're doing. After a bit of Googling (for matchcad ole) I found a link describing the MathCAD OLE interface

What you can do is to examine the MS Word and MS Excel examples for the Perl-ish syntax. The syntax tries to emulate the VBA code as much as possible within the constraints of the language

As mentioned on the Matchcad OLE page, your best bet for finding functions and properties is to use the object browser to find "hooks".

Good luck with it!

Replies are listed 'Best First'.
Re^2: WIN32::OLE interface to Mathcad
by forgedascendant (Novice) on Apr 07, 2009 at 16:25 UTC
    I looked around and read the documentation on the Win32::OLE and looked through the many methods and properties available in mathcad. The good news is I got the perl script to open the correct sheet. The code thus far is:
    #!/usr/ym/util/perl use Win32::OLE; #use existing instance if mathcad is already running eval {$MC = Win32::OLE->GetActiveObject('Mathcad.Application')}; die "Mathcad not installed" if $@; unless (defined $MC) { $MC = Win32::OLE->new('Mathcad.Application', sub{$_[0]->Quit;}) or die "Unable to start Mathcad"; } #Figure out point of orgin and verify MC works my $h = $MC->fullname; print "$h\n"; #Open specific worksheet my $filePath = 'C:\Documents and Settings\aaron.verellen\Desktop\trial +.xmcd'; $MC->{DefaultFilePath} = $filePath; my $WS = $MC->Worksheets->Open($filePath); if ($WS->{IsOpen}) { print "Congratulations the file is open ;P\n"; } else { print "DENIED: Try opening the file again\n"; } #prove the WS object my $Name= $WS->{Name}; print "Name: $Name\n"; #Retrieve a value from the worksheet my $varable = 'number'; my $value = $WS->GetValue($varable); print "$varable = $value\n"; $WS->Recalculate; $WS->save; $WS->close; #$MC->Quit;
    This will open, recalculate the sheet, save and close the sheet. What I can't figure out is how to get a value from the mathcad sheet into the perl program. When I run the code it does not give me any errors. The results are as follows:

    C:\>perl "C:\documents and settings\aaron.verellen\desktop\trial.pl C:\Program Files\Mathsoft\Mathcad 12\mathcad.exe
    Congratulations the file is open ;P
    Name: trial.xmcd
    number =

    The mathcad sheet is simple:
    number:=2
    poly(x):=x^2+2
    poly(number)=6

    Does anyone have any guesses as to why the value is not getting back to the perl program? Again, any guesses or help is much appreciated.

    Aaron