实例介绍
【实例截图】

【核心代码】Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Myfile As String
Dim ext As String
Private Sub browseFolderButton_Click()
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0, "选择文件夹", 0, 0)
If Not objFolder Is Nothing Then
folderTextBox = objFolder.self.Path & "\"
End If
Set objFolder = Nothing
Set objShell = Nothing
If prtCheckBox.Value = False And asmCheckBox.Value = False And drwCheckBox.Value = False Then prtCheckBox.Value = True
If prtCheckBox.Value = True Then
ext = "*.sldprt"
AddItemToListBox
End If
If asmCheckBox.Value = True Then
ext = "*.sldasm"
AddItemToListBox
End If
If drwCheckBox.Value = True Then
ext = "*.slddrw"
AddItemToListBox
End If
End Sub
Private Function AddItemToListBox()
If folderTextBox <> "" Then
Myfile = Dir(folderTextBox & ext)
Do While Myfile <> ""
fileListBox.AddItem folderTextBox & Myfile
Myfile = Dir
If Myfile = "" Then Exit Do
Loop
End If
End Function
Private Sub clearAllButton_Click()
folderTextBox.Value = ""
fileListBox.Clear
End Sub
Private Sub killFileButton_Click()
Dim i As Integer
If fileListBox.ListCount > 0 Then
For i = fileListBox.ListCount - 1 To 0 Step -1
If fileListBox.Selected(i) Then
fileListBox.RemoveItem i
End If
Next i
End If
End Sub
Private Sub MacroTextBox_Change()
End Sub
Private Sub selectMacroButton_Click()
Dim filter As String
Dim fileName As String
Dim fileConfig As String
Dim fileDispName As String
Dim fileOptions As Long
Dim modulenames As Variant
Dim moduleName() As String
Dim modulefilter As Integer
Dim i As Integer
modulefilter = 3 'swAllMethods
Set swApp = Application.SldWorks
filter = "宏 (*.swp)|*.swp|"
fileName = swApp.GetOpenFileName("选取宏程序", "", filter, fileOptions, fileConfig, fileDispName)
If fileName <> "" Then
MacroTextBox = fileName
modulenames = swApp.GetMacroMethods(fileName, modulefilter)
moduleComboBox.Clear
For i = 0 To UBound(modulenames)
moduleComboBox.AddItem modulenames(i)
Next i
For i = 0 To UBound(modulenames)
If UCase(Right(modulenames(i), 4)) = "MAIN" Then 'InStr(UCase(modulenames(i)), "MAIN") <> 0
moduleComboBox.ListIndex = i
Exit For
Else
moduleComboBox.ListIndex = i
End If
Next i
End If
End Sub
Private Sub runButton_Click()
If MacroTextBox = "" Or moduleComboBox.Text = "" Then
MsgBox "请先设置好批量执行宏程序的各项参数!"
Else
If fileListBox.ListCount <> 0 Then
For i = 0 To fileListBox.ListCount - 1
Myfile = fileListBox.List(i)
If UCase(Right(Myfile, 3)) = "PRT" Then swFileTYpe = 1
If UCase(Right(Myfile, 3)) = "ASM" Then swFileTYpe = 2
If UCase(Right(Myfile, 3)) = "DRW" Then swFileTYpe = 0
Set swApp = Application.SldWorks
Set swDoc = swApp.OpenDoc(Myfile, swFileTYpe) '开启档案
Set Part = swApp.ActiveDoc
Call swapp_activemodeldocchangenotify
swApp.CloseDoc Myfile
Next i
MsgBox "文件列表框内文件已执行完毕"
Else
MsgBox "文件列表框没有文件供批量执行"
End If
End If
End Sub
Private Sub exitButton_Click()
Unload Me
End Sub
Private Function swapp_activemodeldocchangenotify() As Long
Dim runmacroerror As Long
Dim moduleName, procedureName As String
Dim temp As Variant
temp = Split(moduleComboBox.Text, ".")
moduleName = temp(0)
procedureName = temp(1)
swApp.RunMacro2 MacroTextBox.Text, moduleName, procedureName, 0, runmacroerror
End Function
标签: SolidWorks 文件夹 id dw 批量
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论