Document_ShapeAdded how to filter copied shapes ?

Started by ivan, May 02, 2010, 03:17:03 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ivan

I use Document_ShapeAdded even to launch some script - i want it to be launched if i draw a line.
i use the following code
Quote'Debug.Print vsoShape.GeometryCount
geom_c = vsoShape.GeometryCount
geom1_r = vsoShape.RowCount(visSectionFirstComponent)

If Not ActivePage.name = "исх. схема" Then Exit Sub
   
    If geom_c = 1 And geom1_r = 3 Then
thus code is exacuted for definite page and if shape is a line.
THe problem is if i copy-paste part of the drawing (manually or via macros)  macro is exacuted a lot of times - i don't need it.
how can i avoid this ?
maybe it's possible to enable/disable Document_ShapeAdded  macro ? or is it possible to get if shape is copy/pasted ?

aledlund


Shapeadded can be fired by a lot of different scenarios, so you might want to check to see what 'scope' it is embedded in. The following might give you some ideas on what can be looked for

al



    '********* visio snippet vb.net vis0050vb ******************

    Private WithEvents pageShapeIsOn As Microsoft.Office.Interop.Visio.Page
    Private eventApplication As Microsoft.Office.Interop.Visio.Application

    Private Sub shapeAddedEventHandler _
        (ByVal addedShape As Microsoft.Office.Interop.Visio.Shape) _
        Handles pageShapeIsOn.ShapeAdded

        Try

            ' Passing visCmdObjectGroup as a parameter to the IsInScope
            If eventApplication.IsInScope(VisUICmds.visCmdObjectGroup) Then
                'Debug.Print("Shape added using grouping action. " _
                '    & "Master name of the shape - " _
                '    & strMasterName)

                ' is in scope with apply data graphic
            ElseIf eventApplication.IsInScope(VisUICmds.visCmdApplyDataGraphic) Then
                'Debug.Print("Shape Added using Apply Data Graphic")

                ' IsInScope with visCmdUFEditPaste parameter returns
            ElseIf eventApplication.IsInScope(VisUICmds.visCmdUFEditPaste) Then
                'Debug.Print("Shape added using EditPaste action. " _
                '    & "Master Name of the Shape - """ _
                '    & strMasterName)

                ' IsInScope with visCmdEditPasteSpecial parameter
            ElseIf eventApplication.IsInScope(VisUICmds.visCmdEditPasteSpecial) Then
                'Debug.Print("Shape added using EditPasteSpecial " _
                '    & "action. Master name of the shape - " _
                '    & strMasterName)


            ElseIf eventApplication.IsUndoingOrRedoing() = True Then
                'Debug.WriteLine("Shape is added as a result of Undo/Redo.")

                ' If the shape is added using a normal user draw action, show
                ' the name of the shape being added.
            Else

                System.Diagnostics.Debug.WriteLine( _
                    "A shape has been added." _
                    & vbCrLf & "The universal name of the shape is " _
                    & addedShape.NameU)

            End If

        Catch err As System.Runtime.InteropServices.COMException
            ' add com exception handler here

        End Try

    End Sub


ivan

can't get your exmaple to work. can you post vsd example ?

aledlund

actually the good news is the latest sdk (v2010) has replaced the vb6 code samples with vba samples and the above code has a version in it for shape added events.
al

ivan