iLogic to toggle sub-assembly BOM structure

iLogic to toggle sub-assembly BOM structure

b.mccarthy
Collaborator Collaborator
365 Views
4 Replies
Message 1 of 5

iLogic to toggle sub-assembly BOM structure

b.mccarthy
Collaborator
Collaborator

I have this assembly, containing a number of sub-assemblies and parts. I am looking for a routine that will temporarily toggle the sub-assembly's BOM structure from Normal to Phantom and back again, ignoring the parts.

 

I found this 2012 post which can perform the toggle, but could not get it to work the way I need. I am not a proficient coder...

 

Thank you for any help...

 

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

JelteDeJong
Mentor
Mentor

You can try something like this:

Dim doc As AssemblyDocument = ThisDoc.Document
Dim names As New List(Of String)
names.Add("Phantom")
names.Add("Inseparable")
names.Add("Normal")

Dim BOMStructureName = InputListBox("Select BOM structure", names, "Normal", "Select", "BOM structures")

For Each refdoc As Document In doc.AllReferencedDocuments
    If (refdoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject) Then

        Select Case BOMStructureName
            Case "Phantom"
                refdoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kPhantomBOMStructure
            Case "Inseparable"
                refdoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kInseparableBOMStructure
            Case "Normal"
                refdoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kNormalBOMStructure
        End Select
    End If
Next

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 5

b.mccarthy
Collaborator
Collaborator

Hello.

 

Thank you for the code, but I am getting these errors.

0 Likes
Message 4 of 5

JelteDeJong
Mentor
Mentor

These errors don't tell me much. Maybe you can try the following (updated) rule. Maybe it becomes clear if you know which document is failing. It will show a message box for each document that can't be updated. (try it on an assembly that is not too big or you might get stuck with a lot of message boxes 😉

Dim doc As AssemblyDocument = ThisDoc.Document
Dim names(3) As String
names(0) = "Phantom"
names(1) = "Inseparable"
names(2) = "Normal"

Dim BOMStructureName = names(1)
For Each refdoc As Document In doc.AllReferencedDocuments
    If (refdoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject) Then
        Try
            Select Case BOMStructureName
                Case "Phantom"
                    refdoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kPhantomBOMStructure
                Case "Inseparable"
                    refdoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kInseparableBOMStructure
                Case "Normal"
                    refdoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kNormalBOMStructure
            End Select
        Catch ex As Exception
            MsgBox("Could not set BOMStructure for document: " & refdoc.DisplayName)
        End Try
    End If
Next

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 5 of 5

b.mccarthy
Collaborator
Collaborator

The form no longer displays, and I am getting these errors:

 

2022-11-18 560.jpg 2022-11-18 561.jpg

 

The 1st appears for every sub-assembly, and the 2nd for each bolted connection.

 

Thanks.

 

0 Likes