Modify master objects on a stencil

Started by goldnhue, July 10, 2008, 05:12:40 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

goldnhue

I need to temporarily remove the drop event from the masters on a stencil (so I can drop them through automation without pop-up appearing).    I can remove the drop event OK, but I can't it back to the stencil objects for some reason.  My code is below.  Any suggestions?  Am I grabbing the stencil/masters incorrectly? (but then why would it work to remove the event, but not add it back? ... perhaps my syntax wrong?

Thank you in advance.

Sub testit()
             Dim zz As Integer, fname As String, mst As Visio.Master
Dim shpsObj As Visio.Shapes, shpObj As Visio.shape
             Dim nrows As Integer, i As Integer, celobj As Cell

'------- Get Master stencil
Set docFlowTemplate = Visio.ActiveDocument
For Each doc In Visio.Documents
  If InStr(doc.Name, "Process Model") > 0 Then
        Set docFlowStencil = doc
        Exit For
  End If
Next
Set doc = Nothing

'--------- Clear the Activity master drop event on the stencil
zz = 1
For Each mst In docFlowStencil.Masters
    fname = docFlowStencil.Masters.ItemU(zz).Name
    If InStr(fname, "Activity") Then
        Call removedrop(docFlowStencil.Masters.ItemU(zz), "remove")
    End If
    zz = zz + 1
Next

'----- do my automationd stuff adding objects to page

'-------Add the drop event back on each master
zz = 1
For Each mst In docFlowStencil.Masters
    fname = docFlowStencil.Masters.ItemU(zz).Name
    If InStr(fname, "Activity") Then
        Call removedrop(docFlowStencil.Masters.ItemU(zz), "add")
    End If
    zz = zz + 1
Next
End sub

Sub removedrop(objMaster As Visio.Master, dropevnt As String)
    ' changes the drop event
    Set shpsObj = objMaster.Shapes
    Set shpObj = shpsObj(1)

    Set celobj = shpObj.CellsSRC(Visio.visSectionObject, visRowEvent, visEvtCellDrop)
     if dropevnt="add" then
            celobj.FormulaForce = "=DOCMD(1312)"
     else
      celobj.FormulaForce = "="
     end if
End Sub

Lars-Erik

You should check if it really runs the code to add them back, add a MsgBox("Hello") to the adding the drop event part to see if it is run.

goldnhue

Thank you for suggestion.

I added:   Debug.Print (shpObj.Name & " Formula=" & celobj.Formula)

and it returned:   Activity.12 Formula=DOCMD(1312)

So it appears to be setting the formula on one of the objects I dropped on the page during the drawing automation, not the original stencil object. ... How do I make it grab the original stencil master instead of whatever it's grabbing?


Lars-Erik

After dropping the shape on the page, the active document is switched to the page? and no longer is the stencil?

QuoteSet docFlowTemplate = Visio.ActiveDocument

Just a thought...

Visio Guy

And please, please, please follow the advice in this article when programmatically editing masters:

Edit Visio Masters Programmatically...the Right Way!
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010