So, I have this working now. open an assembly, run the rule and all work features and sketches are turned off
What I would like to do, is ammend it so that it deals with weldments also.. I've read that I need to use WeldmentComponentDefinition to access the assembly, but have had no luck this far
Can anyone kindly help? - Code below
Sub Main ()
'catch and skip errors
On Error Resume Next
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument
' switch of features and sketches in top level assy
For Each oWorkPlane In oAssyDoc.ComponentDefinition.WorkPlanes
oWorkPlane.Visible = False
Next
'set work axis visibility
For Each oWorkAxis In oAssyDoc.ComponentDefinition.WorkAxes
oWorkAxis.Visible = False
Next
'set work point visibility
For Each oWorkPoint In oAssyDoc.ComponentDefinition.WorkPoints
oWorkPoint.Visible = False
Next
'set sketch visibility
For Each oSketch In oAssyDoc.ComponentDefinition.Sketches
oSketch.Visible = False
Next
'set 3d sketch visibility
For Each threeDSketch In oAssyDoc.Sketches3D
threeDSketch.Visible = False
Next
Dim oAssyDef As AssemblyComponentDefinition
oAssyDef = oAssyDoc.ComponentDefinition
'process all subassemblies
Dim oOcc As ComponentOccurrence
For Each oOcc In oAssyDef.Occurrences
If oOcc.Definition.Type = kAssemblyComponentDefinitionObject Then
Dim oDef As AssemblyComponentDefinition
oDef = oOcc.Definition
'turn off sketches in subassemblies
Dim oSkProxy As PlanarSketchProxy
For Each oSk In oDef.Sketches
oSkProxy.Visible = False
Next
'turn off workplanes in subassemblies
Dim oWpProxy As WorkPlaneProxy
For Each oWp In oDef.WorkPlanes
oWpProxy.Visible = False
Next
'turn off workpoints in subassemblies
Dim oWtProxy As WorkPointProxy
For Each oWt In oDef.WorkPoints
oWtProxy.Visible = False
Next
'turn off workaxis in subassemblies
Dim oWaProxy As WorkAxisProxy
For Each oWa In oDef.WorkAxes
oWaProxy.Visible = False
Next
'turn off 3d sketches in subassemblies
Dim o3DProxy As Sketch3DProxy
For Each o3D In oDef.Sketches3D
o3DProxy.Visible = False
Next
End If
Next 'oOcc
Call TraverseAssembly(oAssyDoc.ComponentDefinition.Occurrences, 1)
End Sub
Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, _
Level As Integer)
' Iterate through all of the occurrence in this collection. This
' represents the occurrences at the top level of an assembly.
Dim oOcc As ComponentOccurrence
For Each oOcc In Occurrences
oDef = oOcc.Definition
'Check for virtual components
If TypeOf oDef Is VirtualComponentDefinition Then
Else
Dim oSkProxy As PlanarSketchProxy
For Each oSk In oDef.Sketches
Call oOcc.CreateGeometryProxy(oSk, oSkProxy)
oSkProxy.Visible = False
Next
For Each oWp In oDef.WorkPlanes
Call oOcc.CreateGeometryProxy(oWp, oWpProxy)
oWpProxy.Visible = False
Next
For Each oWt In oDef.WorkPoints
Call oOcc.CreateGeometryProxy(oWt, oWtProxy)
oWtProxy.Visible = False
Next
For Each oWa In oDef.WorkAxes
Call oOcc.CreateGeometryProxy(oWa, oWaProxy)
oWaProxy.Visible = False
Next
Dim o3DProxy As Sketch3DProxy
For Each o3D In oDef.Sketches3D
Call oOcc.CreateGeometryProxy(o3D, o3DProxy)
o3DProxy.Visible = False
Next
' Check to see if this occurrence represents a subassembly
' and recursively call this function to traverse through it.
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
Call TraverseAssembly(oOcc.SubOccurrences, Level + 1)
End If
End If
Next
End Sub