SOLIDWORKS Task Schedular我试了,根本动不了,自己也倒腾了个宏,功能是工程图转换成PDF和DWG文件,操作是,工具---》宏----》新建----》把下面的代码复制进去----》存到硬盘某个位置----》,调用的时候是,工具----》宏---》运行,当然也可以自定义到SW的工具栏上,宏文件源代码如下需要的拿去,:
! x, W# l. z- r$ W1 k6 WDim swApp As Object
6 g/ }, \ u# UDim Part As Object
2 I+ s4 l& V/ I" S0 TDim boolstatus As Boolean
( w: `+ z- r }0 }2 V. ?- m2 l" U) BDim longstatus As Long, longwarnings As Long
; n# u" d @ ?4 z9 [# _, IDim PathStr As String3 T% U7 L5 _' A
Dim FName(500) As String, FNum As Long
7 x2 S3 `0 f( f* P' r5 h% G5 X" @9 e9 ?& J: E& a; j2 s
Sub main()
" `' z6 x# S! JDim i As Long9 Y# o+ s$ ?( e5 B0 C9 H8 b
Dim PathStr0 As String, PathStr1 As String
0 A; u: u7 [" r! ^5 `0 I7 \Dim PathStr2 As String, PathStr3 As String, PathStr4 As String, PahtStr5 As String
9 M/ }" M |7 E1 l$ eDim L As Long, L1 As Long. @# x+ v( a4 K. p/ s! f
PathStr = InputBox("请输入需要转的工程图所在位置")* G4 b: ~ s( |8 E
Call Showfilelist(PathStr)
+ o7 J+ M# U# ZSet swApp = Application.SldWorks& L- E2 a) H0 `
0 J5 K/ P7 P) K& w. o
For i = 0 To FNum - 1* t5 ^% K5 P' W/ T6 m! h
PathStr0 = PathStr & "\" & FName(i)
. i1 t* H7 b) w1 S! I Set Part = swApp.OpenDoc6(PathStr0, 3, 0, "", longstatus, longwarnings)1 u# Q! `* J9 [% z" [" d4 f
L = Len(PathStr0) d: z) {6 j; |' C
PathStr1 = Left(PathStr0, L - 7) & ".DWG"! @( l$ b- Z6 L
PathStr2 = Left(PathStr0, L - 7) & ".PDF"
8 Y$ L H: q; J! i: n% Y- V longstatus = Part.SaveAs3(PathStr1, 0, 0)
) L) A% w+ }" W longstatus = Part.SaveAs3(PathStr2, 0, 0)
' b( v" @8 f* g; {5 ~2 O9 l, K
5 z* D& \, G$ W: n7 g9 S* r Set Part = Nothing. Y# C- }- h) a" |% ?# B5 D% n( E! c
8 W- ?) v9 Z. O( g9 b7 T; A
L1 = Len(FName(i))
( R: h1 g4 J, T PathStr3 = Left(FName(i), L1 - 7) & " - 图纸1"
1 x, w# E1 W) S/ k( ~# f PathStr4 = Left(FName(i), L1 - 7) & " - 图纸2"
" H5 K+ Q3 s# ~ PathStr5 = Left(FName(i), L1 - 7) & " - 图纸3"/ F2 M2 l/ I6 |' D1 T! Z7 p
' w) G- ~& S- a3 u/ d/ X) i
swApp.CloseDoc PathStr3/ {* }/ {. Y0 Q
swApp.CloseDoc PathStr4* S# |3 [; \ D' o' h
swApp.CloseDoc PathStr53 c1 @! a" U- v# M0 e
0 b. e" U; t0 I+ {2 n/ ANext i, O/ R0 _$ r1 Z# k: p! ~( ?
) H' }8 j; V- m. Y# {9 j( I
End Sub
. E9 f1 ~, F' m# G i9 L1 b) y* U/ N8 z0 ?( V
Private Sub Showfilelist(folderspec As String)- v& f+ t! E" v4 M
Dim fs, f, f1, fc, s
" ?" z; f0 l ~' {! w: u Set fs = CreateObject("Scripting.FileSystemObject")7 W/ d$ r1 m3 Q4 v
Set f = fs.GetFolder(folderspec)$ s) p# f6 A$ g p
Set fc = f.Files6 m5 @7 T9 @8 m
FNum = 0 '清零
& A& W, C$ L# ] For Each f1 In fc4 v, ?" T% f3 ?' a
If InStr(f1.Name, "SLDDRW") > 0 Then
3 g3 e& W- l" c) n FName(FNum) = f1.Name. K; |" `6 V+ X# v# I
FNum = FNum + 1
9 U1 ]+ U" L9 }6 E6 Y End If, O& q3 A- Y m6 {
Next0 `/ V7 G" i! F# O& v t
End Sub
! d) k u& g' t0 _0 ?/ s, [ |