Is there a way to delete the custom properties of a part file and to put new ones back automatically. We have a number of files that do not have the properties we use (e.g. profile file for the welded mechanic). The goal is to quickly restore the new properties in these files.
We are running SW 2016 Premium version - We do not have the MyCad tools.
Yes, it allows you to update existing properties or create new ones, but there is no possibility to delete existing properties so as not to end up with an important list of properties and unnecessary fields. How can I delete existing properties?
You'll be able to use the Task Scheduler to create and replace your properties, and if you use the macro recorder to delete properties that due doesn't need. You can also launch it with the scheduler and choose the files in question.
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim config As SldWorks.Configuration
Dim cusPropMgr As SldWorks.CustomPropertyManager
Dim lRetVal As Long
Dim ValOut As String
Dim ResolvedValOut As String
Dim wasResolved As Boolean
Dim nNbrProps As Long
Dim vPropNames As Variant
Dim vPropTypes As Variant
Dim vPropValues As Variant
Dim resolved As Variant
Dim custPropType As Long
Dim K As Long
Dim NomProperty As String
Set cusPropMgr = swModelDocExt.CustomPropertyManager("")
nNbrProps = cusPropMgr.Count
vPropNames = cusPropMgr.GetNames
For K = 0 To nNbrProps - 1
cusPropMgr.Get2 vPropNames(K), ValOut, ResolvedValOut
custPropType = cusPropMgr.GetType2(vPropNames(K))
If vPropNames(K) = "Description" Then
NomProperty = ResolvedValOut
End If
If vPropNames(K) = "Dessinateur" Then
PropMgr.Delete(vPropNames(K))
End If
Next K
The lines:
If vPropNames(K) = "Description" Then PropertyName = ResolvedValOut End If
Measure the value of the "Description" custom property.
The lines:
If vPropNames(K) = "Draftsman" Then PropMgr.Delete(vPropNames(K)) End If
Ok, I see the principle but at the level of the macro I don't know enough in VBA, to create it, I tried to save a macro aecla deletion of the properties but it doesn't work ... the macro is almost "empty"
Perfect, I want to do one last thing in the task scheduler, I launch the macro with "run the custom task" but can we target this or that folder, I first want to do a test with some of the files.
Ok, to start the creation of a new property on a folder, but to use the delete macro I use "execute task" (see attached image) there are no fields to point to a particular folder...
I don't know enough about this feature but nothing prevents you from managing it in your macro by loading a file containing the list of your 3D to process. Your macro then has to open each file in SW, delete the custom properties and then save it before moving on to the next one.
Thank you for your feedback and your explanations, but I really lack the skills to make this type of macro ... so I prefer to keep it simple... Is it possible to launch the macro from the task scheduler by specifying a particular folder? In a second time I will add the new properties via the task scheduler (this second part is ok for me)
I don't know if this is possible but in my opinion the macro will still have to analyze all the files present in the folder that would have been passed as an argument by the task scheduler.
For this type of operation to be done, I'm not sure if there is really a need for the task scheduler (it is only used to run the macro at a staggered time).
Ok I understand d. roger but "ac cobra 427" indicates that you can launch the macro from the task scheduler ... ac cobra 427 can you tell me the procedure to follow and how to select only the desired files (ok for custom properties, Nok to launch the macro on some files)
Dsl I never needed the task scheduler, I thought it worked because they talk about being able to launch a macro... In the worst case, if you have never had the Mycad tools, you can download and test for 1 month I think...
Otherwise what is the code for VBA to create a property line and associate a value, I was thinking of doing it with the task planner but it doesn't work very well it doesn't accept empty fields (e.g. the description will be filled in manually afterwards by the draftsman)