Get a BOM Structure value from the file reference instead of a selection set.

Get a BOM Structure value from the file reference instead of a selection set.

shastu
Advisor Advisor
2,262 Views
6 Replies
Message 1 of 7

Get a BOM Structure value from the file reference instead of a selection set.

shastu
Advisor
Advisor

FYI I have simplified the below programs as much as possible just to make it easier for you to help me.  With the top one, I would have safe guards to make sure they only have one component selected.  So to see it work, open an assembly and then select one of the components before running it.  The second one you don't select anything.

 

Is there a way to get the BOMStructureEnum.kReferencedBOMStructure value from a file reference?  For example, if I have a component in an assembly selected, I can get what I am after like this:

 

Sub selected()
    Dim odoc As Document
    Set odoc = ThisApplication.ActiveDocument
    Dim oSS As SelectSet
    Set oSS = odoc.SelectSet
'HELP
    If oSS.Item(1).BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then
        MsgBox ("Reference")
    Else: MsgBox ("Normal")
    End If
'END HELP
End Sub

 

If you look at the line right after the 'Help, that is what I am wanting to do with file references.  So here is what I have so far but I can't get it to work.  The line right after the 'Help below throws an error:

 

Sub FileRefs()
    ' Get the active assembly.
Dim odoc As Document
Set odoc = ThisApplication.ActiveDocument
   Dim oAsmDoc As AssemblyDocument
    Set oAsmDoc = ThisApplication.ActiveDocument
    ' Get all of the referenced documents.
    Dim oRefDocs As DocumentsEnumerator
    Set oRefDocs = oAsmDoc.AllReferencedDocuments
   ' Iterate through the list of documents.
    Dim oRefDoc As Document
    For Each oRefDoc In oRefDocs
        MsgBox oRefDoc.DisplayName
        Set oPropSet = oRefDoc.PropertySets("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}")
        'Dim oProp As Property
        Set oProp = oPropSet.Item("Comments")
       'MsgBox oProp.Value
       If oProp.Value = "" Then GoTo Skip:
'HELP
    If oRefDoc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then
        MsgBox ("Reference")
    Else: MsgBox ("Normal")
    End If
'End HELP
Skip:
    Next
       
End Sub

0 Likes
Accepted solutions (1)
2,263 Views
6 Replies
Replies (6)
Message 2 of 7

MechMachineMan
Advisor
Advisor

So it works in your first example because the type of object that you select in the select set is an Occurrence.

 

If you look at the object type ComponentOccurrence in API Help/Object browser, you will see it does have the BOMStructure method available. Which makes sense, and this value returns only the BOMStructure for that occurrence (as is stored in the assembly - which can either be the value it is assigned within the document, or the OVERRIDDEN value of Reference (as you can assign through the right click menu in the model)).

 

In your second sample, the object you have assigned to the variable upon which you try to make the .BOMStructure call is a document

If you look at Document in API Help/Object Browser, you will see it does NOT have the BOMStructure method available.

 

HOWEVER, if you look at ComponentDefinition (which is a method of Document objects), you will see that DOES have the .BOMStructure method available. This method of calling the BOMstructure returns what is assigned to the document for that FILE and does NOT include the override information (which is saved in the assembly file).

 

The fix:

If oRefDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kReferenceBOMStructure

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 3 of 7

shastu
Advisor
Advisor

Justin,  Thanks for the thorough explanation.  I appreciate that.  I tried that and it didn't work.  Regardless if it is a Reference part or a Normal part it is still going to the Else: part of the code.  See video.  You should be able to open it in any Internet Browser.  I use IE. 

0 Likes
Message 4 of 7

MechMachineMan
Advisor
Advisor
Accepted solution

So to follow up with my explanation above;

 

In the start of the video, you show the right click BOM structure for the OCCURRENCE. This shows that the OCCURRENCE BOMStructure OVERRIDE is set to Reference.

 

However, if you were to open that part and go into document setttings, the BOM Structure would show Normal still - which is why it's still triggering that else line.

 

The .Componentdefinition call accesses the Document.

 

What it appears you are looking for is that of the occurrence.

 

To do this we either have to start off by looping through the occurrences and access their documents when we need to, OR use the AllLeafOccurrences/similiar method from the Assembly doc.

 

However, if you have multiple instances of parts with various overrides for each occurrence, you have to write even more code to catch that.

 

The benefit of using the AllReferencedDocuments method is that we access each document ONLY ONCE, since there are never multiple document references for the same document within the same file, but there can be multiple OCCURRENCES that reference the same document within a file.

 

Below is a very skimmed down version that doesn't include filtering to only catch each occurrence once (ideally we would have code to flag it and skip if the same document with the same Overridden BOMStructure occurs more than once).

 

Sub FileRefs()

   Dim oAsmDoc As AssemblyDocument
   Set oAsmDoc = ThisApplication.ActiveDocument
    
   Dim oAsmCompDef As AssemblyComponentDefinition
   Set oAsmCompDef = oAsmDoc.ComponentDefinition

   Dim oOcc As ComponentOccurrence
   Dim oRefDoc As Document

   For Each oRefDoc In oAsmDoc.AllReferencedDocuments
       MsgBox oRefDoc.DisplayName
       Set oPropSet = oRefDoc.PropertySets("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}")
       Set oProp = oPropSet.Item("Comments")
       
       If oProp.Value = "" Then GoTo Skip:

       For Each oOcc in oAsmCompDef.Occurrences.AllReferencedOccurrences(oRefDoc)
            If oOcc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then
                 MsgBox (oOcc.Name & ": Reference")
            Else
                 MsgBox (oOcc.Name & ": Normal")
            End If
       Next
Skip:
    Next
       
End Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 5 of 7

shastu
Advisor
Advisor

I guess I kind of forgot the entire reason why I asked the question.  Once I put your code into the rest of the program, I realized once again that I am trying to loop through all the Referenced documents which includes structure that is under a derived assembly.  With Component Occurrences, it doesn't know what to do once you get to an ipt file because there isn't such a thing as a component occurrences in an ipt file even though it is created from an iam file with a BOM to it.  Am I just out of luck?  You would think their would be a way since you can do it through design assistant.  I just need to be able to do it in VBA.

0 Likes
Message 6 of 7

MechMachineMan
Advisor
Advisor

I don't understand entirely what you are trying to accomplish, and I think that may be preventing me from giving you further advice/direction.

 

I can see that looping through referenced files can cause issues in finding occurrences if that same part occurs within multiple sub assemblies, which means that you would have to add extra checks/looping/recursion in order to account for those situations.

 

Perhaps if you can explain what the end goal of what you are trying to accomplish is, I can give you a more complete solution.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 7 of 7

shastu
Advisor
Advisor

Never mind.  I was able to figure it out.  Thanks!!!

0 Likes