This is PerlMonks "Mobile"

Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  


in reply to Win32::PowerPoint Extension for Lines and Shapes

This works for me:

use Win32::OLE::Const; # may need to adjust version number depending on what you have install +ed my $const = Win32::OLE::Const->Load('Microsoft Office 12.0 Object Libr +ary'); ...->AddShape($const->{msoShapeRectangle}, ...);

Update:

how to change the color of the line that I can successfully draw

MSDN says: "[AddLine] Returns a Shape object that represents the new line." and clicking through that a bit (plus stealing sub RGB from Win32::OLE::TPJ) gives this, which works for me:

sub RGB { $_[0] | ($_[1] >> 8) | ($_[2] >> 16) } my $shape = $slide->Shapes->AddLine(100,200,300,400); $shape->{Line}{ForeColor}{RGB} = RGB(255,0,0);

Replies are listed 'Best First'.
Re^2: Win32::PowerPoint Extension for Lines and Shapes (updated)
by nzsvz9 (Sexton) on Mar 07, 2021 at 18:16 UTC
    Thanks huakex - the color thing worked great. It gives me the syntax and approach I need to get more things to work (like line thickness and so on). There is already in the Win32::PowerPoint::Utils a subroutine for RGB .. so I'll try to use that.

    However, I'm struggling with the shape still. There is a module for Win32::PowerPoint::Const - but it does not include all the msoShape* items I want to use. In the constants module there are some definitions (I think Microsoft calls them Enumerations - MsoAutoShapeType enumeration (Office) - but whatever) but none for the shapes:

    # msoPatternType msoPattern10Percent => 2, msoPattern20Percent => 3, msoPattern25Percent => 4,
    So I'm going to try to extend that module to include the definitions I found in MSDN for the shapes like this:
    # msoAutoShapeType msoShapeRectangle => 1, msoShapeParallelogram => 2, msoShapeTrapezoid => 3,
    And use them ... as the Win32::OLE::Const->Load('Microsoft Office 12.0 Object Library'); I could not determine which Office to load as I've got 365 from work and the documentation is poor. Why Microsoft has to be so obtuse about everything is beyond me, but I digress.

    Thanks for your help. It's appreciated. If anyone else has any ideas - please add them - always welcome!!!

    One more thing ... after I add these other functions, I want to update the original Win32::PowerPoint module (and sub modules) back in CPAN as opposed to adding a new module cloned and forked from the original - so any pointers on how to start down that path would be very helpful.

      Win32::OLE::Const->Load('Microsoft Office 12.0 Object Library'); I could not determine which Office to load

      Yes, that's a little tricky; I actually had to check the registry at HKEY_CLASSES_ROOT\Typelib to figure that out for my machine. There's probably a way to get that information programmatically (I do see some code in Win32::OLE::Const relating to TypeLib), but unfortunately I'm not an expert on that.

      So I'm going to try to extend that module to include the definitions I found in MSDN for the shapes

      You can certainly try doing that, although I thought you said in the root node it didn't work when you tried your own numeric constants? If it were me, I'd first expend some energy trying to see if I can get the constants from the TypeLib before hardcoding my own constants.

      I want to update the original Win32::PowerPoint module (and sub modules) back in CPAN as opposed to adding a new module cloned and forked from the original - so any pointers on how to start down that path would be very helpful.

      The first step is to get in touch with the author of Win32::PowerPoint, for example by filing a pull request with your modification suggestions. If for whatever reason there is a disagreement about adding your features into the distribution, instead of forking, you can design your module as an add-on; since the module is OO, you should be able to create a subclass, and then release that as a distribution to CPAN. If for some reason the author is unresponsive, see How do I go about maintaining a module when the author is unresponsive?.