vba - VBA SOLIDWORKS 从文件中添加设计表
问题描述
我有一个“打包”的代码,并将绘图和设计表放到一个新位置,并且所有三个文件的名称完全相同。现在我有一个问题是要从设计表中更新该打包零件,因为我没有将设计表链接到该零件,因为如果我为“打包”而拥有的代码不会重命名文件把它连接起来。
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swPackAndGo As SldWorks.PackAndGo
Dim OpenFilePath As String
Dim OpenFileName As String
Dim SavePath As String
Dim SaveName As String
Dim myFileName As String
Dim myExtension As String
Dim pgFileNames As Variant
Dim pgFileStatus As Variant
Dim status As Boolean
Dim statuses As Variant
Dim i As Long
Dim partDocExt As SldWorks.ModelDocExtension
Sub PackAndGo()
Call Calculate_TFVPM_FormatSketchFileName
OpenFilePath = "E:\FORMAT\FormatSketch.SLDPRT"
SavePath = "E:\FORMAT\Temp\"
SaveName = NewSaveName
Set swApp = GetObject(, "SldWorks.Application")
Set swModel = swApp.OpenDoc(OpenFilePath, swDocPART)
'Set swModel = swApp.ActiveDoc
OpenFilePath = swModel.GetPathName
OpenFileName = Mid(OpenFilePath, InStrRev(OpenFilePath, "\") + 1, InStrRev(OpenFilePath, ".") - InStrRev(OpenFilePath, "\") - 1)
Set swModelDocExt = swModel.Extension
'Update part from design table
'Get Pack and Go object
Set swPackAndGo = swModelDocExt.GetPackAndGo
'Include any drawings
swPackAndGo.IncludeDrawings = True
'Set folder where to save the files
status = swPackAndGo.SetSaveToName(True, SavePath)
'Get files path
status = swPackAndGo.GetDocumentSaveToNames(pgFileNames, pgFileStatus)
For i = 0 To UBound(pgFileNames)
myFileName = Mid(pgFileNames(i), InStrRev(pgFileNames(i), "\") + 1, InStrRev(pgFileNames(i), ".") - InStrRev(pgFileNames(i), "\") - 1)
myExtension = Right(pgFileNames(i), Len(pgFileNames(i)) - InStrRev(pgFileNames(i), ".") + 1)
'Replace name
If LCase(myFileName) = LCase(OpenFileName) Then
pgFileNames(i) = SavePath & SaveName & myExtension
End If
Next
'Set files path
status = swPackAndGo.SetDocumentSaveToNames(pgFileNames)
'Flatten the Pack and Go folder structure; save all files to the root directory
swPackAndGo.FlattenToSingleFolder = True
'Pack and Go
statuses = swModelDocExt.SavePackAndGo(swPackAndGo)
'Close initial template
swApp.CloseDoc (swModel.GetPathName)
End Sub
不太确定如何用谷歌搜索我正在寻找的东西,但我发现的是: http ://help.solidworks.com/2018/english/api/sldworksapi/get_excel_design_table_worksheet_example_vb.htm
试图弄清楚,也许,这里有人已经知道解决方案?
解决方案
推荐阅读
- image - 使用 crypto-js 解密二进制文件(图像)
- jquery - JQuery DataTables 1.8.1 Checkbox - 代码等价
- openssl - 运行 openssl 一次以使用现有私钥和自签名 CA 生成服务器或中间 CA 证书
- r - 不是标准误差的数字 (NaN),下限和上限使用未标记的预测函数
- azure - 使用 openVPN 的容器实例无法正常运行
- python - 在这种情况下,“for name, val in globals(). items():”是什么意思?
- swift - QLThumbnailGenerator 加载错误的图像
- docker - 更改 docker rootless 的默认卷挂载点?
- powershell - 将现有进度条添加到 GUI
- javascript - 如何使用 Vanilla Javascript 检索多个 JSON 文件