已关注
关注
重播 分享 赞
Sub GetBomTb() '材料明细表Dim swModelDoc As ModelDoc2, swModelDocFullNm As String, swModelDocNm As String, PropTitle As VariantDim PropVal As String, ModelMat As String, PropValRes As String, ActivConfig As String, fsNm As StringDim ReturnVal(), posn As Long, fsNames As Variant, AllModelNmDic As Dictionary, Multi As Boolean, msgtyp As VariantIf myselcondi Thenposn = Selarray(1): SetGolDicWith ThisWorkbook.ActiveSheetIf UCase(.Cells(posn, PropTitDicA("扩展名"))) <> ".SLDASM" ThenMsgBox "未选择装配,程序结束!", vbExclamation, "不正经的机械仙人"Exit SubEnd Ifmsgtyp = MsgBox("请选择材料明细表类型:" & Chr(13) & _"点击 [是(Y)] 展开为多阶, [否(N)] 展开为单阶。", vbQuestion + vbYesNoCancel, "不正经的机械仙人")If msgtyp = vbYes ThenMulti = TrueElseIf msgtyp = vbNo ThenMulti = FalseElseExit SubEnd IffsNm = .Cells(posn, PropTitDicA("文件位置")) & "\" & .Cells(posn, PropTitDicA("SW模型文件名")) & .Cells(posn, PropTitDicA("扩展名"))End WithReturnVal = OpenDsFiles_next("model", posn)If VarType(ReturnVal(0)) <> vbEmpty ThenThisWorkbook.Sheets("SW3 材料明细表").ActivateSet swModelDoc = ReturnVal(0): swModelDocFullNm = swModelDoc.GetPathName: swModelDocNm = swModelDoc.GetTitleActivConfig = swModelDoc.ConfigurationManager.ActiveConfiguration.NameSet AllModelNmDic = CreateObject("Scripting.Dictionary")Application.StatusBar = "正在展开:" & swModelDocFullNmWith ThisWorkbook.ActiveSheet.AutoFilter.ShowAllData: .Range("A3:Z10000").ClearContents.Cells(3, PropTitDicA("文件全名")) = swModelDocFullNm.Cells(3, PropTitDicA("文件位置")) = Left(swModelDocFullNm, InStrRev(swModelDocFullNm, "\") - 1).Cells(3, PropTitDicA("SW模型文件名")) = Left(swModelDocNm, InStrRev(swModelDocNm, ".") - 1).Cells(3, PropTitDicA("扩展名")) = UCase(Mid(swModelDocNm, InStrRev(swModelDocNm, "."))).Cells(3, PropTitDicA("阶层")) = "S1".Cells(3, PropTitDicA("当前配置")) = ActivConfigswModelDoc.Extension.CustomPropertyManager(ActivConfig).Get2 "材料", PropVal, ModelMat.Cells(3, PropTitDicA("材质")) = ModelMat.Cells(3, PropTitDicA("数量")) = 1For Each PropTitle In PropTitDicB.KeysswModelDoc.Extension.CustomPropertyManager(ActivConfig).Get2 PropTitle, PropVal, PropValRes.Cells(3, PropTitDicB(PropTitle)) = PropValResPropValRes = ""NextEnd WithAllModelNmDic.Add swModelDocFullNm, 3GetBomTb_Next swModelDoc, 4, Multi, AllModelNmDic, 1 '递归搜索Set AllModelNmDic = NothingApplication.StatusBar = FalseswApp.QuitDoc swModelDocFullNmMsgBox fsNm & " 材料明细表已搜索整理完毕!", vbInformation, "不正经的机械仙人"ElseMsgBox fsNm & Chr(13) & "打开失败!", vbExclamation, "不正经的机械仙人"End IfElseMsgBox "未选择正确行,程序结束!", vbExclamation, "不正经的机械仙人"End IfEnd SubSub GetBomTb_Next(ParaModel As ModelDoc2, i As Long, Multi As Boolean, Optional AllModelNmDic As Dictionary, Optional dep As String) '递归展开材料明细表Dim Comps As Variant, Comp As Variant, ChiModel As ModelDoc2, PartModel As PartDoc, SouRow As LongDim ModelNmDic As Dictionary, ChiModelFullNm As String, ChiModelNm As String, j As LongDim PropVal As String, ModelMat As String, PropValRes As String, ActivConfig As String, PropTitle As VariantParaModel.ResolveAllLightWeightComponents False '解除轻化Comps = ParaModel.GetComponents(True)Set ModelNmDic = CreateObject("Scripting.Dictionary")With ThisWorkbook.ActiveSheetj = 1For Each Comp In CompsIf Not (Comp.IsSuppressed Or Comp.ExcludeFromBOM) Then '未压缩且未被排除Set ChiModel = Comp.GetModelDoc2: ChiModelFullNm = ChiModel.GetPathName: ChiModelNm = ChiModel.GetTitleActivConfig = ChiModel.ConfigurationManager.ActiveConfiguration.NameSelect Case MultiCase True '展开为多阶If Not ModelNmDic.Exists(ChiModelFullNm) Then '单个装配内,不重复搜索子阶Application.StatusBar = "正在展开:" & ChiModelFullNmModelNmDic.Add ChiModelFullNm, i.Cells(i, PropTitDicA("文件全名")) = ChiModelFullNm.Cells(i, PropTitDicA("文件位置")) = Left(ChiModelFullNm, InStrRev(ChiModelFullNm, "\") - 1).Cells(i, PropTitDicA("SW模型文件名")) = Left(ChiModelNm, InStrRev(ChiModelNm, ".") - 1).Cells(i, PropTitDicA("扩展名")) = UCase(Mid(ChiModelNm, InStrRev(ChiModelNm, "."))).Cells(i, PropTitDicA("阶层")) = "S" & dep & "." & j.Cells(i, PropTitDicA("当前配置")) = ActivConfig.Cells(i, PropTitDicA("数量")) = 1For Each PropTitle In PropTitDicB.KeysChiModel.Extension.CustomPropertyManager(ActivConfig).Get2 PropTitle, PropVal, PropValRes.Cells(i, PropTitDicB(PropTitle)) = PropValResPropValRes = ""Nexti = i + 1If ChiModel.GetType = swDocASSEMBLY ThenChiModel.Extension.CustomPropertyManager(ActivConfig).Get2 "材料", PropVal, ModelMat.Cells(i - 1, PropTitDicA("材质")) = ModelMatGetBomTb_Next ChiModel, i, Multi, , dep & "." & j '递归展开ElseSet PartModel = ChiModelModelMat = PartModel.GetMaterialPropertyName2(ActivConfig, "").Cells(i - 1, PropTitDicA("材质")) = ModelMatSet PartModel = NothingEnd Ifj = j + 1ElseSouRow = ModelNmDic.Item(ChiModelFullNm).Cells(SouRow, PropTitDicA("数量")) = .Cells(SouRow, PropTitDicA("数量")) + 1End IfCase False '展开为单阶If Not AllModelNmDic.Exists(ChiModelFullNm) Then '全局唯一Application.StatusBar = "正在展开:" & ChiModelFullNmAllModelNmDic.Add ChiModelFullNm, i.Cells(i, PropTitDicA("文件全名")) = ChiModelFullNm.Cells(i, PropTitDicA("文件位置")) = Left(ChiModelFullNm, InStrRev(ChiModelFullNm, "\") - 1).Cells(i, PropTitDicA("SW模型文件名")) = Left(ChiModelNm, InStrRev(ChiModelNm, ".") - 1).Cells(i, PropTitDicA("扩展名")) = UCase(Mid(ChiModelNm, InStrRev(ChiModelNm, "."))).Cells(i, PropTitDicA("阶层")) = "S1".Cells(i, PropTitDicA("当前配置")) = ActivConfig.Cells(i, PropTitDicA("数量")) = 1For Each PropTitle In PropTitDicB.KeysChiModel.Extension.CustomPropertyManager(ActivConfig).Get2 PropTitle, PropVal, PropValRes.Cells(i, PropTitDicB(PropTitle)) = PropValResPropValRes = ""NextIf ChiModel.GetType = swDocASSEMBLY ThenChiModel.Extension.CustomPropertyManager(ActivConfig).Get2 "材料", PropVal, ModelMat.Cells(i, PropTitDicA("材质")) = ModelMatElseSet PartModel = ChiModelModelMat = PartModel.GetMaterialPropertyName2(ActivConfig, "").Cells(i, PropTitDicA("材质")) = ModelMatSet PartModel = NothingEnd Ifi = i + 1ElseSouRow = AllModelNmDic.Item(ChiModelFullNm).Cells(SouRow, PropTitDicA("数量")) = .Cells(SouRow, PropTitDicA("数量")) + 1End IfIf ChiModel.GetType = swDocASSEMBLY Then GetBomTb_Next ChiModel, i, Multi, AllModelNmDic '递归展开End SelectEnd IfNextEnd WithSet ModelNmDic = NothingSet Comp = NothingSet Comps = NothingSet ChiModel = NothingSet ParaModel = NothingEnd Sub


For Each PropTitle In PropTitDicB.KeysChiModel.Extension.CustomPropertyManager(ActivConfig).Get2 PropTitle, PropVal, PropValRes.Cells(i, PropTitDicB(PropTitle)) = PropValResPropValRes = ""Next

夜雨聆风