7 Replies Latest reply on Jun 17, 2018 1:23 PM by Deepak Gupta

    Macro Feature, Embedded Macro, Event Listener?

    Ctm Pdm Admin

      The Goal: Make sure configuration name matches the file name (instead of "Default") every time user creates a new Part from the template (we are using PDM).

       

      Half of the Solution: I have a simple macro that renames the active configuration (short version below). I want this macro to be part of the SLDPRT template and run automatically (because I can't rely on users to press that macro button every time they start a new model).

           If swConfig.Name = "Default" Then

                swConfig.Name = FileName

           End If

       

      The Problem: I tried embedded-macro triggered-by-equation method, but it doesn't seem to work in newer versions of SWx.

      I have read a little about "Macro Feature" and "Event Listener" and can't figure out how any of them work. Can someone let me know how I can run this simple macro as part of the SW Part template?

       

      Any other method to achieve the same goal is also appreciated.

       

      Thanks

        • Re: Macro Feature, Embedded Macro, Event Listener?
          Ctm Pdm Admin

          Update: I was able to add a macro feature to the part template that does the rename upon rebuild.

           

          My three questions now are:

           

          1- The rebuild function in the macro-feature is triggered only by a "Ctrl+Q" forced rebuild. Is there any way to make the macro feature run with a normal Rebuild?

          2- The macro feature still references the source .swp file that I used to create it. How can I fully embed the macro feature into the part model?

          3- Can I remove the macro feature automatically after the "main" sub is run once? How?

           

          Here is the code I'm using to insert the macro-feature (credit to Keith Rice):

           

               Dim strMacroMethods(8) As String

           

               strMacroMethods(0) = swApp.GetCurrentMacroPathName

               strMacroMethods(1) = "mMacroFeature"

               strMacroMethods(2) = "swmRebuild"

           

               strMacroMethods(3) = swApp.GetCurrentMacroPathName

               strMacroMethods(4) = "mMacroFeature"

               strMacroMethods(5) = "swmEditDefinition"

           

               swModel.FeatureManager.InsertMacroFeature3 "Rename Config", Empty, strMacroMethods, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, 0

            • Re: Macro Feature, Embedded Macro, Event Listener?
              Ctm Pdm Admin

              Found the answer to my questions 2 and 3

               

              2- Must use "swMacroFeatureOptions_e.swMacroFeatureEmbedMacroFile" for the last argument of InsertMacroFeature3 method instead of 0 to embed the macro in the file itself. Example:

               

                   swModel.FeatureManager.InsertMacroFeature3 "Base Name", Empty, strMacroMethods, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, swMacroFeatureOptions_e.swMacroFeatureEmbedMacroFile

               

              3- Adding the following code to the main sub (swmRebuild function in my case) can remove that macro feature from the Feature Tree after it is run:

               

                   Dim swFeat As SldWorks.Feature

                   Do While Not swFeat Is Nothing

                        If swFeat.Name = "Name of the Macro Feature" Then swFeat.Select (False)

                        Set swFeat = swFeat.GetNextFeature

                   Loop

                   swModel.Extension.DeleteSelection2 (swDeleteSelectionOptions_e.swDelete_Absorbed)

               

              I still wish I could run the macro without having the user to press Ctrl+Q...

            • Re: Macro Feature, Embedded Macro, Event Listener?
              Josh Brady

              Requiring that the configuration name match the filename does not seem to me to be a good workflow.  Of course I have no idea what it is you're doing, but I am almost certain that there is a better way of achieving whatever it is you're trying to do by setting the configuration name equal to the filename.

                • Re: Macro Feature, Embedded Macro, Event Listener?
                  Ctm Pdm Admin

                  It is a rather long story, but a shorter version would be: We work on highly configured models as well as single configuration models. Every time the models get released for production or prototyping, the PDM workflow generates Parasolid (X_T) files for CAM people. The SW Task Add-in uses configuration names to create those parasolids for each configuration (because we can't use part number variable from data card due to the fact that x_t files cannot have "%" character in their file name and whoever wrote the code for SW Task Add-in missed it). Now when users are working on single configuration models, they forget to rename their configuration to match the part number and thus conversion task creates files "Default_Rev.x_t" and basically fails. For highly configured models they use design tables and config names are part numbers.

                   

                  Thus, I want to automate this as part of the template to rename the "Default" configuration to match the Part Number they use to create the file the first time. If they need to change it later they can, this is just to avoid the "Default".

                   

                  I know there are multiple other ways to solve this problem but they all require more extensive coding and I am just an engineering manager who happens to be the PDM admin as well.