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.
Here is the part file which has Model States.
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,
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.
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()
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
(Not an Autodesk Employee)
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
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.