Author Topic: Programmatically adding numerous action items  (Read 1638 times)

0 Members and 1 Guest are viewing this topic.

dolomike

  • Newbie
  • *
  • Posts: 6
Programmatically adding numerous action items
« on: December 20, 2017, 12:46:26 PM »
I'm working on project where users will place multiple color coded lists which then will be populated with multiple color coded list items. Both the list and list items will be pre-defined in a stencil. My idea was to have a simple stencil with one list shape and one list item shape that users would drop and use a context menu to select the "type" of list or "type" of shape they wanted to use which would then color code it accordingly.

I thought it would be easier to add the action menu items programmatically rather than hard coding them in each shape. This way, I can easily maintain an alphabetically sorted and sub-menu'd list rather than tying to do it in the ShapeSheet since it will be updated often. The Action section of the ShapeSheet would be populated when the shape was dropped or when a user selects the "update" context menu command. I think in both methods (drop, update), I would delete the entire actions list then add the list again to ensure it is up-to date as I don't know of any other way to easily check that the structure and each row matches what I want it to be.

I have about 20-30 items that will be added to the context menu but I'm not sure how to add all these items. Can the row be added with a single line or do I need to use a function to manage the index and assign each cell individually?



Hope this makes sense.
« Last Edit: December 20, 2017, 06:07:50 PM by dolomike »

Yacine

  • Hero Member
  • *****
  • Posts: 2710
Re: Programmatically adding numerous action items
« Reply #1 on: December 20, 2017, 01:07:29 PM »
Hope this makes sense.

Interesting question. Could you elaborate some more? may be some pictures and examples?
Yacine

dolomike

  • Newbie
  • *
  • Posts: 6
Re: Programmatically adding numerous action items
« Reply #2 on: December 20, 2017, 02:03:53 PM »
Here's a quick sample visually of what I'm doing. The image shows the context menu for the list/container. It shows one context menu entry with two items but once I have this figured out, it will have multiple context menu entries each with its own set of items. 

When the user selects "Block Type 1" for example, it will change the border and gradient colors as well as the text as shown in the first image. The second image shows what happens when "Block Type 2" is selected.

The same behavior will also occur for the list item as well but I haven't yet created any context menus yet for it.

All the code is maintained in a stencil so that it is easy to update and distribute and users don't have to update all their templates when there is code change. The EventDrop is set to run a sub that I would like to create the context menu when a list/container is placed. The context menu will also contain an "Update Menu" entry which will run the same EventDrop sub so if I release a new stencil with an updated context menu structure, a user wouldn't have to delete and re-ad the list/container to get the updated context menu.

Hope this helps. 


Yacine

  • Hero Member
  • *****
  • Posts: 2710
Re: Programmatically adding numerous action items
« Reply #3 on: December 21, 2017, 10:13:12 AM »
I'm not sure if I understood you well. If you're only after the creating of rows, then you could follow this example:

Code
Sub makeActionRows()
    Dim shp As Shape
    Dim arItems() As String
    Dim t1 As String, t2 As String, t3 As String
    Dim i As Integer
   
    Set shp = ActiveWindow.Selection(1)
    shp.DeleteSection visSectionAction
   
    t1 = ActivePage.PageSheet.Cells("prop.itemsList").ResultStr("")
    arItems = Split(t1, ";")
    t2 = Replace("=CALLTHIS('Foo',,Actions.Row_", "'", Chr(34))
    For i = LBound(arItems) To UBound(arItems)
        r = shp.AddRow(visSectionAction, 0, visTagDefault)
        shp.CellsSRC(visSectionAction, i, visActionMenu).FormulaU = Chr(34) & arItems(i) & Chr(34)
        t3 = t2 & i + 1 & ")"
        shp.CellsSRC(visSectionAction, i, visActionAction).FormulaU = t3
    Next i
End Sub


Sub foo(shp As Shape, arg As String)
    MsgBox arg
End Sub
Yacine

dolomike

  • Newbie
  • *
  • Posts: 6
Re: Programmatically adding numerous action items
« Reply #4 on: January 03, 2018, 01:36:55 AM »
Yes, it was about how to create rows. I have to create a number of Action items for each container that is dropped and after messing around, I ended up using the following:

Code
Sub AddActionItem(shpObj As Visio.Shape, ActionAction1 As String, ActionAction2 As String, ActionMenu As String, ActionFlyoutChild As String)
    Dim index As Integer
    Dim ActionText As String
 
    index = shpObj.AddRow(visSectionAction, 0, visTagDefault)
    shpObj.CellsSRC(visSectionAction, index, visActionAction).FormulaU = Replace(ActionAction1, "'", Chr(34)) & CStr(index + 1) & Replace(ActionAction2, "'", Chr(34))

    shpObj.CellsSRC(visSectionAction, index, visActionMenu).FormulaU = Replace(ActionMenu, "'", Chr(34))
    shpObj.CellsSRC(visSectionAction, index, visActionFlyoutChild).FormulaU = ActionFlyoutChild
End Sub

I made it as flexible as possible to handle all the variations of levels and makes it fairly easy to add new ones. 

Thanks for the help.

Yacine

  • Hero Member
  • *****
  • Posts: 2710
Re: Programmatically adding numerous action items
« Reply #5 on: January 03, 2018, 02:04:05 PM »
Thanks for posting the results of your own work.
Yacine