Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Material and Appearance not updating in BOM with Model States

4 REPLIES 4
Reply
Message 1 of 5
J_Dumont
117 Views, 4 Replies

Material and Appearance not updating in BOM with Model States

Hello,

I'm writing a VB program that allows the user to change the material and appearance of parts within an assembly.

Several part files have Model States, and the change seems to work properly.

The part files that use Model States are set to Factory Scope, so the edits should apply to all members.

If I open the part file, the material and appearance match what the user selected.

However, the BOM doesn't match.

 

Below is an image of the BOM after the assembly is updated.

J_Dumont_0-1730125187928.png

 

Here is the part file which has Model States.

J_Dumont_1-1730125232542.png

If I click on Manage > Rebuild All, save and close the file, the BOM is updated properly.

The image below shows only one  file that was updated, 

J_Dumont_2-1730125308003.png

I have to repeat this process for the other files that have Model States.

 

Here is my code segment.

        Dim oAssemblyCompDef As AssemblyComponentDefinition
        oAssemblyCompDef = oDoc.ComponentDefinition
        ' Specify an occurrence to change its active model state.
        Dim oOccu As ComponentOccurrence
        oOccu = oAssemblyCompDef.Occurrences.ItemByName("Linear Bar")

        Dim partdoc As PartDocument = oOccu.Definition.FactoryDocument
        Try
            partdoc.ComponentDefinition.Material = partdoc.Materials.Item(oParameterGrillMaterial.Value) 'oParameterGrillMaterial.Value
        Catch ex As Exception
            MsgBox("Can't assign materail for the Linear Bar" & vbCrLf & ex.Message)
        End Try

        oLocalAsset = partdoc.Assets.Item(oParameterGrillColor.Value)
        partdoc.ActiveAppearance = oLocalAsset
        partdoc.Rebuild2(True)

 

Any help would be greatly appreciated.

 

 

 

 

 

Labels (3)
4 REPLIES 4
Message 2 of 5
J_Dumont
in reply to: J_Dumont

I was able to update the BOM by adding a Save after the rebuild.

 

I would love to hear if anyone else has a better solution.

 

partdoc.Rebuild2(True)
partdoc.Save()

 

Message 3 of 5
WCrihfield
in reply to: J_Dumont

Quick question...are any of those others that did not update, 'derived from' the one that did update?

Sometimes when folks derive one part into another part, then sometimes even derive that resulting part into yet another part, those 'derive' steps do not get fully recognized as needing to be updated from the main assembly's perspective.  Sometimes in those cases, you may need to include a helper code that specifically updates/rebuilds those specific referenced documents.  The 'Save' step likely works because it is more thorough, actually writing everything in memory to disk.  I am not sure why that is though.  Just one thought.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 5
J_Dumont
in reply to: WCrihfield

Hi Wesley,
Thanks for the response.
None of the files are derived. Each one is a separate independent part file with Model States.
I only showed one of the files in the example. If I opened each one, did a Rebuild All, and then saved it, the BOM would have updated properly.

Message 5 of 5
WCrihfield
in reply to: J_Dumont

OK, thanks for the additional information, and the useful information in your original post.  That is certainly an interesting situation, and unexpected behavior for Inventor.  Which version/year (and update level) of Inventor are you currently using?  This may be one that the folks at Autodesk Tech Support may be able to help with also.  If all referenced documents that have multiple ModelStates in them are set to factory scope, then it sounds like they should all be able to update properly, especially with Rebuild method.  I wander if calling the Rebuild method twice would work, if you do not want to Save at that point in the process?  Just thinking that maybe the first Rebuild changes something somewhere that the second Rebuild would catch and fix.  Just theoretical thoughts at this point though.  I'm about to leave for the day, so good luck, and hopefully others will chime in here too.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report