我想创建一个以PDF格式导出图形的宏,格式为:图纸名称+标题+日期。
我创建了一个宏,当我输入title
的值时,它正是我想要的。但是在这个项目中,我希望title
等于部件名称。因此,我将此代码用于title
值:
$ PRPSHEET:“SW-File Name(文件名)”
图纸显示Title
就好了。但是宏不起作用。我的宏不会将此代码转换为部件名称。我无法弄清楚为什么。有什么提示吗?
这就是我获得标题的方式:
Dim swCustProp As CustomPropertyManager
Function FormatFileLocation() As String
Dim Title As String
Dim bool As Boolean
Dim val As String
bool = swCustProp.Get4("title", True, val, Title) 'title is the name of the
'property and has the value: $PRPSHEET:"SW-File Name(File Name)"
end function
编辑:
我尝试使用Title
和val
,但两者都给出了相同的错误结果。
答案 0 :(得分:0)
如果您使用的是SOLIDWORKS 2014或更高版本,则应使用swCustProp.Get5()。 Get4()已根据documentation已过时。
此代码对我有用:
Dim swApp As Object
Dim swCustProp As CustomPropertyManager
Dim mde As ModelDocExtension
Dim swModel As ModelDoc2
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set mde = swModel.Extension
Set swCustProp = mde.CustomPropertyManager("")
Call FormatFileLocation
End Sub
Function FormatFileLocation()
Dim Title As String
Dim bool As Boolean
Dim val As String
Dim resolved As Boolean
bool = swCustProp.Get5("title", True, val, Title, resolved) 'title is the name of the
'property and has the value: $PRPSHEET:"SW-File Name(File Name)"
End Function
以下是我的绘图自定义属性:
答案 1 :(得分:0)
而不是从自定义属性中读取。您可以从活动的图纸视图中读取它。
Dim swApp As Object
Dim swModel As ModelDoc2
Dim swDraw As DrawingDoc
Sub main()
Set swApp = Application.SldWorks
Set swDraw = swApp.ActiveDoc
Call FormatFileLocation
End Sub
Function FormatFileLocation()
Dim Title As String
Dim v As View
Set v = swDraw.ActiveDrawingView
Set swModel = v.ReferencedDocument
Title = swModel.GetTitle()
End Function