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


In reply to Re^2: WIN32::OLE interface to Mathcad by forgedascendant
in thread WIN32::OLE interface to Mathcad by forgedascendant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.