Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Passing SAFEARRAY type to Visio win32::ole object from Perl

by ketanh (Novice)
on Oct 06, 2012 at 19:07 UTC ( #997640=perlquestion: print w/ replies, xml ) Need Help??
ketanh has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I'm trying to create a spline object in Visio using win32::OLE in perl. I'm struggling with converting the equivalent macro into perl code, especially the part where I have to pass an array of control points and knots for Visio to generate the spline.

The equivalent macro is:

Sub genSplineMy() Dim ControlPoints1(5) As Double Dim Knots1(3) As Double ControlPoints1(0) = 1.5 ControlPoints1(1) = 10.25 ControlPoints1(2) = 2.21642 ControlPoints1(3) = 10.1541 ControlPoints1(4) = 2.375 ControlPoints1(5) = 9.875 Knots1(0) = 0 Knots1(1) = 0 Knots1(2) = 0 Knots1(3) = 2.66958 Application.ActiveWindow.Page.DrawNURBS 3, 0, ControlPoints1, Knot +s1 End Sub

My perl script that is trying to do this:

use strict; use Win32::OLE qw(in with); use Win32::OLE::Variant; use Win32::OLE::Const 'Microsoft Visio'; $Win32::OLE::Warn = 3; my $Visio = Win32::OLE->new('Visio.Application', 'Quit'); $Visio->{Visible}=1 ; my $doc = $Visio->Documents->Open("c:\\work\\tools\\perl\\visio\\basic +_template.vst"); $doc->SaveAs('c:\\work\\tools\\perl\\visio\\test.vdx'); my @controlpoints = (1.5,10.25,1.84606,10.3302,2.21642,10.1541,2.375,9 +.875); my @knots = (0,0,0,0,2.66958); my $variant_controlpoints = Win32::OLE::Variant->new(VT_R8|VT_ARRAY|VT +_BYREF, @controlpoints); my $variant_knots = Win32::OLE::Variant->new(VT_R8|VT_ARRAY|VT_BYREF, +@knots); $Visio->Application->ActiveWindow->Page->DrawNURBS(3, 0, $variant_cont +rolpoints, $variant_knots); $doc->SaveAs('c:\\work\\tools\\perl\\visio\\test.vdx'); $doc->Close;

I get this error when i run the perl script:
OLE exception from "test.vdx - Microsoft Visio":
An exception occurred.
Win32::OLE(0.1709) error 0x86db0898
in METHOD/PROPERTYGET "DrawNURBS" at visio_test.pl line 19

I used the variant type as recommended in the DrawNURBS documentation here: http://msdn.microsoft.com/en-us/library/office/aa224588(v=office.11).aspx
I've tried a bunch of different ways to create that variant and pass it into the DrawNURBS method, but I'm struggling to get it to work.

I can draw a line just fine in Visio using this command

$Visio->Application->ActiveWindow->Page->DrawLine(3.1875, 8.75, 4.875, + 7.5);

It's just the spline and the array argument that's evading me.

Would appreciate any perl wisdom I could be offered here.

Comment on Passing SAFEARRAY type to Visio win32::ole object from Perl
Select or Download Code
Replies are listed 'Best First'.
Re: Passing SAFEARRAY type to Visio win32::ole object from Perl
by Anonymous Monk on Oct 07, 2012 at 01:16 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://997640]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2015-07-29 06:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls