LevelOfDetailRepresentation

LevelOfDetailRepresentation

GeorgK
Advisor Advisor
1,912 Views
17 Replies
Message 1 of 18

LevelOfDetailRepresentation

GeorgK
Advisor
Advisor

Hello together,

 

I am looking for a possibility to list all parts, assemblies and subassemblies which are suppressed by a LevelOfDetailRepresentation.

 

 

This works for an assembly without subassemblies:

 

Dim asm As AssemblyDocument
        asm = m_inventorApplication.ActiveDocument

        Dim acd As AssemblyComponentDefinition
        acd = asm.ComponentDefinition

        Dim rm As RepresentationsManager
        rm = acd.RepresentationsManager

        Dim nvm As NameValueMap
        nvm = m_inventorApplication.TransientObjects.CreateNameValueMap()

        Dim doc As AssemblyDocument
        Dim occ As ComponentOccurrence

        ListBox1.Items.Clear()
        ListBox2.Items.Clear()

        Dim lod As LevelOfDetailRepresentation
        For Each lod In rm.LevelOfDetailRepresentations
            ListBox1.Items.Add(lod.Name)
            ListBox2.Items.Add(lod.Name)
            Call nvm.Add("LevelOfDetailRepresentation", lod.Name)
            doc = m_inventorApplication.Documents.OpenWithOptions(asm.FullFileName, nvm, False)
            Call nvm.Clear()

            For Each occ In doc.ComponentDefinition.Occurrences
                If occ.Suppressed = True Then
                    ListBox2.Items.Add("    " + occ.Name + " Suppressed = " + Str(occ.Suppressed))
                End If

                ListBox1.Items.Add("    " + occ.Name + " Suppressed = " + Str(occ.Suppressed))
            Next

            ' Don't forget to close the document not used anymore
            If Not lod Is rm.ActiveLevelOfDetailRepresentation Then
                Call doc.Close(True)
            End If
        Next

 

Thank you very much

 

Georg

 

 

0 Likes
Accepted solutions (1)
1,913 Views
17 Replies
Replies (17)
Message 2 of 18

MechMachineMan
Advisor
Advisor
This is only going to work for the top level of the active document as you dont have anywhere in your program that tells it to go any deeper.

--------------------------------------
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 3 of 18

GeorgK
Advisor
Advisor

Hello Justin,

 

please could you help me? How could I get the suppressed parts and assemblies from subassemblies?

 

Thank you Georg

0 Likes
Message 4 of 18

RodrigoEiras
Advocate
Advocate

 

In the Programming/API help there is an example about how to traverse an assembly. I think that's what you need to add to your code.

 

I paste it below:

 

Traverse an Assembly API Sample

Public Sub AssemblyCount()
    ' Set reference to active document.
    ' This assumes the active document is an assembly
    Dim oDoc As Inventor.AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    ' Get assembly component definition
    Dim oCompDef As Inventor.ComponentDefinition
    Set oCompDef = oDoc.ComponentDefinition

    Dim sMsg As String
    Dim iLeafNodes As Long
    Dim iSubAssemblies As Long
    
    ' Get all occurrences from component definition for Assembly document
    Dim oCompOcc As ComponentOccurrence
    For Each oCompOcc In oCompDef.Occurrences
        ' Check if it's child occurrence (leaf node)
        If oCompOcc.SubOccurrences.Count = 0 Then
            Debug.Print oCompOcc.Name
            iLeafNodes = iLeafNodes + 1
        Else
            Debug.Print oCompOcc.Name
            iSubAssemblies = iSubAssemblies + 1
            Call processAllSubOcc(oCompOcc, _
                                sMsg, _
                                iLeafNodes, _
                                iSubAssemblies) ' subassembly
        End If
    Next
    
    Debug.Print "No of leaf nodes    : " + CStr(iLeafNodes)
    Debug.Print "No of sub assemblies: " + CStr(iSubAssemblies)
End Sub

' This function is called for processing sub assembly.  It is called recursively
' to iterate through the entire assembly tree.
Private Sub processAllSubOcc(ByVal oCompOcc As ComponentOccurrence, _
                             ByRef sMsg As String, _
                             ByRef iLeafNodes As Long, _
                             ByRef iSubAssemblies As Long)
    
    Dim oSubCompOcc As ComponentOccurrence
    For Each oSubCompOcc In oCompOcc.SubOccurrences
        ' Check if it's child occurrence (leaf node)
        If oSubCompOcc.SubOccurrences.Count = 0 Then
            Debug.Print oSubCompOcc.Name
            iLeafNodes = iLeafNodes + 1
        Else
            sMsg = sMsg + oSubCompOcc.Name + vbCr
            iSubAssemblies = iSubAssemblies + 1

            Call processAllSubOcc(oSubCompOcc, _
                                  sMsg, _
                                  iLeafNodes, _
                                  iSubAssemblies)
        End If
    Next
End Sub

 

I hope that's what you need

 

0 Likes
Message 5 of 18

GeorgK
Advisor
Advisor

Hello Rodrigo,

 

thank you very much for the code. The problem is to get the dependent representations from the main assembly and loop than througt the assembly.

 

 

Main.iam -> LOD1 ; LOD2 ; LOD3

 

SUB1.iam -> LOD1 ; LOD2 ; LOD3

 

SUB2.iam -> LOD1 ; LOD2 ; LOD3

 

 

Georg

0 Likes
Message 6 of 18

RodrigoEiras
Advocate
Advocate

 

Hi Georg,

 

I see that the difficulty lies in trying to get the LODs from the subassemblies, as you cannot do it from the ComponentOcurrence, but probably you would have to access each subassembly individually to be able to use the RepresentationsManager object and get the LODs.

Unfortunately I am not so experienced in this kind of programming with assemblies, so I am afraid I cannot help you further with this issue.

 

Good luck!

 

 

 

0 Likes
Message 7 of 18

MechMachineMan
Advisor
Advisor

I could see this getting pretty interesting depending on how things are suppressed as if you suppress components in a lower level, it will make it a temporary level of detail, thus you will have to search through those to access parts.

 

You might have an easier time just listing all suppressed parts for the current state of the top-level assembly document, by ignoring the level of detail aspect completely and just testing suppression status.

 

Otherwise, I would say you will definitiely need to look into the RepresentationsManager.LevelofDetailRepresentations methods.

 

Looking at all of the methods under Level Of Detail representations, the most use it will be for you is to establish what LOD you are looking at, and chaning/traversing them. They dont contain any information about the suppression status of components, only the substitute parts that may be used instead.


--------------------------------------
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 8 of 18

Vladimir.Ananyev
Alumni
Alumni
Accepted solution

I've slightly changed the code of thr "Traverse an Assembly API Sample".

Now it prints names of suppressed components ignoring substitutes.

You may extend this code to loop through every LOD in your top assembly document.

Public Sub AssemblyCount()
    ' Set reference to active document.
    ' This assumes the active document is an assembly
    Dim oDoc As Inventor.AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    ' Get assembly component definition
    Dim oCompDef As Inventor.ComponentDefinition
    Set oCompDef = oDoc.ComponentDefinition

    Dim sMsg As String
    Dim iLeafNodes As Long
    Dim iSubAssemblies As Long
    
    ' Get all occurrences from component definition for Assembly document
    Dim oCompOcc As ComponentOccurrence
    
    Debug.Print "--- Assembly: " & oDoc.DisplayName
    For Each oCompOcc In oCompDef.Occurrences
        If Not oCompOcc.IsSubstituteOccurrence Then
            If oCompOcc.Suppressed Then
                Debug.Print "suppressed:  " & oCompOcc.Name
                iLeafNodes = iLeafNodes + 1
            Else
                ' Check if it's child occurrence (leaf node)
                If oCompOcc.SubOccurrences.Count = 0 Then
                    'empty SubAssembly - do nothing
                Else
                    iSubAssemblies = iSubAssemblies + 1
                    Call processAllSubOcc(oCompOcc, _
                                        sMsg, _
                                        iLeafNodes, _
                                        iSubAssemblies) ' subassembly
                End If
            End If
        End If
    Next
    
    Debug.Print
    Debug.Print "No of suppressed nodes : " + CStr(iLeafNodes)
    Debug.Print "No of sub assemblies   : " + CStr(iSubAssemblies)
End Sub

' This function is called for processing sub assembly.  It is called recursively
' to iterate through the entire assembly tree.
Private Sub processAllSubOcc(ByVal oCompOcc As ComponentOccurrence, _
                             ByRef sMsg As String, _
                             ByRef iLeafNodes As Long, _
                             ByRef iSubAssemblies As Long)
    
    Dim oSubCompOcc As ComponentOccurrence
    Debug.Print "--- SubAssembly: " & oCompOcc.Name
    
    For Each oSubCompOcc In oCompOcc.SubOccurrences
        If Not oSubCompOcc.IsSubstituteOccurrence Then
            If oSubCompOcc.Suppressed Then
                Debug.Print "suppressed:  " & oSubCompOcc.Name
                iLeafNodes = iLeafNodes + 1
            Else
                ' Check if it's child occurrence (leaf node)
                If oSubCompOcc.SubOccurrences.Count = 0 Then
                    'empty SubAssembly - do nothing
                Else
                    sMsg = sMsg + oSubCompOcc.Name + vbCr
                    iSubAssemblies = iSubAssemblies + 1
        
                    Call processAllSubOcc(oSubCompOcc, _
                                          sMsg, _
                                          iLeafNodes, _
                                          iSubAssemblies)
                End If
            End If
        End If
    Next
End Sub

 Hope this helps.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 9 of 18

GeorgK
Advisor
Advisor

Hello Vladimir,

 

thank you very much for your help.

 

Georg

0 Likes
Message 10 of 18

arge
Participant
Participant

hi   

Can you help me  for  total Item QTY

Adsız.jpg

0 Likes
Message 11 of 18

Vladimir.Ananyev
Alumni
Alumni

Try this sample please:

Sub BOM_Qty_Test()
    Dim oAsmDoc As AssemblyDocument
    Set oAsmDoc = ThisApplication.ActiveDocument
    
    Dim oBOM As BOM
    Set oBOM = oAsmDoc.ComponentDefinition.BOM
    
    oBOM.StructuredViewEnabled = True
    oBOM.StructuredViewFirstLevelOnly = True
    
    Dim oBOMView As BOMView
    Set oBOMView = oBOM.BOMViews.Item("Structured")  'Structured
    
    Dim oBOMRow As BOMRow
    Dim TotalQty As Double
    TotalQty = 0
    
    For Each oBOMRow In oBOMView.BOMRows
        TotalQty = TotalQty + oBOMRow.TotalQuantity
        Debug.Print "ItemNumber = " & oBOMRow.ItemNumber & "    Qty = " & oBOMRow.TotalQuantity
    Next
    Debug.Print "Total Qty = " & TotalQty
    
    Beep
End Sub

BOMRow.TotalQuantityOverridden Boolean property could help you to detect if the TotalQuantity property has been overridden. 

cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 12 of 18

arge
Participant
Participant
hi Vladimir
Thanks for answer but ı need total ItemQTY (sum ItemQTY) in BOM
not Total QTY
0 Likes
Message 13 of 18

Vladimir.Ananyev
Alumni
Alumni

Then use BOMRow.ItemQuantity property.
You may look at the BOMQuery vba sample from the Inventor API Help.

cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 14 of 18

arge
Participant
Participant
thanks
its ok
0 Likes
Message 15 of 18

arge
Participant
Participant

thanks  for your help..

 

Can ı another quession?

 

how do   "user parameter"  = Base Quantity  in part

 

0 Likes
Message 16 of 18

Vladimir.Ananyev
Alumni
Alumni

Look at the following post:  Use iLogic to Change Base Quantity

http://forums.autodesk.com/t5/inventor-customization/use-ilogic-to-change-base-quantity/m-p/3222896/...

See Inventor API Help for the BOMQuantity.GetBaseQuantity method.  It allows to retrieve the base quantity for the part.  If the first argument is BOMQuantityTypeEnum.kParameterBOMQuantity then the second argument returns the parameter object.  You can get parameter name to use it in your rule.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 17 of 18

arge
Participant
Participant
 
 
 

I want to use this way

 

iProperties.Value("Custom", "HAMMADDE MALİYET") = (iProperties.Value("Custom", "HAMMADDE KODU"))*(BaseQuantity)*1.05

0 Likes
Message 18 of 18

arge
Participant
Participant

Can you help me this  topic?

 

" I want to use this way

 

iProperties.Value("Custom", "HAMMADDE MALİYET") = (iProperties.Value("Custom", "HAMMADDE KODU"))*(BaseQuantity)*1.05    "

0 Likes