iappyx / Instrumenta

Free and open source consulting-style Powerpoint toolbar
MIT License
251 stars 20 forks source link

Aligning objects over a table #3

Closed Marmootje closed 3 years ago

Marmootje commented 3 years ago

First of all, great work on the latest updates! The convert table to shapes feature sparked new hope in me for a feature I would love to have in Powerpoint. It might be too advanced or difficult to do, but nothing ventured, nothing gained I guess.

A function aligning objects over a table would be very useful. The function should preferably centre the selected shapes to the cells in the selected table (other alignment options would be very welcome as well of course). The shapes will already be on top of the cells in the table so the function has to match the centres of each shape to a cell based on the position of the shape and align it to the centre of the matched table cell.

To make it a bit more clear, please find below an example of what I mean.

Would be great if you could see whether this is feasible!

Thanks for your amazing work on this add-in!

Before: 210423 Align table - before

After: 210423 Align table - after

iappyx commented 3 years ago

Thanks for your feedback. Would actually love to have this feature too. Had to do this many times manually (creating shapes of the column, do the alignment and then remove the shapes again). I have some ideas how to make this work, minor challenge will be how to select the shapes and the table, as you cannot select one column and the logos at the same time. The column or row should be configured. Will look into it.

iappyx commented 3 years ago

Reusing some code from the convert tables to shape function it was actually quite easy to realize. Have released a new version with this requested functionality (for both rows and columns). You can also skip the first row (header row) or skip the first column.

iappyx commented 3 years ago

Please know that you have to select the table first, and then the shapes in the order you want to align them to the rows. This is MVP. I might change that behavior to select table first and then shapes are sorted based on the top-value of the shape.

iappyx commented 3 years ago

Also updated it based on my latest comment. User can now choose to either sort the shape by top position or by order in which they were selected.

Marmootje commented 3 years ago

Fantastic! Thanks alot for this. It works like a charm.

If I may suggest one addition to the feature, it might be nice to not restrict the user to first selecting the table and then the other shapes (since one wrong click could screw up the order). If you start by looping through the selected shapes to determine which object is the table:

Sub ObjectsAlignToTableColumn()

    Set myDocument = Application.ActiveWindow

    Dim Table As Integer
    For i  = 1 To myDocument.Selection.ShapeRange.Count
        If myDocument.Selection.ShapeRange(i).HasTable = True Then
            Table = i
            Exit For
        End If
    Next

    If Table >= 1 Then

Hope this helps. My apologies is there are any errors in the above code (I'm very much a beginner in VBA).

iappyx commented 3 years ago

Yes, was thinking about that too. Problem in that case is that you can have multiple shapes that have tables. How do you make sure that you set the right table? In theory you can also align smaller mini tables to the bigger table.

Option could be to look at the largest table (width x height) that is part of the selection. Will look into it.

Marmootje commented 3 years ago

That's true. I didn't think of that. It is a bit of a niche case but could definitely be a problem. I think looking at the largest table would work. I would however look at the height (when aligning vertical) and width (when aligning horizontal) of the tables rather than the surface area of the table.