SolidWorks图号分离宏命令运行时报错
Compile error:
Can't find project or library
在编辑宏命令框内运行宏程序,提示是“CustPropMgr =”这处出错,有哪位知道怎么解决吗?程序见下
'定义solidwork
Dim a As Integer
Dim b As String
Dim m As String
Dim e As String
Dim k As String
Dim t As String
Dim c As String
Dim j As Integer
Dim strmat As String
Dim tempvalue As String
Dim Part As Object
Dim swApp As SldWorks.SldWorks
Dim swModelDoc As SldWorks.ModelDoc2
Dim swConfig As SldWorks.Configuration
Dim CustPropMgrAsSldWorks, CustomPropertyManager
Dim swModel As SldWorks.ModelDoc2
Dim startIndex As Integer '定义截取项目号的开始位置
Dim endIndex As Integer '定义截取项目号的结束位置
Dim projID As String '定义项目号变量
Dim startstrmat As Integer '定义截取材质的开始位置
Dim endstrmat As Integer '定义截取材质的结束位置
Dim caizhiID As String '定义材质变量
Sub main()
Set swApp = Application.SldWorks
Set swModelDoc = swApp.ActiveDoc
Set swConfig = swModelDoc.ConfigurationManager.ActiveConfiguration
Set swModel = swApp.ActiveDoc
Set CustPropMgr = swModel.Extension.CustomPropertyManager(swModel.ConfigurationManager.ActiveConfiguration.Name) '配置特定延伸
'设定变量
c = swApp.ActiveDoc.GetTitle() '零件名
strmat = Chr(34) + Trim("SW-Material" + "@") + c + ".SLDPRT" + Chr(34)
a = InStr(c, " ") - 1 '重点:分隔标识符,这里是一个空格,也可换成其他符号
If a > 0 Then
k = Left(c, a)
t = Left(LTrim(e), 3)
If t = "GBT" Then
e = "GB/T" + Mid(k, 4)
Else
e = k
End If
b = Mid(c, a + 2)
t = Right(c, 7)
If t = ".SLDPRT" Or t = ".SLDASM" Or t = ".sldprt" Or t = ".sldasm" Then
j = Len(b) - 7 '消除后缀(区分大小写,即含4种)
Else
j = Len(b)
End If
m = Left(b, j)
End If
startIndex = InStr(c, ".") - 1 '重点:分隔标识符,这里用"."
endIndex = InStr(c, "-") - 1 '重点:分隔标识符,这里用"-"
If startIndex > 0 Then
If endIndex > 0 Then
If startIndex < endIndex Then
projID = Mid(c, startIndex + 2, endIndex - startIndex - 1)
End If
End If
End If
startstrmat = InStr(strmat, " ") - 1 '重点:分隔标识符,这里用"."
endstrmat = InStr(strmat, "-") - 1 '重点:分隔标识符,这里用"-"
If startstrmat > 0 Then
If endstrmat > 0 Then
If startstrmat < endstrmat Then
caizhiID = Mid(strmat, startstrmat + 2, endstrmat - startstrmat - 1)
End If
End If
End If
'删除栏
CustPropMgr.Delete ("图样代号")
CustPropMgr.Delete ("图样名称")
CustPropMgr.Delete ("Material")
CustPropMgr.Delete ("代号")
CustPropMgr.Delete ("名称")
CustPropMgr.Delete ("项目号")
CustPropMgr.Delete ("材料")
'新增
CustPropMgr.Add2 "代号", swCustomInfoText, e
CustPropMgr.Add2 "名称", swCustomInfoText, m
CustPropMgr.Add2 "数量", swCustomInfoText, ""
CustPropMgr.Add2 "单重", swCustomInfoText, ""
CustPropMgr.Add2 "总重", swCustomInfoText, ""
CustPropMgr.Add2 "备注", swCustomInfoText, ""
CustPropMgr.Add2 "代码", swCustomInfoText, ""
CustPropMgr.Add2 "材料", swCustomInfoText, strmat
CustPropMgr.Add2 "项目号", swCustomInfoText, projID
CustPropMgr.Add2 "规格", swCustomInfoText, ""
CustPropMgr.Add2 "标准厂商", swCustomInfoText, ""
CustPropMgr.Add2 "材质", swCustomInfoText, strmat
End Sub |
|