下面是分离到配置(备注:间隔符同样是空格号,并可以根据自己需求编辑)
% U4 d! F8 h% L/ }8 e. @6 r2 |: Z$ x3 z: r: w5 i- n/ a% W
'定义sw( D' u9 C" o* c; c+ c! C' y
4 Q) }/ l$ E9 ]6 w! R& I, @: R. a" L" M: \2 U
. q' p# B4 |9 k$ x
Dim a As Integer( R1 u T0 a6 q
0 E% y+ U( q( gDim b As String. y) b! x, z {- z3 |% P6 H; V
- x& A! v' R" I; C7 H
Dim m As String
: w9 R V$ B. r. H F0 m! ]( E* A/ ~9 [/ }2 ~. V) M- A8 \
Dim e As String
1 A( y4 T1 Q' g1 N8 t: J8 D
r8 ?9 C) b# n: U- q- P: vDim k As String* ~7 u% J8 h+ Q q# l0 T- e
: f) G6 }3 M5 v
Dim t As String2 r1 O: E2 n. ?/ r" [6 Y& Z
* ]3 N% V- l5 a" a* UDim c As String( ~1 c5 F' ^4 L% Q
; D0 I- l. T# p7 J, k
Dim j As Integer
% \4 O! O7 M: E- H$ K
0 e. V" J4 j# x8 t1 y4 {/ tDim strmat As String
3 c: ~' B2 r& o. m, O' _' t' Z$ s' J- Q9 n! v% n; x; ~/ ~
Dim tempvalue As String
# k5 r5 x6 b3 r: x8 B' ]' J/ O. K' i5 D& Y! f. K7 W7 R4 p
Dim Part As Object
9 T7 U2 O' V& V
: J& G4 q6 ^7 D- m$ p( QDim swApp As SldWorks.SldWorks
) I1 p% f+ n7 u2 p) y5 t% P1 g% U" y1 b6 E5 Q% v+ [4 V
Dim swModelDoc As SldWorks.ModelDoc23 p; y* j3 }3 [8 [8 ?
. D: g; x% W) b0 T2 l1 g) @) T
Dim swConfig As SldWorks.Configuration
# z1 s |, d1 e: f" S+ o- i3 S/ j/ ]# k
Dim CustPropMgr As SldWorks.CustomPropertyManager2 ]5 W L* }8 `$ p1 f. t9 R( G+ L. S8 ]
6 f- [6 m" J8 p! i) k2 g6 ODim swModel As SldWorks.ModelDoc23 _' O9 c4 T' d( d6 }1 g
5 h& ~! C! ?, e' D, T) l$ H9 t8 L
, l O. i1 B ^6 Q9 p& L
Sub main() w+ p( N/ G: l" q3 J* B/ [
0 E5 {8 S" f7 o) f* f/ M
Set swApp = Application.SldWorks
1 K0 U X0 _! L9 w; y1 Y m, F) Z
Set swModelDoc = swApp.ActiveDoc! W4 l2 i/ r' C" Y; e% ^6 m
" w5 [# u) W# N" E1 b
Set swConfig = swModelDoc.ConfigurationManager.ActiveConfiguration% n: H6 C* N. V8 J6 Z- _
0 e1 g* [3 |* c ?* R, B5 g
Set swModel = swApp.ActiveDoc( N6 }; X- J- U- C8 Q y5 A7 S
g1 J. I& ]* W& H7 y3 ^
Set CustPropMgr = swModel.Extension.CustomPropertyManager/ L: z5 {8 i% W7 x4 v
3 c% R5 B& p0 f! X3 j' M+ t0 J' @
(swModel.ConfigurationManager.ActiveConfiguration.Name) '配置特定延伸$ w' V$ g7 T R+ [3 ]" r9 [) A
1 ?- Z4 q6 R4 n! n6 R
" e' k7 n0 ?& y# e- u8 T' F, i! F
'设定变量8 C2 d+ X/ H* c1 N& S. P) U
* O1 E( Z q9 J0 q: q0 ]
c = swApp.ActiveDoc.GetTitle() '零件名
" {1 d! b! h2 S5 c" R, P# `
7 K$ p) ]; x5 P: xstrmat = Chr(34) + Trim("SW-Material" + "@") + c + Chr(34)5 \# a0 q% T/ t) f; Q
- f; ]2 v% f) d& L. _9 Ua = InStr(c, " ") - 1 '重点:分隔标识符,这里是一个空格,也可换成其他符号
- U3 {6 C4 `3 }% b
( a5 T( }( ?2 @1 a$ @If a > 0 Then* x# Z, k/ m3 }% B4 f5 G
- @- @7 L- @* \. m; m. Uk = Left(c, a)
- b% _# B$ t) E7 {3 T8 ~
( h! \/ Q2 @" ?- X- `2 _- ut = Left(LTrim(e), 3)% Q3 v3 X0 Y* c; b+ H D
* _3 T; J, }. e# ~5 g7 X1 N
If t = "GBT" Then Z- z$ r6 H7 O! ?6 E
" {0 w3 a- ^5 |9 qe = "GB/T" + Mid(k, 4)
0 N' i" }( ?2 J6 ?& E0 x2 J" H- z7 ]8 T+ q- G/ C
Else I% v- F# L5 r+ m3 ]8 s
' O" I7 u# e* N% R8 e3 ne = k
; F+ [( ~5 V8 j' d7 a+ |* D
0 y* i6 }- U: B) Q b& kEnd If2 c, ?3 R, h3 X. ?; p
5 F! H: x$ v. o$ J0 u
b = Mid(c, a + 2)6 r2 D% W. `: \1 [
: ^* @' m- t5 P8 X
t = Right(c, 7)3 U9 F$ [6 I. c
; K: D7 |: L: x; cIf t = ".SLDPRT" Or t = ".SLDASM" Or t = ".sldprt" Or t = ".sldasm" Then
% s( ] \7 U$ k" e
! |( g- z3 r o; \9 u$ r( \j = Len(b) - 7 '消除后缀(区分大小写,即含4种)* W3 q% F: q' ]2 D- W& @
- T/ J3 B1 J; z' O c, @
Else/ o) M5 g' B. Q/ U/ G& }. I
% x1 ? u7 C* B3 w1 Dj = Len(b)
8 g3 X& A0 f6 X1 h* P
) ]3 j f6 v) fEnd If
1 L6 f% W/ r5 _% H
: p$ H: N! _4 t5 L- c: c, `5 Pm = Left(b, j)
) V; o4 V H# D& b7 }$ I1 g) ~! k4 h/ P
End If) {9 B w: _% N$ f$ J
K; \. V m8 ~/ j
'删除栏
( X% I! d& x- j+ s& q& F4 `% Q8 |' z5 k ^0 Q$ R/ C) i9 s
CustPropMgr.Delete ("Number")
& E! N6 ?! P2 X# L( L& o/ j5 j7 |7 }4 H$ C# Z9 f* N
CustPropMgr.Delete ("作者")3 H% W+ U; T# m. Q
+ c# j/ t0 P# `( S, nCustPropMgr.Delete ("图样名称")+ U4 c+ b: }* C8 U
. d8 u# s9 C( x7 B6 d9 s9 g
8 U" L% w7 \3 e& `
* x7 W4 E) c6 A, N! G
* x1 D- H4 W& a B0 j5 h; N6 M. `. q+ W0 D
5 i3 \- p4 C( L" ]
'新增
( i5 c! _ G' r/ q1 P* F9 r
& Z/ U6 M$ w: E/ V/ i' x) ?2 ~CustPropMgr.Add2 "Number", swCustomInfoText, e5 J, x; ~" ?4 s: R O. ?
+ P6 ?/ P" J4 s5 b3 Y! q
CustPropMgr.Add2 "作者", swCustomInfoText, "刘腾qq420221716"
: O9 c; t5 t, Z) {3 S# r5 Y4 r! q( c! z
CustPropMgr.Add2 "图样名称", swCustomInfoText, m) A8 c' Z9 n7 s! b% Y, [
h8 x; l+ o2 x p+ L" `; w. s
8 t/ U6 D. c$ s: V- V/ u/ B( q9 n; g9 P7 @$ ?) ~- }
" W& y/ x' K) W G& _; K8 z. ~End Sub
2 |3 E- Y3 b y# K
s9 M6 }2 G& L |