Visibility based on bom structure

Visibility based on bom structure

gma
Advocate Advocate
365 Views
4 Replies
Message 1 of 5

Visibility based on bom structure

gma
Advocate
Advocate

 

Hi,

I made this code to make some parts visible from the bom structure, but it doesn't quite work.
I hide all parts and then run this rule but it doesn't work.
I can't figure out what's wrong



'Visible some components
Dim oOccs As ComponentOccurrences = oADef.Occurrences For Each oOcc As ComponentOccurrence In oOccs If oOcc.Name = "SewGearmotor"Then If oOcc.BOMStructure = BOMStructureEnum.kDefaultBOMStructure Then oOcc.Visible = True ElseIf oOcc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then oOcc.Visible = False End If End If Next

 

0 Likes
366 Views
4 Replies
Replies (4)
Message 2 of 5

A.Acheson
Mentor
Mentor

To clarify you only want to effect the visibility of the part named "SewGearmotor" correct?

Is this part in a sub assembly or just in the main assembly? Can you give some images or error message your getting?

I placed in the missing oADef in case it is missing your end. 

Dim oADef As ComponentDefinition = ThisDoc.Document.ComponentDefinition

'Visible some components Dim oOccs As ComponentOccurrences = oADef.Occurrences For Each oOcc As ComponentOccurrence In oOccs If oOcc.Name = "SewGearmotor"Then If oOcc.BOMStructure = BOMStructureEnum.kDefaultBOMStructure Then oOcc.Visible = True ElseIf oOcc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then oOcc.Visible = False End If End If Next

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 5

gma
Advocate
Advocate

The code runs fine enough and no errors occur.
But SewGearmotor remains hide, even if bom is set to default.

Here is the full code.



Dim
doc As AssemblyDocument = ThisDoc.FactoryDocument Dim oADoc As AssemblyDocument = ThisDoc.FactoryDocument Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition Dim oMSs As ModelStates = oADef.ModelStates oMSs.MemberEditScope = MemberEditScopeEnum.kEditActiveMember Dim oMSName As String = "Low" 'if the one we want to Delete is 'Active', activate original instead If oMSs.ActiveModelState.Name = oMSName Then 'activate original (Master/Primary) ModelState oMSs.Item(1).Activate End If 'search for & delete ModelState named "Low" For Each oMS As ModelState In oMSs If oMS.Name = oMSName Then oMS.Delete End If Next Try ThisDoc.Document.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Item("Low").Delete Catch Logger.Debug("Could not delete Low") End Try Dim WBelt As DesignViewRepresentation = ThisDoc.Document.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Item("iLogic").Copy("Low") WBelt.Activate 'Visible all ThisApplication.ActiveDocument.ComponentDefinition.RepresentationsManager.ActiveDesignViewRepresentation.HideAll Component.Visible("Bånd") = True Component.Visible("Lige bånd_Venstre vange") = True Component.Visible("Lige bånd_Højre vange") = True 'Visible some components Dim oOccs As ComponentOccurrences = oADef.Occurrences For Each oOcc As ComponentOccurrence In oOccs If oOcc.Name = "SewGearmotor" Or oOcc.Name = "Sidestyr, venstre" Or oOcc.Name = "" Or oOcc.Name = "Sidestyr, højre" Or oOcc.Name = "SewGearmotor"Then If oOcc.BOMStructure = BOMStructureEnum.kDefaultBOMStructure Then oOcc.Visible = True ElseIf oOcc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then oOcc.Visible = False End If End If Next ThisDoc.Document.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Item("Low").CopyComponentVisibilityToSuppression("Low")' As ModelState ThisDoc.Document.ComponentDefinition.RepresentationsManager.DesignViewRepresentations("iLogic").activate 'update the files InventorVb.DocumentUpdate

 

0 Likes
Message 4 of 5

_dscholtes_
Advocate
Advocate

did you manually rename your occurrence to remove the index at the end?

0 Likes
Message 5 of 5

gma
Advocate
Advocate

I do not quite understand what you mean.

but my plan is.
Delete model state Low if created.
Create a view Low if not created
Enable View Low.
Hide all files.
Turn on Part 1,2,3
Turn on Parts 4,5,6,7 if boom reference is default, otherwise they must remain off.
Create Modelstate Low from View Low
Enable View iLogic
Activate Modelstate Master

I know I've mixed up my codes a bit, but it's clipped from different codes I have...

0 Likes