|
- Public swApp As SldWorks.SldWorks
- Public swModel As SldWorks.ModelDoc2
- Public Filepath, NewFilepath As String
- Public A1, A2, A3, oldName As String
-
-
- Sub main()
- Set swApp = Application.SldWorks
- Set swModel = swApp.ActiveDoc
- Filepath = swModel.GetPathName()
- Set swDraw = swModel
- Get_P
- oldName = Left(Filepath, Len(Filepath) - 7) + "-" + "*" + ".pdf"
- If Dir(oldName) <> "" Then Kill oldName '删除原文件
-
- NewFilepath = Left(Filepath, Len(Filepath) - 7) + "-" + A1 + "-" + A2 + ".pdf"
-
- swDraw.SaveAs3 NewFilepath, 0, 0
- End Sub
- Public Function Get_P() '获取零件属性
- Dim PathName As String
- Dim swNameA As String
- PathName = Left(Filepath, Len(Filepath) - 6) '文件路径去后缀
- PathName = PathName + "sldprt"
- swNameA = Dir(PathName, vbDirectory)
- If Not swNameA = Empty Then
- Set swModel = swApp.OpenDoc6(PathName, 1, 1, "", 0, 0) '静默打开文件
- GoTo ss
- End If
- PName = Left(Filepath, Len(Filepath) - 6) '文件路径去后缀
- PName = PathName + "SLDASM"
- swNameA = Dir(PathName, vbDirectory)
- If Not swNameA = Empty Then
- Set swModel = swApp.OpenDoc6(PathName, 2, 1, "", 0, 0) '静默打开文件
- Else
- Exit Function
- End If
- ss:
- A1 = Get_Property_value(swModel, "Material")
- A2 = Get_Property_value(swModel, "Description")
-
- End Function
- Public Function Get_Property_value(swDoc As ModelDoc2, Property_Name As String) As String
- Dim swModelDocExt As ModelDocExtension
- Dim swCustProp As CustomPropertyManager
- Dim val As String '属性值
- Dim valout As String '属性评估值
- Dim bool As Boolean
- Set swModelDocExt = swDoc.Extension
- Set swCustProp = swModelDocExt.CustomPropertyManager("")
- bool = swCustProp.Get4(Property_Name, False, val, valout)
-
- If InStr(1, val, Chr(168), vbTextCompare) = 0 Then '如果属性值中含有引号,则取属性评估值
- Get_Property_value = valout
- Else
- Get_Property_value = val
- End If
-
- End Function
复制代码 |
|