4 Replies Latest reply on Jan 14, 2014 4:48 PM by Keith Rice

    InsertMacroFeature Issue's SolidWorks 2014

    Jakob Deslippe

      Hey everyone,

       

      Is there anyway to tell the inserted macro feature to use the original macro path? It seems to use the temp file its creates. I am having issues with the feature inserting into part files. I currently have a template which has this feature inserted, if I delete the feature it will not insert again, I have to restart Solidworks. Also sometimes the feature will work all day then out of no where it doesn't insert, I have to save a restart SolidWorks. Also if I modify my macro I have to be very careful because sometimes it will reference the temp file it creates and delete whatever I have just modified and revert back to whatever the temp file code is.

       

      Does anyone else have issue's like this????

       

      Thanks,

       

      Jakob

        • Re: InsertMacroFeature Issue's SolidWorks 2014
          Keith Rice

          Jakob,

           

          You may already know this, but when you insert a macro feature using IFeatureManager::InsertMacroFeature3, the last argument lets you specify whether to embed the macro feature if the macro is written in VBA. If you choose to embed, there is no way to switch to a non-embedded macro feature. You would need to delete out the macro feature and then reinsert it with the last argument in InsertMacroFeature3 changed to not embed.

           

          Also note concerning embedded macro features and macros added to the design binder: you cannot edit them once they are added. You have to delete them out, make the changes you want to the macro, then re-insert them. Editing the temp macro file will not modify the macro that is actually embedded in the part.

           

          Keith

          SolidWorks API Tutorials

            • Re: InsertMacroFeature Issue's SolidWorks 2014
              Jakob Deslippe

              Keith,

               

              Thank for your reply, I am using the embed argument and the macro is written in VBA. The problem is when I delete that feature I cannot insert it again for some reason. Its really hit or miss, sometimes it will work and other times it doesn't. Thats why I was curious if it had something to do with temp files.

               

              Here is the code that inserts the macro feature and the embed argument:

               

              Dim MacroFeatOptions As Long

                                  MacroFeatOptions = swMacroFeatureOptions_e.swMacroFeatureAlwaysAtEnd + _

                                      swMacroFeatureOptions_e.swMacroFeatureEmbedMacroFile

               

                                  Set cmd_MacroFeat = swFeatMan.InsertMacroFeature("Stock block", "", _

                                      (MacroMethods), (ParamNames), (ParamTypes), (ParamValues), _

                                      Nothing, MacroFeatOptions)

               

               

              I cannot seem to figure out why this macro is not inserting everytime it runs.

                • Re: InsertMacroFeature Issue's SolidWorks 2014
                  Jakob Deslippe

                  Keith,

                   

                  I forgot to mention another really weird thing, If I run this macro from the VBA editor (Play Button) it works every time with no problems.

                    • Re: InsertMacroFeature Issue's SolidWorks 2014
                      Keith Rice

                      What you are describing probably isn't related to macro features. If you run a macro with multiple sub procedures using Tools-->Macro-->Run, SolidWorks doesn't know what sub-procedure to run first (the "entry sub procedure"). In your case, you want it to run the one with InsertMacroFeature3. But it might be running another sub-procedure.

                       

                      There's a few options.

                       

                      First, try putting the sub procedure with InsertMacroFeature3 last in your module---assuming you have only one module. I have found that, by default, the last sub procedure in a single-module macro will always get run first.

                       

                      If you have more than one module in your macro, then you can never rely on the Run button starting with the right sub-procedure. Maybe there is some criteria by which the entry sub procedure is picked, but I don't know what it is. So instead what you need to do is run your macro from a macro shortcut button, because there you can specify your desired entry sub procedure.

                       

                      Directions on how to set up a macro shortcut button.

                       

                      Hope this helps.

                       

                      Keith

                      SolidWorks API Video Tutorials