打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
API 批量修改solidwork属性

'定义solidwork
Dim swApp As Object
Dim Part As Object
Dim SelMgr As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
 

Dim Feature As Object
'定义excel
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
 
Dim a As String
Dim b As String
Dim m As String
Dim e As String
Dim c As String
Dim j As Integer
Dim t As Integer
Dim f As String
Dim g As String
Dim h As String
Dim i As Integer
Dim k As Integer
Dim p As Integer
 
 
 
Sub main()
 
On Error GoTo aa
 

'link solidworks
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager
swApp.ActiveDoc.ActiveView.FrameState = 1
 
'设定零件地址
f = "D:\"
 

'link excel
Set oExcel = Excel.Application
oExcel.Visible = False
Set oWB = oExcel.Workbooks.Open("f:\***.xls")   'excel表格位置
Set oWS = oWB.Worksheets(1)
 

'设置在excel中的查找代码,查找各个属性
j = 2
 
Do Until Sheets(1).Cells(j, 2) = ""
 
h = Sheets(1).Cells(j, 2)
 
i = 1
Do Until Mid(h, i, 1) = "."
i = i + 1
Loop
i = i + 1
 
b = Mid(h, i, 6)
 
Select Case b
Case Is = "SLDPRT"
k = 1
Case Is = "SLDASM"
k = 2
End Select
 

'生成零件具体位置
g = f & h ' & ".SLDPRT"
 

Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager
swApp.ActiveDoc.ActiveView.FrameState = 1
'打开零件
'Part.OpenCompFile
Set Part = swApp.OpenDoc6(g, k, 0, "", longstatus, longwarnings)
 
'记录零件名称
h = Sheets(1).Cells(j, 2)
 

'经excel赋值
a = Sheets(1).Cells(j, 3) 'Description
'm = Sheets(1).Cells(j, 4)
'e = Sheets(1).Cells(j, 3)
 
'编辑零件
 
'清空solidwork旧的属性
 
blnretval = Part.DeleteCustomInfo2("", "物料编码")
'blnretval = Part.DeleteCustomInfo2("", "坯料尺寸")
 

'加入新的solidwork属性
 
blnretval = Part.AddCustomInfo3("", "Material", swCustomInfoText, a)
'blnretval = Part.AddCustomInfo3("", "坯料尺寸", swCustomInfoText, m)
 

'关闭编辑完的零件
Set Part = swApp.ActivateDoc2(g, False, longstatus)
Part.Save2 True
Part.ClearSelection2 True
Set Part = Nothing
swApp.CloseDoc g
 
'显示当前文件
Set Part = swApp.ActivateDoc2("****.SLDPRT", False, longstatus)
 

aa:
j = j + 1
 
Loop
 

'关闭excel
oExcel.DisplayAlerts = False
oWB.Close
oExcel.Quit
Set oWS = Nothing
Set oWB = Nothing
Set oExcel = Nothing
 

strErrMsg = "SetCustomProps Sub Routine" & strErrMsg
End Sub
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
solidworks打印教程之拼图打印宏方法(把多页工程图批量输出1:1TIF档案)
读取Excel内容到MSHFlexgrid
Excel VBA代码保护方案讨论及总结
excel 导入导出 vb.net版,网上很难找的哦
在ASP .NET中读写Excel文件
DataSet资料转到Exec的做法
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服