下面是分离到配置(备注:间隔符同样是空格号,并可以根据自己需求编辑) $ ]5 l9 @6 u5 |( E+ t ( k/ h* Y- I# p7 _1 G: m# r'定义sw 3 h$ X$ k, ^; t. U* ]; B# l0 L! W0 c y* r9 G, q
+ t+ y) M- \4 [1 T1 Q/ b" @ 7 O" J" O" x& Z" WDim a As Integer 6 c7 m: m# L+ [6 B% O6 g$ x( I* H! @3 f* v; t* z Dim b As String & o! y8 y# a* {; s0 h0 D: J3 Y3 |9 C0 M2 j/ t1 Y- W" h+ p Dim m As StringH& p: y0 u$ V% v8 {1 B; c 0 Y4 B; M: u% k$ {: j/ U Dim e As String $ Z# s- {! b( z+ u$ e7 c8 S5 y5 k) X0 V& \- Q8 G. i Dim k As String/ n- f, g- S) q
% {9 G2 @5 e h5 S J8 m$ yDim t As String+ T4 v Q# g6 K: H, _ 5 s* G: d' V9 W* J Dim c As String1 p* v( s1 B* X) k+ C) a" p4 K$ f ' T+ I# G% n- e Dim j As Integer 2 E+ b9 r* ^! A ' Y! B! n( G! k* b2 U' l. gDim strmat As String + j) R' A+ h; R, ^3 {9 y 5 j/ H4 J r8 Y2 V& ADim tempvalue As String " b* j% E& k6 }1 W6 A. h5 R( v& K3 \' p( C& u, h" U8 D$ n. u- M3 a Dim Part As Object ; E. p7 I' D' ~4 N4 g) Z) o1 ?* Z/ n8 \$ i4 z: | Dim swApp As SldWorks.SldWorks6 S& N1 \ p( m, W2 B 2 w }% h( h! b Dim swModelDoc As SldWorks.ModelDoc2 ; |6 N2 r, m6 N5 `/ U+ @7 G( l Dim swConfig As SldWorks.Configuration+ ~: Q( ]: h3 G& R 9 K- q1 c) u$ o) r Dim CustPropMgr As SldWorks.CustomPropertyManager& z0 n+ d7 L5 g" T' ~# n y8 l 5 ?" q9 x# L( l Dim swModel As SldWorks.ModelDoc2 ; J; v2 O4 x6 P 7 `- j0 _; L; ~8 L4 J. h3 d M' T8 X) B' x: {% E/ k" {, r' M8 O ! ` H; N t4 I5 B: x" n Sub main() , V" J6 N/ K8 n. Q7 V: g ( ^2 F j. _- d m, j/ `' DSet swApp = Application.SldWorks! k- }0 W7 x( u' {- k
1 f# m1 z$ s6 e6 y9 k* y! bSet swModelDoc = swApp.ActiveDoc6 S- z5 P0 K0 ]6 V4 a
/ X$ f8 `1 Q+ ]Set swConfig = swModelDoc.ConfigurationManager.ActiveConfiguration : T) h* I: ~/ r: |+ w8 HG$ @ \ B" C9 x* [7 a Set swModel = swApp.ActiveDoc; ^" m) ^' h) x; J& J# Y $ ?& t2 K$ X8 w1 {' R Set CustPropMgr = swModel.Extension.CustomPropertyManager! Y. T5 ?% F" g& P( \$ P/ A
8 f8 a! b+ B' }" V/ _! u# d7 Y(swModel.ConfigurationManager.ActiveConfiguration.Name) '配置特定延伸9 L( F7 e7 [$ u 6 C1 g5 W) X$ I/ T3 P3 [
" s3 U2 o: r9 Q0 F+ `, h6 U ) O# }; g6 D- Q+ e& R'设定变量 ( e* z8 L2 K. x A& d0 @! w* @3 jc = swApp.ActiveDoc.GetTitle() '零件名1 m/ _: m2 B0 ] / {' `% H" s8 o strmat = Chr(34) + Trim("SW-Material" + "@") + c + Chr(34)& C7 E) c" ]: o" k5 {. k
9 x) c) I* B0 g i2 d; Y* s) s: Ua = InStr(c, " ") - 1 '重点:分隔标识符,这里是一个空格,也可换成其他符号 4 L1 w2 y# }. F; g$ Z9 S2 S) ?3 C' w& S; G If a > 0 Then ]% A) l% E7 k' V4 r9 s9 ~/ K; L k = Left(c, a) 9 p& u; U, J S: f: ^( r% y- X- x1 f& H. @ t = Left(LTrim(e), 3) A& G/ K4 H' g. K" [( n- _' F. R3 P; d6 ^8 i If t = "GBT" Then 2 l K' `! t, X$ l- f 1 A r! Z' |* V. C. y0 Ne = "GB/T" + Mid(k, 4); Z8 g$ _ N. h4 k. Z& r
; e, c& g1 {2 S, Y B8 D d" hElse% ~7 S# i* x- Y4 A: P( l ; J* M- K: _* u0 t% I- ` e = k 0 y4 T! |" L% K% H0 w0 V ' ?$ r0 @; ~6 ]8 l+ Y: XEnd Ifc2 }' C* W' `( e8 n: A& l
+ G$ H4 k) r0 X4 s# Nb = Mid(c, a + 2)' K3 ] f& X1 J& U8 q. P
; F; ?. |* H/ B- Vt = Right(c, 7) : A# @# S* ]! e* X, G& | / n6 J1 D7 n& [& ?# k2 qIf t = ".SLDPRT" Or t = ".SLDASM" Or t = ".sldprt" Or t = ".sldasm" Then , I: g3 y) u1 `6 D- p ' s" t# z6 Q h# Sj = Len(b) - 7 '消除后缀(区分大小写,即含4种)) p; h# Y; Q5 {5 c/ Q6 q, ?( | 6 T# Q- H% a& y7 N Else1 O( f$ b- s" a# o4 p- k. V0 T; K
. a: L# i5 E) O$ y& sj = Len(b) 7 ^( b5 K" k0 f : a1 a- ~3 U5 f q _/ t; NEnd If2 ~4 F( Q Q+ x/ p . n) N; `% W4 P4 ]/ V( @+ R m = Left(b, j)( k- b# U2 L! K ' x! c: m- L2 {: ] h+ {: W, E2 d End If . u" q, j( w9 n: K, u+ ^4 |4 x* T, ?& f0 o4 s& S0 _ '删除栏 / X: t' L+ p7 R$ v4 M ; k0 i6 B2 u B$ }CustPropMgr.Delete ("Number")2 \- R+ E# t2 v- h; ~5 T& |% O ; V/ s$ s- u+ U$ Q CustPropMgr.Delete ("作者")$ K2 M5 n+ G" x4 u
. t6 E* J* j- h( n fCustPropMgr.Delete ("图样名称")" Y+ R/ O1 \; h* s% v* e: b, O+ g ; m3 ?: X$ K4 r6 X, T: e2 J 8 _: Q0 B. M5 \ y 3 r& }6 q. @$ Z3 S 9 f5 d" I6 u- b7 b4 M' m7 D: ` Y P ; ]: A5 k+ m* U4 |2 w / a$ Q3 u% X- D3 @# N: F '新增$ u- j* f6 h" T0 p ; [4 n7 m% N p% ? y! s CustPropMgr.Add2 "Number", swCustomInfoText, e. I! e: N7 @6 K- H8 n
1 m; Z+ H4 C m, QCustPropMgr.Add2 "作者", swCustomInfoText, "刘腾qq420221716": l$ F4 B+ W8 J% s ! y1 o4 d! h9 T" I9 V9 L CustPropMgr.Add2 "图样名称", swCustomInfoText, m / l- ]* }) |5 V. y" _4 v, z" n - D* K$ p1 d6 Z, G! k2 B ! T3 r' W, c4 \8 n/ }! G 4 P6 {/ w7 ` x8 H; G5 _! t. D6 O0 ?* o; j: u# I5 P: l End Sub! w1 _: r6 e6 ^" G/ t1 k& i$ w/ M / O. }' P* [8 D( P8 |4 b. o) v
|