Share via

Activate a Drawing tool using the object model

Anonymous
2012-11-21T16:51:04+00:00

PowerPoint 2010.

I'm working on an Add-in to provided tools for creating diagrams. (Yeah, I know PowerPoint is for creating slides, but it handles drawing better than Word or Excel.)

Rather than forcing the user to navigate to the Ribbon and search through a gallery, I'd dearly love to have buttons on my Task Pane for drawing Lines and Curves (AutoShapes). I'm not able to find any command that would just turn this on for the user - in essence, press the button, leaving the mouse in "Drawing mode" for the type of tool required. This way, the user could start creating the "line" at the point he wants and going to the intended target.

Or do I really have to use AddLine and BuildFreeForm, which means the started object would be "somewhere" and the user would have to drag it around to get it to the intended start position, then - for a Curve - have to use "Edit Points"?

Microsoft 365 and Office | PowerPoint | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-11-28T16:52:24+00:00

Hmm, can we make use of any legacy 2003 controls?

I just downloaded this: http://www.add-in-express.com/products/commandbars-controls-ids.php and if you scroll down far enough (with ppt 2007), there is (almost at the bottom):

Insert Shape

            ...

Lines

            &Line

            &Arrow

            &DoubleArrow

            &Curve

            &Freeform

            &Scribble

Connectors

            ...

For me, Lines was about 16 top-level Commandbars up from the bottom.

&Freeform has Office ID 200 (&Scribble is 409).

And apparently, we can do this:

    Dim ctrl As CommandBarControl

    Set ctrl = Application.CommandBars.FindControl(Id:=200)

    ctrl.Execute

How’s that?

Cheers

Rich

PS. Curve's Office Id is 1041

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

Answer accepted by question author

Anonymous
2012-11-23T12:44:48+00:00

UPDATE!

I've just discovered that this IS possible!  I was looking for something else in the list of idMso's that can be downloaded from here:

2007: http://www.microsoft.com/en-us/download/details.aspx?id=3582

2010: http://www.microsoft.com/en-us/download/details.aspx?id=6627

In the 2007 version (that I have) of PowerPointRibbonControls.xlsx, you can set the filter for Tab Set Name to "None (not in the ribbon)".  There I found such gems as:

ShapeRectangle

ShapeOval

ShapeElbowConnectorArrow

ShapeStraightConnectorArrow

ShapeElbowConnector

ShapeRoundedRectangle

ShapeStraightConnector

ShapeRightArrow

ShapeDownArrow

ShapeRoundedRectangularCallout

ShapeIsoscelesTriangle

ShapesMoreShapes

ShapeLeftBrace

ShapeRightBrace

ShapeArc

ShapeStar

SnapToShapes

So you can actually do: 

    Application.CommandBars.ExecuteMso ("ShapeStraightConnector")

and let the user click and drag to draw a line.  What I struggle with (and I don't know if you want this) is to then be able to apply some kind of formatting to that shape once it is drawn.  Clearly the new shape should (providing it hasn't been drawn within a Chart object) be the top shape on the slide:

    Dim sld As Slide

    Set sld = ActiveWindow.View.Slide

    Set shp = sld.Shapes(sld.Shapes.Count)

but right now, I can't think of an easy way to detect when the user has finished drawing the new shape.  Do let me know if you can think of one (API for mouse down then mouse up? With a catch for Escape key pressed?).

Hope that helps.

Cheers

Rich

PS. Or, you could just add the built-in controls to your custom ribbon in the xml:

    <toggleButton idMso="ShapeStraightConnector"/>

Was this answer helpful?

0 comments No comments

15 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-11-23T21:32:50+00:00

    I had a look in the 2010 file.  Did you try ShapeConnectorStyleCurved ?

    I've only got 2007, so couldn't test it.

    Cheers

    Rich

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-11-23T16:43:04+00:00

    Hi Rich

    Yes, I found that same idMso list, but didn't have any luck actually using ShapeCurve or Shape Freeform with ExecuteMso when I tried them in PowerPoint 2010 VBA (Immediate Window). Were you able to get it to work? I kept getting a Runtime error 5...

    I'd prefer the command in my Custom Task Pane, but would settle for having them on the Ribbon, if that would actually work. The advantage with the CTP, of course, is that it doesn't matter which Ribbon Tab is currently active - the tools are always there. And one of the reasons I'm doing this is to not have to constantly run up to the Ribbon.

    Formatting isn't a major issue in my scenario as I already have buttons with the five different Line styles + weights appropriate for the type of diagram. It is an extra step, but, as you say, figuring out when the user has finished drawing would be a challenge. I suppose finding out when the user releases the Left Mouse Button a second time would be a reliable trigger... Have to give that some more thought, once I have everything else under control!

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2012-11-23T00:06:16+00:00

    do I really have to use AddLine and BuildFreeForm, which means the started object would be "somewhere" and the user would have to drag it around to get it to the intended start position, then - for a Curve - have to use "Edit Points"?

    I'm afraid there's no way to activate a drawing tool.  If there were an indivdual button for draw line, draw oval, etc., then you could use

        Application.CommandBars.ExecuteMso ("idMso")

    but since the drawing tools are all integrated into a built-in gallery control the don't have their own idMso, so this can't be done.

    So I think this is the only way:

        Dim shp As Shape

        Set shp = ActiveWindow.View.Slide.Shapes.AddLine(BeginX:=50, BeginY:=80, EndX:=150, EndY:=80)

    'or

        Set shp = ActiveWindow.View.Slide.Shapes.AddShape(msoShapeOval, Left:=30, Top:=50, Width:=20, Height:=20)

    But by doing this, you can then apply some of your own "default" formatting to the shp object, thus making your tool a bit more useful, albeit a tradeoff between clicking the built-in drawing tool and being able to draw, or clicking your tool and having to stretch and move an already formatted shape.

    Cheers

    Rich

    Was this answer helpful?

    0 comments No comments