|
|
发表于 2015-11-25 11:23:12
|
显示全部楼层
来自: 中国广东佛山
8 ]+ `' n8 ?' X: t1 q( z; R2 U( c首先谢谢梁大提供了那么好的东西~7 r' r" V3 K, G) Y X r9 s) [7 |
再来,SW API 里面提供了两个函数可以满足您的使用要求。0 C- x" j: G+ a
1. iModelDoc2.GetType 可以得到文件的类型 * k0 i4 |$ {6 g( W' f
2. iModelDoc2.GetPathName 可以得到文件的全路径
' B6 j& @! ^+ d; @
- C' ^# A1 J; K9 ?2 b2 r针对梁大提供的宏,可以追加如下函数,
* o( B2 @+ g! O U% u$ b
$ I# l+ ~: v) z4 q* FPrivate Function getModelDocExtAsString(ByVal prModelDoc As SldWorks.ModelDoc2) As String
# ?6 {) ^, z& ]- X$ f* l1 e# p
7 B- k* L2 f: {! V& ~# B9 B Dim sFileName As String7 x# D9 i; R" {2 a. f$ h
) p5 K$ V% c) g1 e, n Const swDocPART = 1, b0 X8 E( ^$ H. s' O
Const swDocASSEMBLY = 2
# V1 a# I1 k0 m! W6 q* E% @ Const swDocDRAWING = 3
& Q3 ^' Q( Z6 k' I7 [ t
" N3 [% [) r* g- A; c/ ^ If prModelDoc Is Nothing Then Exit Function
4 q/ o, t. [ y2 _+ N: d2 E Select Case prModelDoc.GetType0 B, l& Q* _7 p+ V7 @6 T
7 U5 ~' U. @( M+ D1 u Case swDocPART
0 D7 k* y0 @1 x* N- d5 |) n getModelDocExtAsString = ".SLDPRT"
$ q* m/ ?( ~6 q# J, H1 G9 Q
4 i* _# C# a: D) s! B; e Case swDocASSEMBLY
4 r* m) a2 O7 p1 r) @5 J5 t0 ?! M getModelDocExtAsString = ".SLDASM"
7 G. {$ ?( i6 P
! `) X2 o7 y5 q, v5 t% v* M Case swDocDRAWING
9 k, P9 E2 a0 p getModelDocExtAsString = ".SLDDRW"
. a$ {6 ~ I- ~! F- C7 C, F# J
- \# \! l8 Y9 P Case Else y9 q3 }% { ~6 N( Z( _2 v2 P
sFileName = prModelDoc.GetPathName; u# c' u1 w4 A
If InStr(1, sFileName, ".") > 0 Then
: r) l/ o0 E% x, W* H- b* h getModelDocExtAsString = Right(sFileName, Len(sFileName) - InStrRev(sFileName, ".") + 1)
, ^3 G+ t, p, d3 s9 z' T9 s$ _ Else: getModelDocExtAsString = ""9 K7 H) ^! f- U4 o8 j2 A
End If% j7 A; u$ a' M7 [0 w, Q
0 V" m$ ^$ _; R" o# B
End Select
! z8 B" j& F# Z7 y3 J
, P1 O+ Y& S7 nEnd Function
: Y: f/ T( c. ^, d/ W( v9 @+ x h) z2 C" `+ [/ ^
4 j. ?) |; J/ O* ~" o g并对原来的宏的一行作如下修改:: t( T9 Y$ H4 N# M0 q
, E3 Z3 [ \, ^) h6 x+ ]'Na = c + ".SLDPRT"
# a- w; r# \! r! a( l: \+ ]Na = c + getModelDocExtAsString(swApp.ActiveDoc)3 L7 p, O" Z0 D# `
$ s8 y5 K4 U. E* X( [5 [8 c即可。 |
评分
-
查看全部评分
|