iCAx开思网
标题:
【分享】Replace BOM Table
[打印本页]
作者:
gt.adan
时间:
2019-3-10 03:12
标题:
【分享】Replace BOM Table
本帖最后由 gt.adan 于 2019-3-10 21:39 编辑
壇子內有人問起,剛好前一陣子碰到一樣的工作要求。
取經了原廠論壇前輩們寫的巨集,自個兒瞎唬弄拼湊了一個還堪用的代碼…
老手用力噴!噴完請不吝指導較為簡潔的寫述方式~~
'Replace BOM
'刪除原工程圖中的BOM,並插入新BOM到指定的座標
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeatMgr As SldWorks.FeatureManager
Dim swFeat As SldWorks.Feature
Dim swView As SldWorks.View
Dim swBomAnn As BomTableAnnotation
Dim swBomFeat As SldWorks.BomFeature
Dim anchorType As Long
Dim bomType As Long
Dim configuration As String
Dim tableTemplate As String
Dim Names As Variant
Dim visible As Variant
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swFeat = swModel.FirstFeature
While Not swFeat Is Nothing
If "BomFeat" = swFeat.GetTypeName Then
swFeat.Select2 False, -1
swModel.Extension.DeleteSelection2 swDeleteSelectionOptions_e.swDelete_Absorbed
End If
Set swFeat = swFeat.GetNextFeature
Wend
Set swSelMgr = swModel.SelectionManager
Set swFeatMgr = swModel.FeatureManager
Set swDraw = swModel
Set swSheet = swDraw.GetCurrentSheet
'Select View
swModel.ClearSelection2 True
Set swView = swDraw.GetCurrentSheet.GetViews()(0)
'Insert BOM Table
anchorType = SwConst.swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_BottomRight
bomType = SwConst.swBomType_e.swBomType_TopLevelOnly
swModel.ClearSelection2 True
configuration = ""
tableTemplate = "" '<---在雙引號內輸入新零件表模板完整路徑
Set swBomAnn = swView.InsertBomTable2(False, 0, 0, anchorType, bomType, configuration, tableTemplate)
'上一行代碼中,False後接的 0,0 即為工程圖中的 X,Y 座標值,自行依需要插入表格位置修改,唯注意比例是 1:5000
Set swBomFeat = swBomAnn.BomFeature
Names = swBomFeat.GetConfigurations(False, visible)
visible(0) = True
boolstatus = swBomFeat.SetConfigurations(True, visible, Names)
swFeatMgr.UpdateFeatureTree
End Sub
复制代码
PS. 此巨集僅為單一工程圖檔使用,有需要的朋友自便,
更可拜讀悶哥之前的教學「批量處理宏」,將其修改為更便利的工具。
作者:
xiabulai
时间:
2019-3-10 07:26
感谢分享。
作者:
mach12
时间:
2019-3-10 09:50
谢谢分享。
作者:
scattie
时间:
2019-3-11 09:29
好东西,谢谢分享!!!
作者:
qxzch
时间:
2019-3-12 00:30
丹大出手,必属精品!
作者:
q297369733
时间:
2019-3-17 09:17
vcbxdfbcvbn
作者:
wxg263
时间:
2019-3-26 09:03
这个 VB代码从哪儿学啊?看天书一样
作者:
scattie
时间:
2019-3-26 14:33
感谢楼主的分享
作者:
风中de沙
时间:
2019-12-21 20:34
感谢楼主的分享
作者:
cher_liu
时间:
2022-2-16 17:48
顶一下
作者:
jccforever
时间:
2022-11-16 23:56
谢谢分享
欢迎光临 iCAx开思网 (https://www.icax.org/)
Powered by Discuz! X3.3