6 Replies Latest reply on Oct 16, 2012 9:12 AM by Jeremy Schmidt

    determine which files have been modified

    Jeremy Schmidt

      I was disappointed to find out that the "Don't prompt to save read-only referenced documents (discard changes)" doesn't work when doing a save as.  If any of the sub components of an assembly have been modified (ie: they have an asterisk next to them in the header), SolidWorks still prompts the user to save them.  When doing a save, they are not prompted.  So I'm trying to create a work around for this inconsistency.  I'd like to programatically prevent SolidWorks from attempting to save these child components or prevent the save as all together.  I was also disappointed to find out that post save event does not run on the parent component if the pre save as event of one of the child components is cancelled.  In other words, I can't just cancel the save of the child components.  Any suggestions?  My latest thought is to try and determine if any of the child components have been modified, and if so, notify the user and cancel the save as.  The whole reasoning behind this is that I have critical operations running in the post save events that aren't run if the user cancels the save of any of the modified documents.  Ideally, it just wouldn't prompt to save the children, but this doesn't seem to be an option.

        • Re: determine which files have been modified
          Keith Rice

          Jeremy,

           

          Its hard to tell whether you are referring to a macro you wrote or something you are doing manually.  Can you clarify what you are trying to accomplish and how you have thus far tried to accomplish it? Then hopefully I'll be able to share some ideas.

           

          Keith

          Video Tutorials for the SolidWorks API

            • Re: determine which files have been modified
              Jeremy Schmidt

              Keith,

               

              I'm writing a SolidWorks add-in.  I have code that runs during the pre and post save events.  I recently discovered that if a child of an assembly has been modified, and a save as is done to the assembly, that SolidWorks tries to do a save as of the modified component.  If the user hits cancel during the save as of the child component, the post save event of the parent assembly does not occur.  This is a problem.

               

              Ideally, I'd like to prevent SolidWorks from trying to do a save as to child components in an assembly when a save as is done to the assembly.  I can't figure out a way to do this.  I thought that the "Don't prompt to save read-only referenced documents (discard changes)" option would do this, but apparently not.  If there's a way to do this through the API, that would be just fine.

               

              Another option would be to cancel the Save As of the child components.  However, when I cancel the save as event of a child (return -1), the post save event of the parent does not run.

               

              Another option would be to prevent the save as of the parent altogether if any of the children have been modified.  I cannot figure out a way to do this either.

               

              Let me know if I need to clarify anything further.

                • Re: determine which files have been modified
                  Artem Taturevych

                  ModelDoc2::GetSaveFlag should help. Please check the macro in the attachment which determines whether there is at least one unsaved component.

                   

                  ______________________

                  Regards,

                  Artem Taturevych

                  Application Engineer at Intercad

                  http://intercad.com.au/

                  Tel: +61 2 9454 4444

                    • Re: determine which files have been modified
                      Jeremy Schmidt

                      Thank you very much Artem.  The GetSaveFlag method is exactly what I was looking for my option to prevent the save as of the parent.  Although this is not the ideal fix, it will at least get me closer and prevent some of my issues.

                       

                      Does anyone know if there's a way to prevent the save as of the child components without preventing the post save event from firing?

                        • Re: determine which files have been modified
                          Artem Taturevych

                          I may be wrong but I think what you are looking for is incorrect behaviour. Usually the assembly file depends of the children (display data, references etc.). And if you can only save top assembly but not children this may produce extra problems when opening file next time. Even if you find some workaround not sure that this will not produce unexpected behaviour in future.

                          ______________________

                          Regards,

                          Artem Taturevych

                          Application Engineer at Intercad

                          http://intercad.com.au/

                          Tel: +61 2 9454 4444

                            • Re: determine which files have been modified
                              Jeremy Schmidt

                              I understand your concern, however, the files I'm trying to prevent from being saved are read-only anyway.  I have the "Don't prompt to save read-only referenced documents (discard changes)" option enabled, but this only appears to prevent the prompt when the "save" button is pushed, not the "save as" button.  In fact, it seems to be directly related to the button and not the actual process.  For example, whether you click the save button or the save as button on the initial save of an assembly, the save as process runs.  This makes sense and I agree with it.  However, if you hit the save button and a read-only child has been modified, it will not prompt to save the child if that option is enabled.  But if you hit the save as button in the same scenario, it does prompt to save the child.  This makes no sense to me.  The exact same process is happening.  Why would one button cause the prompt, but not the other?

                               

                              That being said, it doesn't make sense to me, but it is what it is.  So I'm just trying to prevent SolidWorks from prompting to save the read-only components as the option suggests it does, and does do if the save button is clicked.  I'd like to repeat what I saw in another post.  You can sneeze and SolidWorks thinks the document needs to be saved.  We have countless scenarios in which a user will have a child open and SolidWorks thinks it needs to be saved, even when it doesn't.  This is especially true when the child is read-only.

                               

                              Again Artem, thank you for your help.