2 Replies Latest reply on Nov 15, 2018 7:39 PM by Win Lai

    ViewChangeNotify Can not Fired

    Win Lai

      Dear Everybody,

      I have a question about swModelView notify.I have create a SW api Project with SW2016 API SDK, and add ViewChangeNotify code(Hight light with red color) .

      But it can not fired, can you tell me why?

       

      thank you very much!

       

      'Here is my VB.net code================================================

          Dim WithEvents iModelView As ModelView

       

          Function AttachEventHandlers() As Boolean

              AddHandler iModelView.RepaintNotify, AddressOf Me.ModelView_RepaintNotify

              AddHandler iModelView.ViewChangeNotify, AddressOf Me.ModelView_swViewChangeNotify

          End Function

       

       

          Function DetachEventHandlers() As Boolean

              RemoveHandler iModelView.RepaintNotify, AddressOf Me.ModelView_RepaintNotify

              RemoveHandler iModelView.ViewChangeNotify, AddressOf Me.ModelView_swViewChangeNotify

          End Function

       

          Function ModelView_RepaintNotify(ByVal repaintTYpe As Integer) As Integer

             'Fired Successful!

          End Function

       

       

          Function ModelView_swViewChangeNotify(ByVal View As Object) As Integer

             'can not fired

          End Function

      'Here is my VB.net code================================================

        • Re: ViewChangeNotify Can not Fired
          Gennadiy Tsybikov

          You have to assign iModelView variable first and then Attach Event Handlers. You can use either Class Constructor or Button Click Event Handler. In the example below I use Class Constructor:

           

              Dim SwApp As New SldWorks.SldWorks
              Dim SwModel As ModelDoc2
              Dim WithEvents iModelView As ModelView
          
          
              Sub New()
                  SwModel = SwApp.ActiveDoc
                  iModelView = SwModel.ActiveView
                  AttachEventHandlers()
              End Sub
          
          
              Sub AttachEventHandlers()
                  AddHandler iModelView.RepaintNotify, AddressOf Me.ModelView_RepaintNotify
                  AddHandler iModelView.ViewChangeNotify, AddressOf Me.ModelView_swViewChangeNotify
              End Sub
          
          
              Sub DetachEventHandlers()
                  RemoveHandler iModelView.RepaintNotify, AddressOf Me.ModelView_RepaintNotify
                  RemoveHandler iModelView.ViewChangeNotify, AddressOf Me.ModelView_swViewChangeNotify
              End Sub
          
          
              Function ModelView_RepaintNotify(ByVal repaintTYpe As Integer) As Integer
                  'Fired Successful!
          
          
                  Return 0
              End Function
          
          
              Function ModelView_swViewChangeNotify(ByVal View As Object) As Integer
                  MessageBox.Show("View has been changed.")
          
          
                  Return 0
              End Function