The macro does work, it took about an hour to run through a table with 500 parts. I still have an issue where the table is updated but the parts are not all updated. In some instances it happens to 1 out of 10 configurations.
If I delete and recreate the BOM it shows which values have not been changed. Prior to running the macro all the quantities are set to X with another macro. If I change "qtyrqd" to an arbitrary number on the parts that have an issue, and run the macro again it still doesn't update.
QtyRqd is configuration specific on all parts.
If you have duplicate components in the BOM then you write multiple times to that part as you traverse the bom
The BOM is displayed as parts only so duplicate components are grouped together. Its not actually updating some of the parts or configurations. It appears random but is consistent.
This doesn't look like it should take half an hour to loop over 500 lines. When you run it, is the VBA editor open? I usually have significantly slower run-times with the editor running.
I'm not very familiar with the functions that modify BOM table fields. Looking at your code, it just looks like text manipulation. I think you might have better results if you get a reference to the CustomPropertyManager of each component in the model that is driving the BOM Table and modify the custom property directly. Using that method, you will then have the added benefit of getting a return value when the assignment fails. Let me know if you have any questions about getting that object from where you are now.
Out of curiosity, if you comment out the line assigning the quantity value to the custom property (inside the BOM-traversing loop at the bottom of your macro), does the macro finish significantly faster (on the order of seconds)? After making that change, the macro won't have actually done anything when it completes but it might reveal that the assignment to the quantity field in the BOM is what takes so long (roughly 4 seconds or 30/500 minutes, perhaps?).
Thanks for the feedback. The VBA editor was closed.
My initial though was to use the custom property manager but I wasn't sure how to do that either from a drawing or where to store and recall the data and run the macro though an entire folder. Any help on this would be appreciated. Also I should mention the parts or configurations that don't update through the macro will also not update when I manually manipulate the table.
I will try to comment out the set quantity line. but I suspect you are correct. I did comment out the if statement and it took slightly longer when running on a BOM with some of the parts already updated. When running on a smaller BOM you can watch the values update and it takes about a second per line.
When I'm working in an assembly drawing and want the Components in the assembly, I'll usually use a view in the drawing and then grab the ReferencedDocument property of the view.
Being that you already have a BomTableAnnotation, there must be a quick way of getting the component reference:
From there, you can get the ModelDoc for the component and you'll have access to the CustomPropertyManager. Try putting this in your loop, replace string_pulled_from_qty_on_BOM, index, and configuration with the variable that you are copying from the BOM qty column, iterator for the loop, and the configuration to set the custom property for ("" if it is not configuration-specific).
Set swComponent = swBomTable.GetComponents2
Set swModel = swComponent.getModelDoc2(i,configuraiton)
lRet = swModel.Extension.CustomPropertyManager.set("QtyRqd",string_pulled_from_qty_on_BOM) '(fieldName,fieldValue)
if lRet = 0 then
'property "QtyRqd" was set
elseif lRet = 1
'property "QtyRqd" was not set
'property "QtyRqd" doesn't exist
*Edit: forgot to include GetComponents in the code snippet.