in reply to PowerPoint.pm extension for AddPolyline not working

According to the Microsoft documentation for AddPolyline, the method takes a Variant datatype. Without testing, you should be able to create a (2-dimensional) Variant that contains an array (of integers) like this:

use Win32::OLE; use Win32::OLE::Variant; my $pointcount = 4; # 4 points my $point_dimensions = 2; # The arrayrefs mean we use 1-based indices, like the VBA examples do: # my $pointlist = Variant(VT_ARRAY | VT_R4 , [1,$pointcount], [1,$poin +t_dimensions]); # Alternatively, use 0-based indices, like Perl does: my $pointlist = Variant(VT_ARRAY | VT_R4 , $pointcount, $point_dimensi +ons); $pointlist->Put( 0,0, 25 ); $pointlist->Put( 0,1, 100 ); ... $slide->Shapes->AddPolyline($pointlist);

The MS documentation suggests that the SafeArryOfPoints should be a 2-dimensional array.

Replies are listed 'Best First'.
Re^2: PowerPoint.pm extension for AddPolyline not working
by EnzoXenon (Acolyte) on Jun 14, 2023 at 12:15 UTC
    Corion ... thank you very much!

    Here's what I put into the PowerPoint module per your guidance on Win32::OLE::Variant (which I looked up on CPAN afterward ... because I should learn how to read)

    # Get the points my @points=@{ $options->{points} }; # Create the Win32::OLE::Variant my $pointlist = Win32::OLE::Variant->new(VT_ARRAY | VT_R4 , 4, 2); # Convert points to Win32::OLE::Variant for my $index (0 .. 3) { # Add x $pointlist->Put( $index, 0, shift(@points) ); # Add y $pointlist->Put( $index, 1, shift(@points) ); } my $new_poly=$self->slide->Shapes->AddPolyline($pointlist);
    So I could make the call into the function simple ...
    # Add filled Triangle $PPT->add_polyline( {'points' => [$pptpoints[0], $pptpoints[1 +], $pptpoints[2], $pptpoints[3], $pptpoints[4], $pptpoints[5], $pptpo +ints[0], $pptpoints[1]], 'fillcolor' => &convert2RGBvalues($fill), 'weight' => $weight/px2pt, 'forecolor' => &convert2RGBvalues($color) } +);
    Meaning the user will only have to define a list of three coordinate pairs in perl to make a triangle in PowerPoint.

    EXCELLENT!