Is it possible to modify attached code so that user can choose a new name for the sketch from drop down list? The pre-condition would be that a sketch would be pre-selected. I was thinking of having an ini file with the new sketch names.
I was spending some time trying to learn to handle the PropertyManager in SolidWorks API. Used this case to play around with and to see if I managed to get something working...
Just had this evening to play around so I will pretty much leave this as is. Use it if you want, tweak it as you want etc etc.... I did this for learning so there is no warranties
What you need to change is the path in the clsRename class to have it point to you ini file. Note that the names will be shown in the the same order as in the file.
bRetVal = GetNames("C:\names.ini")
The ini file is not included. But I think you manage to arrange one. You also might want to change name of the macro file and the class and module.
You could also use an input box and user may fill in the required name.
There seems to be an error with the code. I pre-selected a sketch and ran the macro. I get a message " Please select a sketch and try again"
It is the If statement that do not really work as intended. Splited the If swFeature Is Nothing to be a seperate If statement and now it works. I have encountered previously that mixing If ... Is Nothing with Or statements that has values makes VBA act in a maner that is not intended.
I also changed the handle of sName = vbNullString to be just Exit Sub, since that is what the input box will return if you press Cancel.
Changed also to use the SolidWorks message box in order to keep down the number of things poping up taskbar
It works now but I was actually looking for something where the user can choose the name from a list. I currently have 15 macros like my original post that saves the pre-selected name.
So you want this...
1) user selects the sketch
2) user clicks the macro button
3) user selects name from the list
4) user clicks Ok or Cancel
5) Name is assigned to the sketch or the action is canceled
I looked at the attached macro you have and there is no lists in it... do you already have a macro that you want to add this function to it?
That's exactly what I'm after. I would like to add this functionality to an existing macro. The code below changes the name of the selected sketch to "Recess". I would like the code to be changed so that the user can choose the new name from a list.@
Dim swApp As SldWorks.SldWorksDim doc As ModelDoc2Dim SelMgr As ObjectDim boolstatus As BooleanDim longstatus As Long, longwarnings As LongDim Feature As ObjectSub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDocSet SelMgr = Part.SelectionManagerboolstatus = Part.Extension.SelectByID2("Sketch2", "SKETCH", 0, 0, 0, True, 0, Nothing, 0)Part.SelectedFeatureProperties 0, 0, 0, 0, 0, 0, 0, 1, 0, "Recess"End Sub
Not sure why it has failed though it worked for me earlier
Thanks Daniel Andersson for fixing it.
Feroz Mahomed how are you looking to derive the list; INI or Excel file?
I would like to derive the list from an ini file as it would be easier for me to add more names to the list should the need arise.
Either way, you can modify both the files and have the macro list updated. I'll try to make something tommorrow.
I shall wait for your response.
Your code works well. Thank you for all the help.
Deepak Gupta : Deepak, Thank you for all the assistance as well.
Retrieving data ...