stevsmith 发表于 2022-7-8 22:11:37

打印到PDF(文件名和版本

(描述被偷走了,因为它准确地描述了我要找的东西)
 
我有一个宏,我用它来生成打开图形的pdf。我的绘图
文件名只是零件号。我想添加修订
在另存为pdf之前,返回到文件名的末尾。我携带当前版本
在模型中的自定义属性中。我的工作表格式上有一条注释
参考此,在标题栏中显示版本。
 
我似乎不能用part。getcustominfo2,因为它在自定义
图形的特性区域(为空),而不是从模型中引用
 
我不知道如何访问引用模型的属性,例如
注释do($PRPSHEET:REV)。
 
有什么办法吗?
 
 
 
我的同事发现了这个链接,它提出了相同的问题,但我们对VB的知识是不存在的。
 
http://compgroups.net/comp.cad.solidworks/api-get-custom-prop-from-referenced-model/15615
 
任何帮助都将不胜感激。

stevsmith 发表于 2022-7-8 23:43:48

没关系,伙计们,我设法找到了它的代码。
 
Dim swApp         As SldWorks.SldWorks
Dim swModel         As SldWorks.ModelDoc2
Dim swDraw          As SldWorks.DrawingDoc
Dim swCustProp      As CustomPropertyManager
Dim valOut          As String
Dim valOut1         As String
Dim valOut2         As String
Dim resolvedValOutAs String
Dim resolvedValOut1 As String
Dim resolvedValOut2 As String
Dim Filepath      As String
Dim FileName      As String
Dim ConfigName      As String

Sub main()
Set swApp = Application.SldWorks
Set swDraw = swApp.ActiveDoc
' Check to see if a drawing is loaded.
If (swDraw Is Nothing) Or (swDraw.GetType <> swDocDRAWING) Then
' If no model currently loaded, then exit
Exit Sub
End If
Set swView = swDraw.GetFirstView
Set swView = swView.GetNextView
Set swModel = swView.ReferencedDocument
ConfigName = swView.ReferencedConfiguration
Set swCustProp = swModel.Extension.CustomPropertyManager(ConfigName)
swCustProp.Get2 "NewPartNo", valOut, resolvedValOut               'Change the custom property name here
swCustProp.Get2 "AssyDescription", valOut1, resolvedValOut1         'Change the custom property name here
swCustProp.Get2 "CurrentRev", valOut2, resolvedValOut2            'Change the custom property name here
Filepath = "C:\Drawings\"
FileName = Left(swDraw.GetTitle, Len(swDraw.GetTitle) - 9)
swDraw.SaveAs (Filepath + resolvedValOut + " - " + resolvedValOut1 + " - Rev" + resolvedValOut2 + ".PDF")   'Change the custom property text here
MsgBox resolvedValOut + " - " + resolvedValOut1 + " - Rev" + resolvedValOut2 + "   Saved as a PDF"
End Sub

页: [1]
查看完整版本: 打印到PDF(文件名和版本