2 Replies Latest reply on Sep 1, 2016 4:09 AM by Olivier DAVID

    How to properly Redraw a document periodically

    Olivier DAVID

      Hi,

      I'm currently working onto a project linking a standalone C++ program (let's call it _Prog1_ ) to a C++ Solidworks add-In.

      The idea is to load Solidworks parts within an assembly document and then update the positions of these parts according to data computed by _Prog1_.

      _Prog1_ sends every 0.1 seconds the new positions to the Solidworks add-In.

      In order to refresh positions into the Solidworks view, I call the API method  "iView->IGraphicsRedraw(0)" (assuming iview is a SldWorks::IModelViewPtr and 0 is sent because we want to redraw all the screen). This redraw operation is called periodically every 0.1s in order to produce something like a movement into the Solidworks window. 

       

      Everything usually works fine if nobody touches the Solidworks window. Problems are however sometimes occuring if  Solidworks has to redraw the same window following a user action (resizing or rotating the view...).

      I believe the problem is caused by concurrent access to the  IGraphicsRedraw method that is not correctly managed by my add-in and therefore conflicts with Solidworks Core application trying to do the same thing at the same time.

      So my question is  is there a proper way to redraw a document ?

      I mean are there a set of operations to call, or a set of actions to do, or events to fire if I want to warn Solidworks that I you would like to allow some time and ressources to do a redraw operation ? I'm thinking to something like  a Mutex protected operation in which you prevent third party access to specific ressources until you are finished with your operations.

       

      It would be nice if there was a way to be informed  into my add-in that Solidworks will intend to redraw the window soon. I would therefore skip the redraw step of my add-in until Solidworks is finished.

      I tried without success to subscribe to some events such as swViewRepaintNotify. However, it seems like this event is not the good one (or I'm not using it as it should be).

       

      Off course I also would like to have teh capability to inform Solidworks that I will redraw the window soon and that it should wait a bit before launching its own set of actions.

       

      I was unable to find any answers into other messages so any help will be greatly appreciated.

      Thanks a lot.

      Best regards,

      Olivier

        • Re: How to properly Redraw a document periodically
          Simon Turner

          I use IModelDoc2.IActiveView.EnableGraphicsUpdate = False to stop SolidWorks refreshing the screen whilst my program is processing. This is mainly for performance reasons. However, there are a few limitations - sometimes SolidWorks repaints the screen anyway. And some operations seem to need SolidWorks to be refreshed in order to work.

          When in sketch mode, you can use ISketchManager.DisplayWhenAdded to avoid repainting until you have finished creating sketch geometry.

          If your program is running, then user interaction should ideally be blocked. I think that IModelDoc2.Lock is used for this.

            • Re: How to properly Redraw a document periodically
              Olivier DAVID

              Thanks a lot for this answer. I tried an implementation and it has improved the process. Unfortunately, as you said, sometimes Solidworks repaints anyway which still causes errors. However the frequency of errors seems to be now much lower than it was and this is a good point.

               

              I saw in the API help that the EnableGraphicsUpdate flag has something to deal with the refreshment of the view during selection actions. If this flag is limited to selection actions, this is probably the reason why we still experience some errors.

              I keep this question open just in case someone would have an other idea, but thank you for your help.

              regards,