Turning -off visibility for sub-assembly components!

Turning -off visibility for sub-assembly components!

vinayababu.yerneni
Enthusiast Enthusiast
392 Views
3 Replies
Message 1 of 4

Turning -off visibility for sub-assembly components!

vinayababu.yerneni
Enthusiast
Enthusiast

Hi, I'm trying to turn off the visibility of the certain component occurrences in my assembly. In some cases I also had to turn off the sub-assembly components. For Example: in the below code i have a sub-components present in the M.P.R.D which are automatically turned off with the M.P.R.D. I need some the sub -components to be turned on for my requirements. I have written below code for that.

 

Sub Visibility()

Dim oAss As AssemblyDocument
Set oAss = ThisDocument

Dim oAssComp As AssemblyComponentDefinition
Set oAssComp = oAss.ComponentDefinition

Dim oOcc As ComponentOccurrences
Set oOcc = oAssComp.Occurrences

oAssComp.RepresentationsManager.DesignViewRepresentations.Item("Master").Activate

Dim oLOD As RepresentationsManager
On Error Resume Next
Set oLOD = oAssComp.RepresentationsManager.DesignViewRepresentations.Add("CNC")


Dim Occ As ComponentOccurrence

Debug.Print oOcc.Count

For Each Occ In oOcc

If Left(Occ.Definition.Document.PropertySets.Item(3).Item("Part Number").Value, 3) = "LTC" Then
Occ.Visible = False


ElseIf Left(Occ.Definition.Document.PropertySets.Item(3).Item("Part Number").Value, 3) = "TOP" Then
Occ.Visible = False

ElseIf Left(Occ.Definition.Document.PropertySets.Item(3).Item("Part Number").Value, 3) = "FLE" Then
Occ.Visible = False

ElseIf Left(Occ.Definition.Document.PropertySets.Item(3).Item("Part Number").Value, 3) = "351" Then
Occ.Visible = False

ElseIf Left(Occ.Definition.Document.PropertySets.Item(3).Item("Part Number").Value, 3) = "M.P" Then
Occ.Visible = False

ElseIf Left(Occ.Definition.Document.PropertySets.Item(3).Item("Part Number").Value, 3) = "LAP" Then
Occ.Visible = False

End If
Next

For Each Occ In oOcc.SubOccurrences

If Left(Occ.Definition.Document.PropertySets.Item(3).Item("Part Number").Value, 3) = "MPR" Then
Occ.Visible = True

End If
Next

oAss.Save
oAssComp.RepresentationsManager.DesignViewRepresentations.Item("CNC").Activate


End Sub

0 Likes
Accepted solutions (1)
393 Views
3 Replies
Replies (3)
Message 2 of 4

dalton98
Collaborator
Collaborator
Accepted solution

You need to put the SubOccurrences inside your first For loop.

Sub Visibility()

Dim oAss As AssemblyDocument
Set oAss = ThisDocument

Dim oAssComp As AssemblyComponentDefinition
Set oAssComp = oAss.ComponentDefinition

Dim oOcc As ComponentOccurrences
Set oOcc = oAssComp.Occurrences

oAssComp.RepresentationsManager.DesignViewRepresentations.Item("Master").Activate

Dim oLOD As RepresentationsManager
On Error Resume Next
Set oLOD = oAssComp.RepresentationsManager.DesignViewRepresentations.Add("CNC")


Dim Occ As ComponentOccurrence

Debug.Print oOcc.Count

For Each Occ In oOcc

If Left(Occ.Definition.Document.PropertySets.Item(3).Item("Part Number").Value, 3) = "LTC" Then
Occ.Visible = False


ElseIf Left(Occ.Definition.Document.PropertySets.Item(3).Item("Part Number").Value, 3) = "TOP" Then
Occ.Visible = False

ElseIf Left(Occ.Definition.Document.PropertySets.Item(3).Item("Part Number").Value, 3) = "FLE" Then
Occ.Visible = False

ElseIf Left(Occ.Definition.Document.PropertySets.Item(3).Item("Part Number").Value, 3) = "351" Then
Occ.Visible = False

ElseIf Left(Occ.Definition.Document.PropertySets.Item(3).Item("Part Number").Value, 3) = "M.P" Then
Occ.Visible = False

ElseIf Left(Occ.Definition.Document.PropertySets.Item(3).Item("Part Number").Value, 3) = "LAP" Then
Occ.Visible = False
End If

For Each Oc In Occ.SubOccurrences

	If Left(Oc.Definition.Document.PropertySets.Item(3).Item("Part Number").Value, 3) = "MPR" Then
	Occ.Visible = True

	End If
Next

Next



oAss.Save
oAssComp.RepresentationsManager.DesignViewRepresentations.Item("CNC").Activate
0 Likes
Message 3 of 4

vinayababu.yerneni
Enthusiast
Enthusiast

Thank you for the the solution !

0 Likes
Message 4 of 4

vinayababu.yerneni
Enthusiast
Enthusiast

Thank yo u for the solution!

0 Likes