AnsweredAssumed Answered

Drw Macro: Set all Cosmetic threads to "Per standard" layer

Question asked by Nick Tzallas on Jan 3, 2021
Latest reply on Jan 26, 2021 by Deepak Gupta

After going through quite a bit of work and with most of the help coming from the community, we were able to scrape together a multistage macro for cleaning up some legacy drawings.

Please refer to Drawing Migration Cleanup Macro 


One of the things noticed after running that macro is that the cosmetic threads are set to the "Tables" layer, hence making them a solid line type.


Does any one have any idea of a code snippet that is needed to:

  1. run through all sheets in active drawing
  2. find all cosmetic threads
  3. Set layer to "Per standard"


Not sure if this is possible as I don't know if the cosmetic thread is "seen" as separate to everything else i.e. not considered an "swNote" for example


You can refer to the full macro if you like in the above thread link but I have also pasted the layer section of that macro below for quick reference in case it helps


running SW2020 SP5.0


Thank you




Set swApp = CreateObject("SldWorks.Application")
Set swDoc = swApp.ActiveDoc
Set swDraw = swDoc
vSheetNames = swDraw.GetSheetNames

Dim k As Integer
Dim j As Integer
Dim s As Integer
Dim vSheets As Variant
Dim vViews As Variant

For k = 0 To swDraw.GetSheetCount - 1
swDraw.ActivateSheet vSheetNames(k)
'Change border layer
Set swSketch = swDoc.GetActiveSketch2
swDoc.ClearSelection2 (True)
vSketchSeg = swSketch.GetSketchSegments
vLayName = "Auto-Border" 'Change the layer name in quotes to your layer name here
For i = 0 To UBound(vSketchSeg)
Set swSketchSeg = vSketchSeg(i)
swSketchSeg.Layer = vLayName
Next i


'Change non-border object layer....
vSheets = swDraw.GetViews

For s = 0 To UBound(vSheets)
vViews = vSheets(s)

For v = 0 To UBound(vViews)
Set swView = vViews(v)
If swView.GetAnnotationCount > 0 Then
vAnn = swView.GetAnnotations

For j = 0 To UBound(vAnn)
Set swAnn = vAnn(j)
Select Case swAnn.GetType
Case swNote
swAnn.Layer = "Annotations" 'Change the annotations layer name in quotes to your layer name here
Case swDisplayDimension
swAnn.Layer = "Dimensions" 'Change the Dimensions layer name in quotes to your layer name here
Case swTableAnnotation
swAnn.Layer = "Tables" 'Change the Table layer name in quotes to your layer name here
Case Else
End Select
Next j
End If
Next v
Next s
Next k