A lot of the VBA Macro tools I write are the bring our legacy drawings up to our current standards. One of the anomalies that we run into is tables that are gray instead of black. The solution to this condition is to manually select them, then put them on the "0" (zero) layer. I'm not sure what's going on here, but that's the solution that works.
I have written a macro that scours a drawing for drawing entities that don't have a layer (ie. layer = ""), and moves them to the zero layer. This matches the workflow that works for us, but I can't find a method for setting the layer for tables using VBA. The SW API help shows some iTable members that do this, but that's only for DraftSight.
How does one move a table to a layer using VBA?
Thank You,
-Loeb
Table Layers?
Table Layers?
You can get the annotation from the table, and change layer for that.
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelectionMgr As SldWorks.SelectionMgr
Dim swTable As SldWorks.TableAnnotation
Dim swAnn As SldWorks.Annotation
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swTable = swModel.SelectionManager.GetSelectedObject6(1, -1)
Set swAnn = swTable.GetAnnotation
swAnn.Layer = "0" 'Layer Name
End Sub
Go to full postSub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelectionMgr As SldWorks.SelectionMgr
Dim swTable As SldWorks.TableAnnotation
Dim swAnn As SldWorks.Annotation
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swTable = swModel.SelectionManager.GetSelectedObject6(1, -1)
Set swAnn = swTable.GetAnnotation
swAnn.Layer = "0" 'Layer Name
End Sub
Re: Table Layers?
You can get the annotation from the table, and change layer for that.
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelectionMgr As SldWorks.SelectionMgr
Dim swTable As SldWorks.TableAnnotation
Dim swAnn As SldWorks.Annotation
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swTable = swModel.SelectionManager.GetSelectedObject6(1, -1)
Set swAnn = swTable.GetAnnotation
swAnn.Layer = "0" 'Layer Name
End Sub
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelectionMgr As SldWorks.SelectionMgr
Dim swTable As SldWorks.TableAnnotation
Dim swAnn As SldWorks.Annotation
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swTable = swModel.SelectionManager.GetSelectedObject6(1, -1)
Set swAnn = swTable.GetAnnotation
swAnn.Layer = "0" 'Layer Name
End Sub
Deepak Gupta
SOLIDWORKS Consultant/Blogger
SOLIDWORKS Consultant/Blogger