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
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
I still wish I could run the macro without having the user to press Ctrl+Q...
Doesn't this require the Event Listener macro to run on every single workstation? I know we can add "/m" in the SW shortcut to run the macro when SW launches, but SW can be run by various methods that do not accept macro script. Also it is going to be a challenge to make sure all workstations are running the macro all the time.
Also, Deepak you are a hero! Your posts here have helped me tremendously in the past couple years. Just wanted to say that. Keep it up!
Thanks for the kind words, I'm just giving back what I've learned from others and sharing what I've.
Regarding your question, yes you would need to run that macro on each machine. But you can use an add-in and set that to run with SW automatically irrespective of how SW has been started.
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.
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.