5 Replies Latest reply on Aug 6, 2013 8:30 AM by Josh Brady

    Event for saving subcomponents

    Christian Neulen

      Hello,

       

      I save an assembly with a modified part. Solidworks asks me to save both files, but the events "FileSaveNotify" and "FileSavePostNotify" are only triggered for the assembly. I suppose this is because the assembly is the active document, so only events for the assembly are fired. How can I trap the saving of the subcomponent?

       

      Thanks in advance.

       

      Regards,

      Christian

        • Re: Event for saving subcomponents
          Josh Brady

          Perhaps a dumb question, but do you have an object variable referencing the subcomponent that is Dim'd WithEvents?  Your macro will only catch events that are raised by objects that you have registered for.

            • Re: Event for saving subcomponents
              Christian Neulen

              Hi Josh,

               

              I have object variables declared WithEvents for each file type Drawing, Assembly and Part. In the event "ActiveDocChangeNotify", I put the active document in the corresponding variable.

                • Re: Event for saving subcomponents
                  Josh Brady

                  It sounds like that is your issue then... The subcomponent never becomes the active document.  Therefore you never catch events for it.

                   

                  If you want to catch events for all referenced documents of an active assembly, you will need to make yourself a collection/array of WithEvents PartDocs whenever the assembly is opened.  I'm not entirely sure the best way to do that.  I've not actually tried it myself.

                   

                  I'm not sure if the referenced component's FileSaveNotify actually happens before the assembly's or not.  I would guess that the one for the assembly happens first.  If that is the case, then you could catch the assembly's FileSaveNotify and then create your array/collection of all of its referenced documents (PartDoc or AssemblyDoc) so you can catch their events.

                    • Re: Event for saving subcomponents
                      Christian Neulen

                      Hi Josh,

                       

                      great Idea, thank you. I use the event "BeginInContextEditNotify" to store an instance of the currently edited subcomponent in a List. I capsulated the WithEvents-Variables in a class because I cannot store WithEvents-Variables directly in a List (as far as I know). Now the Save-Event for every edited subcomponent is fired when the assembly is saved.

                       

                      Best regards,

                      Christian

                        • Re: Event for saving subcomponents
                          Josh Brady

                          Glad I could be some assistance...

                           

                          One thing you may have already considered... I know that you can modify a component of an assembly by just double-clicking a part or feature and changing a dimension (rather than actually entering In-Context edit).  I am not sure, but I think that the BeginInContextEditNotify may not fire in this case.  If your user modifies a component in this manner you may not get it into your list and therefore miss its save event.