下面是分离到配置(备注:间隔符同样是空格号,并可以根据自己需求编辑)) ^' P& {$ F. x$ U" s
& s5 N. A/ @5 f; [+ V' W'定义sw
/ F, I: {, r1 H. q p3 d
& d2 E. G" X: m6 J+ J+ s' y) t F$ d3 `* z9 z& m& I9 }" ^: {
! j: F; T! ]# D8 bDim a As Integer
1 n- i4 f$ k; [! |- ^) Y
: g! j& m: }( z3 }8 f; c( IDim b As String
6 V% t9 X: B4 k0 Y: Q7 U
- q" P" N9 b [/ D$ q* \Dim m As String
5 S9 L' Y" @$ O* i$ @ t7 N9 f! n9 I- [' N0 T1 x/ r
Dim e As String
) ^/ T/ y' l+ C0 H% f: E$ u. \% z5 |/ x5 ?
Dim k As String! B/ K0 o( k5 @: \$ C6 h: y
( g8 w4 m5 I, A. e, ~' N- Z( ~
Dim t As String
/ \8 z7 i9 r* |/ U+ W
: G9 F2 h+ e% x4 G4 N6 qDim c As String
- d5 [: d; U6 s( i, p: _
2 _" v, {9 Y3 S* }, [+ K, CDim j As Integer* L. @' L* B ~, F3 D b2 |
* i9 W! `8 A) k8 H' L {* V
Dim strmat As String& q4 o8 x8 y) m* k; O1 m
7 e2 h% V e; `2 M6 [7 xDim tempvalue As String
$ c" e# M2 I) c+ u8 S
6 z! j o# R0 S: [Dim Part As Object
6 Y( [9 n' v+ R* y; O4 e7 I
' p w3 `" f1 [) YDim swApp As SldWorks.SldWorks. V4 Q, F- n7 q6 D3 n7 h, ?/ \+ t
]$ M7 }3 t( Q. ]$ u% v1 Y
Dim swModelDoc As SldWorks.ModelDoc2
& a1 e) J( o) M( P# R5 x; g& \$ T; Y* n) K
Dim swConfig As SldWorks.Configuration# a* C' v2 |1 ]3 Z+ L. T4 V" I
5 {7 K/ ^* T/ L% I! o$ {. M/ @Dim CustPropMgr As SldWorks.CustomPropertyManager
- g* ^# h( ^3 g* D: r2 \$ w
* i' G- i, {, p, YDim swModel As SldWorks.ModelDoc2
+ ^; o* k% B# u! D8 T9 v& f3 p f/ S9 U+ ?3 [9 ~
# {/ r5 ^$ ^+ i+ [
& i* B7 `/ F; u, y# X" N- _Sub main()) w: B# C' t# I: X3 Z8 a& j i
+ O1 k% @% O, M% P) p& l! xSet swApp = Application.SldWorks
9 c( e6 \ x7 Z* O8 W8 h+ Q( m( _" S& |+ z; q) `& v
Set swModelDoc = swApp.ActiveDoc
3 b: s8 n4 m" f2 a% W% I/ A$ b5 z! J4 `. O+ B
Set swConfig = swModelDoc.ConfigurationManager.ActiveConfiguration, `1 e+ o& T' R
& }4 x* y/ a* R i9 |- B6 l
Set swModel = swApp.ActiveDoc! K+ Z- C/ O0 n6 f% b6 ~% l) M7 Q
3 S F8 \, c* K4 S& eSet CustPropMgr = swModel.Extension.CustomPropertyManager% j& I [- w) X, K# |
% q" @% V7 [# w5 k0 I
(swModel.ConfigurationManager.ActiveConfiguration.Name) '配置特定延伸4 d0 Z" M" C3 m, ~9 W; N! u
3 }4 }5 r. S! Y4 A1 C. l C3 ?( W- `! b& p4 w
8 q% {* m- _1 f3 \7 x( K& C
'设定变量! J% g; S/ ^8 K; w% Y/ I3 P
7 ]3 U3 o1 ?( t6 @% j& ?7 ~! U3 D. U
c = swApp.ActiveDoc.GetTitle() '零件名
, K0 z! o [3 _- s7 p* C& p9 I% y9 S1 y) }
strmat = Chr(34) + Trim("SW-Material" + "@") + c + Chr(34)
) G% T4 I. Z2 ~
( K( F$ Z. {+ |, N7 q! w V2 }a = InStr(c, " ") - 1 '重点:分隔标识符,这里是一个空格,也可换成其他符号
6 D, O" p4 @8 O1 X& j
( Y7 C/ W; I4 g! S5 w8 RIf a > 0 Then% M8 _3 i8 e- n9 e
: C) k# j4 W1 _% I* k! Yk = Left(c, a)
! f. A$ M3 `, C0 K' c$ Y- k m2 {# \0 J* ^7 |( i
t = Left(LTrim(e), 3)+ a# x; ^$ @" `
9 N8 {/ C g/ J& U. ?( E7 OIf t = "GBT" Then
0 F0 C) _9 l, r u( l! r1 Y$ S$ Q
e = "GB/T" + Mid(k, 4)2 ^5 z$ T9 h0 [/ I
0 m+ \) {6 S) q* J6 `( D
Else
& V% I1 I9 B; L Q$ Z4 L+ p' v' A* T3 h7 c
e = k: u0 `- g/ _3 [( Q% _1 F8 t4 H* v
. [* d+ u; }0 u! l+ {: U: FEnd If
% G- x# p" y! R9 \9 |- a3 q
' ^) J K7 Y3 {+ u& I& t4 Vb = Mid(c, a + 2)3 h# V- O. t& K5 k+ [/ i, Y) H5 |
- p8 ^" X1 G# V) J$ m# S# E8 dt = Right(c, 7)
2 j) P0 y3 C% q. l3 @3 @9 L
* H% h8 U; v) b- K6 AIf t = ".SLDPRT" Or t = ".SLDASM" Or t = ".sldprt" Or t = ".sldasm" Then" p. z& k7 u9 W" r t9 N, ?
3 D+ J. p5 e/ j" c/ I1 p
j = Len(b) - 7 '消除后缀(区分大小写,即含4种)7 \- m# |9 Q) ^+ i- r
' T/ b ^& Y! T" o
Else
, c4 g; ~$ v& s% u# G7 v3 {
" C; l2 d+ K& Dj = Len(b)/ ~/ O0 C; ]6 g( S/ l; ?
) q8 o, }7 o+ IEnd If
& y' r) _- E) }2 I2 ~+ B4 ^ f2 I7 o! K0 u2 ]' I- w+ J& h" N9 L# L
m = Left(b, j) }' G5 T& y5 v0 x7 F
8 N/ F; G7 S2 n5 Q3 a2 W3 v9 C
End If7 t6 }) Q3 {) W& j7 [, y
5 Y, e+ O9 R4 A8 b/ a' B y'删除栏- r- m, C$ e0 I& Q) O* s
/ V7 K/ V, N' q2 j# @6 qCustPropMgr.Delete ("Number")
$ F5 n5 K3 w4 G* k6 U7 E. t6 \, f2 U v
CustPropMgr.Delete ("作者"), I. q8 r* n9 ? r5 w, U
0 C$ {$ O+ g1 P4 g
CustPropMgr.Delete ("图样名称")( \9 y4 U( [( n
% f4 K8 U/ @ W- E* b O$ G! M3 Z6 v9 K) Q0 p4 n
+ q; y% R9 H7 \2 f' s8 Y4 J
% D9 R" T2 S; i: F) v2 Y, b$ }4 R, a5 q. ?& u8 J
+ T( m7 h& H5 }! ~' \
'新增, e8 C* W, M* L
$ U4 N3 Q3 y$ s @CustPropMgr.Add2 "Number", swCustomInfoText, e% ?& L0 Q' T0 P0 e
1 p! y: `* S3 \9 a; m1 e% r3 UCustPropMgr.Add2 "作者", swCustomInfoText, "刘腾qq420221716"
" h0 S% C- |5 Y$ c. B
+ J* S" m* N6 X: _4 [CustPropMgr.Add2 "图样名称", swCustomInfoText, m% O$ e9 s5 h; J7 z4 N3 [) f' z0 |; a
& J; k6 [: m* b3 I, @8 @6 X
$ p( ?0 U$ r. V E
1 U2 h$ \ w/ j' T) t
4 y1 {8 i& D; n9 H' u+ o: S7 PEnd Sub
9 h9 u* j5 C% C/ C9 ]+ c4 \- A: _
, c: N& B7 v7 }3 A( q |