AnsweredAssumed Answered

Drawing Migration Cleanup Macro

Question asked by Nick Tzallas on Jul 16, 2020
Latest reply on Nov 16, 2020 by Nick Tzallas

****re-posting Drawing Migration Cleanup Macro  as a question. Mistakenly made it a discussion***

 

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

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 template switch macro, 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)


Intended order of events in macro: On Currently open drawing:

  1. Saves current file (to convert to latest SW version) - Works
  2. Deletes all drawing layers. - works
  3. Brings in specific drafting standard. Drafting standards managed by Vault. Local vault view root varies between client machines (c:\, d:\), ideally should be "drive agnostic" or %root vault view folder% - Not working
    1. This would be a "nice to have" but cycling through the drive letters similar to Model Cleanup Macro would be great as well with an "If not, else" - Not Working
  4. Applies selected drafting standard - Partially working, will work once step 3 is solved
  5. Applies specific sheet format to all sheets - Partially working, only does it on sheet 1
  6. Sets auto-zone border to correct layer, on all sheets - Works
  7. Deletes any existing revision table - Works
  8. Applies new specific revision table template - Not Working

 

I have managed to scrape together the below macro using the record function plus bits and bobs from the forum Delete Drawing Layers Macro  & Automatic Border Not Remembering Layer :& Model Cleanup Macro 

 

A lot of things are working great, however, current issues I am having:

 

Line 51

need to make that cycle through C:...or D:.... see Model Cleanup Macro. Maybe with a similar IF not,else statement?

 

Line 53-54:

Would like the macro to cycle through all sheets automatically and apply the selected sheet format.

I tried recording the "apply to all sheets" button when setting it but it seems to not return the respective code snippet.

Even better if it could incorporate a silent "No" click to the old "do you want to rename blocks" pop-up.

 

Line 55-60:

I would like to also add the If not statement for this section to check and look for the specific rev table format and then apply it to the sheet.

This would also need to check alternative drive letters similar to Line 51 issue mentioned above. Currently it deletes the existing table but then brings in the SolidWorks default table template rather than bringing in the specific one I want.  See also snippet below macro code.

 

 

 

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

' Zoom To Fit
Part.ViewZoomtofit2

' Zoom To Fit
Part.ViewZoomtofit2

' Zoom To Fit
Part.ViewZoomtofit2

' Save
Dim swErrors As Long
Dim swWarnings As Long
boolstatus = Part.Save3(1, swErrors, swWarnings)

'  Delete all existing Layers start
Dim doc As ModelDoc2
Dim lyrMgr As LayerMgr
Dim v As Variant
Dim i As Integer
Dim count As Integer
Set swApp = Application.SldWorks
Set doc = swApp.ActiveDoc
Set lyrMgr = doc.GetLayerManager
count = lyrMgr.GetCount
v = lyrMgr.GetLayerList
For i = 0 To count - 1
    lyrMgr.DeleteLayer (v(i))
Next i
'  Delete all existing layers over

boolstatus = swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swEdgesTangentEdgeDisplay, 0)
boolstatus = swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swEdgesTangentEdgeDisplay, 1)
boolstatus = swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swEdgesTangentEdgeDisplay, 0)
boolstatus = swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swEdgesTangentEdgeDisplay, 1)
boolstatus = swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swEdgesTangentEdgeDisplay, 0)
boolstatus = swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swEdgesTangentEdgeDisplay, 1)
boolstatus = swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swEdgesTangentEdgeDisplay, 0)
boolstatus = swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swEdgesTangentEdgeDisplay, 1)
boolstatus = Part.Extension.LoadDraftingStandard("C:\Vault View\VCT Live\zzz Vault Administration zzz\VCT Templates\Drafting Standards\ANSI-Part Drawing-Make.sldstd")
Part.ClearSelection2 True
boolstatus = Part.SetupSheet5("Sheet1", 12, 12, 1, 2, False, "A4-L-ANSI-mm.slddrt", 0.297, 0.21, "Final Part View", True)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("DetailItem181@Sheet1", "REVISIONTABLE", -8.37584846247418E-02, 0.043120236745548, 0, False, 0, Nothing, 0)
Part.EditDelete
Dim currentSheet As Object
Dim myRevisionTable As Object
Set currentSheet = Part.GetCurrentSheet()
Set myRevisionTable = currentSheet.InsertRevisionTable(True, 0.103008000834168, 0.04, 2, "")

' Zoom To Fit
Part.ViewZoomtofit2

' Zoom To Fit
Part.ViewZoomtofit2

' Zoom To Fit
Part.ViewZoomtofit2

'  Set AutoZone Border to "Auto-Border" Layer Start
    Set swApp = CreateObject("SldWorks.Application")
    Set swDoc = swApp.ActiveDoc
    Set swDraw = swDoc
    vSheetNames = swDraw.GetSheetNames
  
    For k = 0 To swDraw.GetSheetCount - 1
        swDraw.ActivateSheet vSheetNames(k)
        swDraw.EditTemplate
        Set swSketch = swDoc.GetActiveSketch2
        swDoc.ClearSelection2 (True)
        vSketchSeg = swSketch.GetSketchSegments
        vLayName = "Auto-Border"
        For i = 0 To UBound(vSketchSeg)
            Set swSketchSeg = vSketchSeg(i)
            swSketchSeg.Layer = vLayName
        Next i
        Set swView = swDraw.GetFirstView
        vAnn = swView.GetAnnotations
        For j = 0 To UBound(vAnn)
            Set swAnn = vAnn(j)
            swAnn.Layer = vLayNamer
        Next j
        swDraw.EditSheet
        swDoc.ForceRebuild3 True
    Next k
'  Set AutoZone Border to "Auto-Border" Layer Over

' Save
boolstatus = Part.Save3(1, swErrors, swWarnings)
End Sub

 

 

rev table specific placement macro I have found from Insert Revision Table and Set Anchor Position Macro 

Line 26 would need an IF not, else to look ad Drive letter D: as well

Not sure if all if this is actually needed? shouldn't  bringing in the specific rev table template "A4-L-Revision Table.sldrevtbt" apply its specific settings as saved when creating the template file in the first place? (anchor point location and snap, stationary corner, layer setting, revision symbol shape etc etc).

 

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swDraw As SldWorks.DrawingDoc
Dim currentsheet As SldWorks.Sheet
Dim swModel As SldWorks.ModelDoc2
Dim revTableAnno As SldWorks.RevisionTableAnnotation
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()


Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel



Set currentsheet = swDraw.GetCurrentSheet
swDraw.ActivateSheet (currentsheet.GetName)


' Insert a revision table

Set revTableAnno = currentsheet.InsertRevisionTable2(True, 0, 0, swBOMConfigurationAnchor_TopRight, "C:\Vault View\VCT Live\zzz Vault Administration zzz\VCT Templates\Revision Table Templates\A4-L-Revision Table.sldrevtbt", swRevisionTable_HexagonSymbol, True)

'boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swRevisionTableSymbolShape, 0, swRevisionTableSymbolShape_e.swRevisionTable_CircleSymbol)
'revTableAnno.AnchorType = swBOMConfigurationAnchor_BottomLeft

End Sub

Outcomes