Quantcast
Channel: Manufacturing DevBlog
Viewing all articles
Browse latest Browse all 518

BOM Item total quantity by sub-assemby

$
0
0

By Xiaodong Liang

Question:
I would like to obtain, in a structured parts list, the total number of ITEM in the sub-assembly.
I have found an iLogic rule to create an user ipropertie in each part, with the total nomber of this part in all the assemby (included all sub-assemblies).
I would like to know if it is possible to obtain the total of this part only in the sub-assembly. Is it possible with an iLogic rule or VBA ? 

Solution:
You can recurse the referenced documents of the top assembly, filter out the sub assemblies. And iterate the occurrences of the assemblies to count each part. iLogic is based on VB.NET, so you could take advantage the Dictionary object to make the worflow more clear.

The following code is a demo to dump an assembly, get the part count of each sub assembly.

SubMain()'get top assemblyDimoTopAssAsAssemblyDocumentoTopAss=ThisApplication.ActiveDocument'store part info for each sub assembly,' including decedent Sub AssemblyDimoTotalDictAs_NewDictionary(OfString, _Dictionary(OfString, Integer))DimoEachRefDocAsDocumentForEachoEachRefDocIn_oTopAss.ReferencedDocumentsIfTypeOfoEachRefDocIs_AssemblyDocumentThen'get full path of the assemblyDimoSubAssFullPathAsStringoSubAssFullPath=_oEachRefDoc.FullFileNameIfoTotalDict.ContainsKey(oSubAssFullPath)Then' should have iterated, do nothingElse'store each unique part per its full pathDimoSubDict=_NewDictionary(OfString, _Integer)'add a dictionary for the sub assemblyoTotalDict.Add(oSubAssFullPath, _oSubDict)'iterate the parts within the sub assemblyrecurseSubAss(oEachRefDoc, _oTotalDict, _oSubDict)EndIfEndIfNext'dump the count statistic of the assembliesDimoMsgAsStringDimiAssKeyAsStringDimoEachAssDicAs_Dictionary(OfString, Integer)=NothingForEachiAssKeyIn_oTotalDict.Keys'each sub assembly, including the decendent assemblyoMsg+=vbCr+"***"+_iAssKey+"***"oEachAssDic=_oTotalDict(iAssKey)DimiPartKeyAsStringForEachiPartKeyIn_oEachAssDic.KeysDimquantityAsInteger=_oEachAssDic(iPartKey)oMsg+=vbCr+""+_iPartKey+"  [count: "+_quantity .ToString()+"]"NextNext'message the infoSystem.Windows.Forms.MessageBox.Show(oMsg)End SubSubrecurseSubAss(ByValoParentDocAsAssemblyDocument, _ByRefoTotalDictAs_Dictionary(OfString, _Dictionary(OfString, Integer)), _ByRefoSubDictAs_Dictionary(OfString, _Integer))DimoAssDefAsAssemblyComponentDefinitionoAssDef=oParentDoc.ComponentDefinitionDimoEachOccAsComponentOccurrenceForEachoEachOccInoAssDef.OccurrencesDimoEachRefDocAsDocumentoEachRefDoc=oEachOcc.Definition.DocumentIfTypeOfoEachRefDocIs_AssemblyDocumentThen'get full path of the assemblyDimoSubAssFullPathAsStringoSubAssFullPath=_oEachRefDoc.FullFileNameIfoTotalDict.ContainsKey(oSubAssFullPath)Then' should have iterated, do nothingElse'store each unique part per its full pathDimoSubSubDict=_NewDictionary(OfString, Integer)'add a dictionary for the sub assemblyoTotalDict.Add(oSubAssFullPath, _oSubSubDict)'iterate the documents within the sub assemblyrecurseSubAss(oEachRefDoc, _oTotalDict, _oSubSubDict)EndIfElse' it is part'get full path of the partDimoPartFullPathAsStringoPartFullPath=oEachRefDoc.FullFileName'add this part to the dictionaryIfoSubDict.ContainsKey(oPartFullPath)Then' if the part has existed in the dictionary'quantity  + 1oSubDict(oPartFullPath)=_oSubDict(oPartFullPath)+1Else' add this part, quantity  =1oSubDict.Add(oPartFullPath, 1)EndIfEndIfNextEnd Sub

Viewing all articles
Browse latest Browse all 518

Trending Articles