4 Replies Latest reply on Mar 9, 2017 9:16 AM by Joe Pickens

    Addin Event Handling FileSaveAsNotify2 to add Comment

    Joe Pickens

      I am creating a Solidworks AddIn and one of the things I'm trying to do is, I want to catch when someone does a save as to a component. I want to wright in the comments part of the property manager the name of the file the document was saved from. I result when someone does a save as to a component. In the comments of the new part it will state Component (serial#) made from Component (serial#).

       

      I have captured the save as event using FileSaveAsNotify2 but how do I get a hold of the new component name and how do i wright to the comments in the new component?

        • Re: Addin Event Handling FileSaveAsNotify2 to add Comment
          Joe Pickens

          Ok i made some advancements and I almost got it I think.

           

          so first off i use the event handler FileSaveAsNotify2 to get the name of the file being saveased and then i use FileSavePost to get the new document name. I am trying to use this code to input my new comment but its not working.

          So i am trying to wright to the comments part of the custom property but intstat = CustMgr.Set2("Comments", "Hellow World"); equats to 1 which means Custom property does not exist and my PropNamesList which im trying to use to verify the names of the custom properties comes back null

           

                          int errors = 0;

                          int warnings = 0;

                          int intstat;

                          int error;

                          object PropNames = null;

                          object PropTypes = null;

                          object PropValues = null;

                          object Resolved = null;

           

                          object[] PropNamesList = null;

           

                          ModelDoc2 Comp = iSwApp.OpenDoc6(filename, SWType, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);

           

                          Configuration config = (Configuration)Comp.GetActiveConfiguration();

           

                          CustomPropertyManager CustMgr = config.CustomPropertyManager;

           

                          /* 0 = Success

                           * 1 = Custom property does not exist

                           * 2 = Specified value has an incorrect type

                          */

                          intstat = CustMgr.Set2("Comments", "Hellow World");

           

                          PropNamesList = (object[])CustMgr.GetNames();

           

                          intstat = CustMgr.GetAll2(ref PropNames, ref PropTypes, ref PropValues, ref Resolved);

           

                          foreach (string Name in (string[])PropNames)

                          {

                              string CName = Name;

                          }