*****Re-posted this topic as a question from original post Model Cleanup Macro . mistakenly made it a discussion at the time*****
I know this has been asked before in several different combinations and permutations over the years
Recently we have migrated from 2016 WGPDM to PDMPro 2020
As you might imagine there is a vast amount of legacy CAD DATA that has not been upgraded/cleansed prior to migration.
I would like to create a little macro for my users to help the model and drawing "cleansing/version upgrade" become a little easier
A few points to make:
- I am aware of the File version upgrade tool that could be batch run on the server. However our data is so old and so mixed up in legacy SW versions that running it causes error or failures, have tried on a sample selection of files, did not work.
- #TASK is not a possibility for us in terms of batch processing this, or using their built in macros , since they have recently upgraded to a paid tier version, therefore excluding as an option
- My macro skills are novice to none.
- SW API is not an option (my skills there are non-existent)
On Currently open model:
- Saves current file (to convert to latest SW version)
- Upgrades cosmetic thread features
- Prompts user with drafting standard selection. Drafting standards managed by Vault. Local vault view root varies between client machines (c:\, d:\), so prompt should be "drive agnostic" or %root vault view folder%
- Applies selected drafting standard
The idea would be to eventually map this to a macro button on the tool bar and deploy it to users via administrative image, hence the importance of %root vault view folder% mentioned above (I believe that would be the way?)
Thank you for any help you might be able to provide
****Update***
After attempting to record my intended actions and looking at the resulting file and also getting a very handy piece of code from here for the "Upgrade cosmetic threads" function I have scraped together this extremely basic Macro below.
I'm sure its super messy and can be cleaned up and simplified
My question now is how to make this "universal"
Line 17 - is specific to the test part I recorded the macro on (??), how would I make it just work on the open part?
Line 16-18 - I assume this is me clicking yes to the warning prompt about "this will convert your file to the latest SW version....." - any way to make that "ok" selection silent?
Line 20 - is the specific location of the drafting standards in our live vault view on my client machine but, I would like this to go to the particular vault view folder on the client machine running the macro (some client machines have local vault views on alternative drive letters. Want to make this agnostic, kind of like %program files%
Thank you for any insight!
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
' Save to convert to latest SW version
Dim swErrors As Long
Dim swWarnings As Long
boolstatus = Part.Save3(1, swErrors, swWarnings)
boolstatus = Part.Extension.SelectByID2("TEST_106639-01.SLDPRT", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
Part.ClearSelection2 True
' Loading new drafting standard from Vault view
boolstatus = Part.Extension.LoadDraftingStandard("C:\Vault View\VCT Live\zzz Vault Administration zzz\VCT Templates\Drafting Standards\ANSI-Part Model-Make.sldstd")
' Upgrade cosmetic threads silently wihtout needing to click yes in the warning
Dim allowUpgrade As Boolean
allowUpgrade = swApp.GetUserPreferenceToggle(swUserPreferenceToggle_e.swEnableAllowCosmeticThreadsUpgrade)
try:
On Error GoTo catch
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swEnableAllowCosmeticThreadsUpgrade, True
If False = swModel.Extension.UpgradeLegacyCThreads() Then
Debug.Print "Thread is not upgraded"
End If
Else
Err.Raise vbError, "", "Please open document"
End If
GoTo finally
catch:
swApp.SendMsgToUser2 Err.Description, swMessageBoxIcon_e.swMbStop, swMessageBoxBtn_e.swMbOk
finally:
swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swEnableAllowCosmeticThreadsUpgrade, allowUpgrade
' Final Save
boolstatus = Part.Save3(1, swErrors, swWarnings)
End Sub
Apologies for the late reply, was not able to log into the forums for some reason for several days.
Thank you to Wayne Matus suggestion on the original post I made, see Model Cleanup Macro
Cycling through drive letter options worked.
Luckily we only have a few possible vault view drive letter combinations.
Auto-reading the root folder from PDM would be a "nice to have" but the "If not" statement works great.
Macro attached for anyone looking into this, or even wanting to improve on it