下面是分离到配置(备注:间隔符同样是空格号,并可以根据自己需求编辑)
# K! Y3 I; W' v- E. j8 K2 t2 i$ ^$ q
'定义sw% W3 l+ a3 R) j) g
! b0 u* U* c9 U2 n
J* [9 a Q6 q' }$ @
( f7 h- C1 J. b4 e3 rDim a As Integer
2 ]( a2 B4 C( V9 V2 B6 W+ q
+ B# B3 _% p* {, [( S5 L/ h+ ]8 P8 FDim b As String
' L. u. Q5 m, x7 F/ m# T b5 u9 n2 k
Dim m As String% s u6 N" b$ u" \9 {
, U; h( g! X9 \# v9 Q# ^8 ADim e As String! D. g8 W! O2 d( U, E2 |
, @5 `0 w+ e' {
Dim k As String
4 N- z" ~+ r$ @% h
1 _! N3 r0 m0 p2 ^Dim t As String' @) e: Q. w# f5 X5 A2 [
0 i8 @5 D) u7 m. j6 _" l7 S# l, wDim c As String1 L1 u: C2 g* P( D' q7 u* c
( ^: ]* y" Z* `2 K# e/ nDim j As Integer
$ U$ o) |3 z% @5 f6 W
/ I; y* e# t( d# KDim strmat As String
$ n+ |! u( ]& n7 ~+ [
' e: L$ b* c" n& QDim tempvalue As String: j' J; e: f- O
2 N0 q8 w q6 b& qDim Part As Object
/ j9 w4 [" E, r4 h* u5 j. i6 b( z5 r; C
Dim swApp As SldWorks.SldWorks1 j+ a" T) j/ Z6 O$ [6 h
, f. |5 L. E- D @6 Q1 g/ E
Dim swModelDoc As SldWorks.ModelDoc2
# x( n& W6 | G( Z0 _' S6 W- A0 G8 Z" z; C* v+ s- N w/ {
Dim swConfig As SldWorks.Configuration: u, r# F+ `9 H) }. W; [" u
* T7 j; X' q9 v! n" ^
Dim CustPropMgr As SldWorks.CustomPropertyManager' Y# J4 [& U0 R
+ g! L2 w- l5 i$ gDim swModel As SldWorks.ModelDoc2
/ |; p9 x9 A( A6 S! f/ O4 X5 o) Q4 e7 e; t" h; L9 m
: u+ B5 O2 j. \( d
: _5 }' `& [$ g' t% n* HSub main()
- `" b2 n! W" g# N6 l1 T
; [3 z. g" n7 N+ bSet swApp = Application.SldWorks
' n# A+ p7 y+ A7 U% w/ ?( F/ w0 Z! q0 X$ o
Set swModelDoc = swApp.ActiveDoc
8 g# T. Z! a+ O$ R
5 W5 ?! R: U' U; D/ T8 B4 ?Set swConfig = swModelDoc.ConfigurationManager.ActiveConfiguration+ b" A( u1 A: x! i
5 t ^' _3 U( `2 u
Set swModel = swApp.ActiveDoc
N0 [# y! c% Z! `! `
0 f/ q7 r" H+ t5 X1 NSet CustPropMgr = swModel.Extension.CustomPropertyManager
, W8 k( Z9 O# x( Q* U4 |/ M/ e! S, {/ @( L( G. _; G
(swModel.ConfigurationManager.ActiveConfiguration.Name) '配置特定延伸( k# S- ^4 ?) I" k7 F# N
) z9 F5 c d, N+ J8 P
+ r! M6 \" e/ P( Z: I% Y. L3 D$ v4 k" A4 _5 x
'设定变量" ^" Z* }; x: \( g
, K& Z, d/ k9 C/ A" |c = swApp.ActiveDoc.GetTitle() '零件名5 X7 E6 f9 t- M) f3 f! u
2 C0 H- G: V3 \strmat = Chr(34) + Trim("SW-Material" + "@") + c + Chr(34)
" Z7 L* \) e" q. o) B2 B c! q
a = InStr(c, " ") - 1 '重点:分隔标识符,这里是一个空格,也可换成其他符号; ^% d4 g9 r4 Z$ n$ n
/ p3 l7 \. r, O2 W. s, u3 OIf a > 0 Then2 ?# Z: i( m% s D4 z7 D; P
! z# t4 X1 s2 I+ R7 Y6 {5 yk = Left(c, a), U* n9 e1 o9 h5 X T$ z2 o
$ Y8 {/ D B6 Y+ `! ]
t = Left(LTrim(e), 3)) C7 Z% Z2 Z+ c v% t7 [
' V+ p; L1 C: NIf t = "GBT" Then
& f& V3 _0 \' ]. A; U9 W- E8 V% _3 p9 o
e = "GB/T" + Mid(k, 4)
[) T) W5 ?9 `
# t8 ~; K e U9 I2 r6 H4 _Else
+ B1 V- D; d2 J! v5 B% |
- j: Q* ]& r- D+ @3 ]e = k/ E$ j$ I, {, b0 P! _
9 L. Z; R4 @, }( h' c3 \- O8 L
End If
- m' b0 \# x' \7 ? R. Z+ o, L8 d# A- e3 ]
b = Mid(c, a + 2)
9 d1 `* f" e6 y( W$ O8 ^$ I4 q+ [# z, \8 V. q& o& {0 {
t = Right(c, 7)4 C, R) p$ W# o
/ ]. ~; d3 c `7 u: JIf t = ".SLDPRT" Or t = ".SLDASM" Or t = ".sldprt" Or t = ".sldasm" Then
* i8 w7 N& K6 v) _. P# l! g; r. j( T3 }9 W6 U3 O- B' z6 b. c
j = Len(b) - 7 '消除后缀(区分大小写,即含4种)
6 C$ h# v. Q" |7 r% m, p8 ~, i1 W' d6 a6 e9 ^
Else
9 x0 a8 i$ h X8 H* b: R
7 q" m- c: H. n: V) |( Z' vj = Len(b)5 T! f' [/ _* S I2 l& ?/ J# V: F
, G* f6 W! N, i: r( D6 {
End If& Q ^0 o6 l+ d! [. N2 L @
+ N9 E7 ?0 _8 E9 o, N- d8 c$ Zm = Left(b, j)
, B9 G! k( M& G; T* F9 D8 Q k9 _9 u& j
End If9 ~& S% `, l# M. i! W8 @
: z" O( R/ U/ E7 k4 _7 L# @'删除栏
8 t8 {0 A' o# f1 w, U0 w( a7 Q! |4 y& g
CustPropMgr.Delete ("Number")
; p F( k; T" ~& I! i H! ]. p; Y8 \
" d i9 }% J% z$ |. CCustPropMgr.Delete ("作者"): o1 A1 e- {9 E. H0 r: m, F7 `
1 S# e( E( r0 b5 R) @% R" j9 fCustPropMgr.Delete ("图样名称")
" j- H% _8 _4 s$ R. e! g+ P2 p& G2 d4 s2 b4 ~
- N: {' R, i, z0 X) ]' h( \' M$ d1 x9 h! ]$ c2 I
4 X: H1 a- V5 }7 U
5 y' t# j: Q! z' B$ C1 _. P* X/ h) T2 Q5 O, g& x. {! l1 v
'新增0 W7 ?( w6 @% ?& X d; _4 `4 k
4 ^! u, O% D! W! X. p
CustPropMgr.Add2 "Number", swCustomInfoText, e# ?8 i" z. _/ _. E& y8 s& L
5 I+ {+ p! R+ A& H4 \3 b
CustPropMgr.Add2 "作者", swCustomInfoText, "刘腾qq420221716"
: g& K5 Q! }- _+ }' C6 f* ~7 P( }; a/ k
CustPropMgr.Add2 "图样名称", swCustomInfoText, m
6 V2 s& [0 A: w" q; U {9 D0 S' i- h6 J# b; c8 a# k
8 W# n6 r2 z$ _' U9 R. E' M5 G) t$ M! H% w: J* g% ~
; s; y) }, |6 UEnd Sub
) r7 f9 j' p' [$ Z8 B& o7 c3 [* \% t% Y! P
|