Edit parts material via BOM

Edit parts material via BOM

Anonymous
Not applicable
821 Views
13 Replies
Message 1 of 14

Edit parts material via BOM

Anonymous
Not applicable

Hello,

 

my name is Nicola, I am new to this forum and in need of some hints.

 

I am working on an assembly with some subassemblies. My goal is to change the material of some parts by using the runtime adjustment column found in the BOM. This works fine, but some parts seem to be write protected.

 

I found out that parts are protected in the BOM when they appear in more than one instance and in different subassemblies (SA). Just like this:

 

Main Assembly

- SA 1

  - Part 1

  - Part 2

- SA 2

  - Part 3

  - Part 1

 

Part 1 will be protected in the BOM. Opening the SA and editing its BOM is possible, but not so convenient.

The parts do not occure in any libraries, they are just simple sheet metal parts drawn by me.

 

Is there a way to set the material properties for all parts in the BOM of the main assembly?

 

Any help is very much appreciated.

 

Nicola

0 Likes
Accepted solutions (1)
822 Views
13 Replies
Replies (13)
Message 2 of 14

bradeneuropeArthur
Mentor
Mentor

You better use the PartsOnly Bom.

this will list only the parts and their material.

if you need further support please let me know.

hope this will solve your problem.

 

Regards,

Autodesk Software: Inventor Professional 2018 | Vault Professional 2018 | Autocad Mechanical 2018
Programming Skills: Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Dimension Component! | Partlist Export! | Derive I-properties! | Vault Prompts Via API! | Vault Handbook/Manual!
Drawing Toggle Sheets! | Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 14

Anonymous
Not applicable

Hello,

 

thank you for your reply. I think I am already using the parts BOM. Please take a look at the picture.

 

Regards,

 

NicolaBOM.png

0 Likes
Message 4 of 14

bradeneuropeArthur
Mentor
Mentor

You could also use the:

dim part as Inventor.partdocument = ...Bomrow.componentdefenition.document

 

part.open 

 

than changing the material......

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 14

Anonymous
Not applicable

Hm, I don't exactly know what you mean, but it looks a bit like ilogic to me. I would prefer to change the material by using ilogic anyway, but I failed to get the code to work. I tried to adapt the code below.

 

I changed it by adding an if-then statement to change material only if the "old" material number is either 1.4301 or 1.4571 to prevent the code from changing all the other, non-steel parts too.

"YOUR MATERIAL HERE" was replaced by a string parameter.

 

Didn't work, that's why I tried the BOM method.

 

' Get the active assembly document.
    Dim oAsmDoc As AssemblyDocument 
    oAsmDoc = ThisApplication.ActiveDocument

    ' Get the material to assign to all of the parts.
    Dim strMaterialName As String
    strMaterialName = "YOUR MATERIAL HERE"

    Dim oMaterial As Material
    On Error Resume Next
    ' Try to get the material of the specified name.
    oMaterial = oAsmDoc.Materials.Item(strMaterialName)
   
    On Error Goto 0

    ' Iterate through all of the documents refrenced by the assembly.
    Dim oDoc As Document
    For Each oDoc In oAsmDoc.AllReferencedDocuments
        ' Check to see if this is a part.
        If oDoc.DocumentType = kPartDocumentObject Then
            Dim oPartDoc As PartDocument
            oPartDoc = oDoc

            ' Set the material.
            oPartDoc.ComponentDefinition.Material = oMaterial
        End If
    Next

 

0 Likes
Message 6 of 14

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous ,

 

Hoping that below iLogic code will work for you.

' Get the active assembly document.
    Dim oAsmDoc As AssemblyDocument 
    oAsmDoc = ThisApplication.ActiveDocument

    ' Get the material to assign to all of the parts.
    Dim strMaterialName As String
    strMaterialName = "YOUR MATERIAL HERE"

    Dim oMaterial As Material
    On Error Resume Next
    ' Try to get the material of the specified name.
    oMaterial = oAsmDoc.Materials.Item(strMaterialName)
   
    On Error Goto 0

    ' Iterate through all of the documents refrenced by the assembly.
    Dim oDoc As Document
    For Each oDoc In oAsmDoc.AllReferencedDocuments
        ' Check to see if this is a part.
        If oDoc.DocumentType = kPartDocumentObject Then
            Dim oPartDoc As PartDocument
            oPartDoc = oDoc

            ' Set the material.
            oPartDoc.ActiveMaterial= oMaterial
        End If
    Next

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 7 of 14

Anonymous
Not applicable

Hello Chandra,

 

please apologize my late reply, I wasn't at the office for a few days..

Thank you very much for your help, but unfortunately there still seems to be an error somewhere.. I copied your code an replaced the string for the material and I got an error message stating:

Error in Rule: test in document: test.iam The COM object of type "System .__ ComObject" 
can not be converted to interface type "Inventor.Asset". This operation could not be
performed because the QueryInterface call to the COM component for the interface with the
IID "{766A9447-A604-43C8-9393-2D2709837D1E}" failed because of the following error:
Interface not supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 I translated the error description from German via google translator, so I hope it makes any sense.

 

By the way: is it possible to adapt the code to change the material only if the part already has a specific material? It should look something like this (please take a look at my remarks in green):

 

If oDoc.DocumentType = kPartDocumentObject Then
            Dim oPartDoc As PartDocument
            oPartDoc = oDoc

            ' Set the material.
if oPartDoc.ActiveMaterial = "1.4301" or oPartDoc.ActiveMaterial = "1.4571" then oPartDoc.ActiveMaterial= oMaterial
end if End If

This would be better because the code should change only steel parts which are either 1.4301 or 1.4571. No other materials should be changed.

 

Many thanks in advence!

 

Nicola

0 Likes
Message 8 of 14

Anonymous
Not applicable

I tried to find the line containing the error, it seems to be

oPartDoc.ActiveMaterial = oMaterial

If this is commented out the code runs without errors.

 

Nicola

0 Likes
Message 9 of 14

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous ,

 

Please provide sample assembly file to test and make sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 10 of 14

marcin_otręba
Advisor
Advisor

Hi,

 

I think that problem is because you set material from assembly and try to add it to sub part.

Try:

 Dim oAsmDoc As AssemblyDocument
    Set oAsmDoc = ThisApplication.ActiveDocument
    Dim strMaterialName As String
    strMaterialName = "cartboard"
    Dim oMaterial As MaterialAsset
    On Error Resume Next
    Dim oDoc As Document
    For Each oDoc In oAsmDoc.AllReferencedDocuments
        If oDoc.DocumentType = kPartDocumentObject Then
          Dim oPartDoc As PartDocument
          Set oPartDoc = oDoc
                Dim localAsset As MaterialAsset
                Dim localAsset1 As MaterialAsset
                Set localAsset = oAsmDoc.MaterialAssets.Item(strMaterialName)
                Set localAsset1 = localAsset.CopyTo(oPartDoc, True)
               oPartDoc.ActiveMaterial = oPartDoc.MaterialAssets.Item(strMaterialName)
        End If
    Next

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 11 of 14

Anonymous
Not applicable

Hello Marcin,

 

thank you very much, the code works. i just had to remove the "set"-statements.

 

It would be very nice if you could change the code a little bit: The material should only be changed if it is either material 1.4301 or material 1.4571. I do not know how to set up the correct syntax for the if...end if loop.

 

It should look something like this:

 

if oPartDoc.ActiveMaterial = "1.4301" or oPartDoc.ActiveMaterial = "1.4571" then
oPartDoc.ActiveMaterial = oPartDoc.MaterialAssets.Item(strMaterialName)
end if

Many thanks in advance

 

Nicola

0 Likes
Message 12 of 14

Anonymous
Not applicable

Hello Chandra,

thank you very much for your reply. Marcin just posted a working code, it seems that his thoughts regarding the access from .iam to .ipt were right.

 

I will upload my test assembly anyway, maybe it is still needed.

 

Nicola

0 Likes
Message 13 of 14

marcin_otręba
Advisor
Advisor
Accepted solution

 

 Dim oAsmDoc As AssemblyDocument
    Set oAsmDoc = ThisApplication.ActiveDocument
    Dim strMaterialName As String
    strMaterialName = "cartboard"
    Dim oMaterial As MaterialAsset
    On Error Resume Next
    Dim oDoc As Document
    For Each oDoc In oAsmDoc.AllReferencedDocuments
        If oDoc.DocumentType = kPartDocumentObject Then
          Dim oPartDoc As PartDocument
          Set oPartDoc = oDoc
          if oPartDoc.ActiveMaterial.name = "1.4301" or oPartDoc.ActiveMaterial.name = "1.4571" then
                Dim localAsset As MaterialAsset
                Dim localAsset1 As MaterialAsset
                Set localAsset = oAsmDoc.MaterialAssets.Item(strMaterialName)
                Set localAsset1 = localAsset.CopyTo(oPartDoc, True)
               oPartDoc.ActiveMaterial = oPartDoc.MaterialAssets.Item(strMaterialName)
          end if
        End If
    Next

 

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 14 of 14

Anonymous
Not applicable

Hello Marcin,

 

thank you very much for your help. Everything is working as expected now!

 

Best regards

 

Nicola

0 Likes