Hi @fixmepm, here are 2 versions that will handle CC parts also.
Hope this helps, Curtis
This version just turns everything off:
Sub Main
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'Define the open document (top level assembly)
Dim openDoc As Document = ThisDoc.Document
'define view rep
Dim oViewRep As DesignViewRepresentation
Dim sVRep As String = "Default"
'create or activate view rep in the top level assembly
Try
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(sVRep).Activate
Catch
'create new View Rep
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add(sVRep)
End Try
'turn off features in top level
Call TurnOff(openDoc)
'create or activate view rep in subassemblies
Dim docFile As Document
For Each docFile In openDoc.AllReferencedDocuments
Dim subDoc As AssemblyComponentDefinition
If docFile.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
subDoc = docFile.ComponentDefinition
Try
subDoc.RepresentationsManager.DesignViewRepresentations.Item(sVRep).Activate
Catch
'create new View Rep
subDoc.RepresentationsManager.DesignViewRepresentations.Add(sVRep)
End Try
End If
Next
'look at only the subassemblies
Dim subDocFile As Document
For Each oCompOcc As ComponentOccurrence In oAsmCompDef.Occurrences
If oCompOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
oCompOcc.SetDesignViewRepresentation(sVRep, , True) 'True sets the view rep to be associative
Else
If oCompOcc.Definition.IsContentMember = True Then oCompOcc.Visible = False
End If
Next
'Look at all of the files referenced in the open document
For Each docFile In openDoc.AllReferencedDocuments
Call TurnOff(docFile)
Next
iLogicVb.UpdateWhenDone = True
End Sub
Sub TurnOff(oDoc As Document)
Dim oDef As ComponentDefinition = oDoc.ComponentDefinition
For Each oWorkPlane In oDef.WorkPlanes
oWorkPlane.Visible = False
Next
For Each oWorkAxis In oDef.WorkAxes
oWorkAxis.Visible = False
Next
For Each oWorkPoint In oDef.WorkPoints
oWorkPoint.Visible = False
Next
For Each oSketch In oDef.Sketches
oSketch.Visible = False
Next
End Sub
This version turns things on or off:
Sub main
'get user input
oInput = InputRadioBox("Select work feature visibility:", _
"Turn ON work feats, sketches, CC parts", _
"Turn OFF work feats, sketches, CC parts", "False", "iLogic")
' set a reference to the assembly component definintion.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'Define the open document (top level assembly)
Dim openDoc As Document = ThisDoc.Document
'define view rep
Dim oViewRep As DesignViewRepresentation
Dim sVRep As String = "Default"
'create or activate view rep in the top level assembly
Try
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(sVRep).Activate
Catch
'create new View Rep
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add(sVRep)
End Try
'create or activate view rep in subassemblies
Dim docFile As Document
For Each docFile In openDoc.AllReferencedDocuments
Dim subDoc As AssemblyComponentDefinition
If docFile.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
subDoc = docFile.ComponentDefinition
Try
subDoc.RepresentationsManager.DesignViewRepresentations.Item(sVRep).Activate
Catch
'create new View Rep
subDoc.RepresentationsManager.DesignViewRepresentations.Add(sVRep)
End Try
End If
Next
'set visibility work features in the open document (top level assembly)
Call SetVis(openDoc, oInput)
Dim subDocFile As Document
For Each oCompOcc In oAsmCompDef.Occurrences
If oCompOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
oCompOcc.SetDesignViewRepresentation(sVRep, , True) 'True sets the view rep to be associative
Else
'handle Content Center Parts
If oCompOcc.Definition.IsContentMember = True Then oCompOcc.Visible = oInput
End If
Next
'Look at all of the files referenced in the open document
For Each docFile In openDoc.AllReferencedDocuments
'set visibility or work features
Call SetVis(docFile, oInput)
Next
iLogicVb.UpdateWhenDone = True
End Sub
Sub SetVis(oDoc As Document, oInput As Boolean)
Dim oDef As ComponentDefinition = oDoc.ComponentDefinition
For Each oWorkPlane In oDef.WorkPlanes
oWorkPlane.Visible = oInput
Next
For Each oWorkAxis In oDef.WorkAxes
oWorkAxis.Visible = oInput
Next
For Each oWorkPoint In oDef.WorkPoints
oWorkPoint.Visible = oInput
Next
For Each oSketch In oDef.Sketches
oSketch.Visible = oInput
Next
End Sub
