下面是分离到配置(备注:间隔符同样是空格号,并可以根据自己需求编辑) 8 {) R- b$ ^+ k5 n0 q& h' ^" g# j& i. Y. _- @1 A '定义sw# v9 Q/ M2 n4 S; _5 |: s 4 q) V C W2 m, D
8 S. L5 v9 [ L+ ]+ j" V/ }6 |7 c! @3 H3 f1 _9 r. k+ A Dim a As Integer " x7 e" Y/ w6 `/ \ 6 E9 W( U) m4 V- h9 ]Dim b As String# C0 p8 c! J5 ~$ v
! L- e; C, f& i4 |3 K9 l3 CDim m As String4 p s6 P/ z6 b3 d; C
5 s- V* `3 a, e/ kDim e As String % U6 v F' b( R) r' N; m5 q2 J* Z1 l2 ^) W# ` Dim k As String4 `- \/ ]9 u% Y$ ^7 M ; h/ p+ ?, P" I% Q3 g# |5 |5 A6 _ Dim t As String ) U8 N* X+ k; s6 ` % A6 A2 _$ q7 Z. K) y2 o3 }& D8 L% bDim c As String ; q/ E# k' S' r u; S3 Y; u' b! t, F0 |9 F( h) x# g Dim j As Integer 1 r+ _. x* f0 m' n, \ + h. z, z8 h* C# q; N3 I: PDim strmat As String5 c L: W: w+ k+ m4 `3 z8 {5 X * A. a, R" A! k1 I( `9 N+ v* W4 [ Dim tempvalue As String: ^7 T F' {% {) e+ c U ! V6 |3 p3 N, j Dim Part As Object ' L, }7 ~5 U$ W" D3 y u9 Q+ w: K2 W* |/ l5 S' _Dim swApp As SldWorks.SldWorks^- h: j3 m/ {. b W u$ P! u2 x! B% r) d Dim swModelDoc As SldWorks.ModelDoc2( ]% Z/ F/ h3 s r" G% E' i& [' c% W* N Dim swConfig As SldWorks.Configuration ; R5 W# Q; P& |2 ~: r5 t2 B; O+ Z8 A1 G5 y, y, K ~% ` Dim CustPropMgr As SldWorks.CustomPropertyManager( V4 L; s7 I% ^3 j; k5 p 2 k* v) \8 i8 K5 x6 }. ?, z3 ` Dim swModel As SldWorks.ModelDoc2 9 m5 b( M: }: o! v m2 n+ h: ~' V7 z& R+ G * O( k" q7 ?$ a" _8 P7 X% D' a: k
$ U$ n0 H5 G' C1 Y, @' vSub main()8 H" Y3 g- }6 y! J# I. a* x; y
! T5 x% J. k1 a2 wSet swApp = Application.SldWorks3 j2 f* e G4 b2 _2 s+ b
4 q- p& u; d9 L7 s* Y+ }; a% T OSet swModelDoc = swApp.ActiveDoc . V! A. K% Z/ Z3 K; g g4 p( x) q" R4 |) h, Z$ g Set swConfig = swModelDoc.ConfigurationManager.ActiveConfiguration+ x$ R0 \+ j0 P# D) E+ h
4 I7 N5 a, l0 I! V0 kSet swModel = swApp.ActiveDoc- i; F% \6 \, y& S% z5 T9 e V
9 N0 u/ g, I3 TSet CustPropMgr = swModel.Extension.CustomPropertyManager 4 w. f! z1 {" y8 ~7 k$ k! L8 m, U (swModel.ConfigurationManager.ActiveConfiguration.Name) '配置特定延伸) X- \' f# O) X " Q7 z' r7 J4 ~5 t5 s
5 Y7 Y% {9 q1 p* d. W7 S: m2 ] Z- k) Q* E) j4 _1 \% }) r: S0 B '设定变量 1 ]* n8 q4 n- U0 t $ {- \# b# I5 O) I/ J$ wc = swApp.ActiveDoc.GetTitle() '零件名 m X" E O% b% y1 j3 H# q # N6 f$ [% M6 F2 |strmat = Chr(34) + Trim("SW-Material" + "@") + c + Chr(34) - @( m' X- q) x/ ^ U & U4 {: j2 z* K; Oa = InStr(c, " ") - 1 '重点:分隔标识符,这里是一个空格,也可换成其他符号 l( j+ U1 b1 J* h0 V % C" T' D* w5 m4 I5 R% `If a > 0 Then% l: o0 T) I+ o/ E) K ; Y1 {! _' f% a" b1 Y) X k = Left(c, a) - o) N! s- @. ^" h1 J+ \ & q9 Y% y+ G. E: L; gt = Left(LTrim(e), 3) # ~0 s8 L9 l; L& F, N- o 0 g, V! m/ |! q* L1 r" ]0 C; vIf t = "GBT" Then d, J/ h- @+ m % E9 @" t' H1 j; ie = "GB/T" + Mid(k, 4) & z2 z& o2 t. a0 P- I4 V* |1 x6 _9 r Else" ~, X8 d9 n( T8 x! j* M ) d& [* F5 `6 d9 d: i6 ^& A% D e = k ; R+ l* g0 {$ v) G: L9 g+ s% D. q% | End If * l. I/ k% Y {! N * S+ H5 m) {4 C) V4 wb = Mid(c, a + 2): r, _$ ?* L ~3 G2 a/ G% e; v ! L" o5 V+ B4 a1 Q( e t = Right(c, 7) 0 f5 f3 `: L, g/ B: Q3 y - V. ]1 w5 c' E% t3 j/ cIf t = ".SLDPRT" Or t = ".SLDASM" Or t = ".sldprt" Or t = ".sldasm" Then! S3 W! b/ `. ~7 X3 _, f . P6 u" L/ j5 y" p2 `: T# N j = Len(b) - 7 '消除后缀(区分大小写,即含4种)- U- d' @* O7 x, Z( ]: ?/ p6 m
! {7 ^. q- I! q: \, yElse4 H/ d/ S; n9 i2 e# x+ y& h # k! G7 A2 n) L( s j = Len(b)% [1 g6 ^* o0 S# K* o
/ l' q9 T- R$ A& }. G% F c# ~End If, y2 `, D# _3 t; I# z. |' _
$ S4 t5 d3 J* h0 b1 Em = Left(b, j)9 y. w0 G i2 w6 J8 Q
S( E7 u/ N- ~7 o# {2 G' [& IEnd If1 u2 ^% L* M) z' W 4 o+ A9 k& Y4 T5 D: X& e/ I; N '删除栏$ G' S) `- _1 j
* _2 n( w4 a9 A" z1 Q' @CustPropMgr.Delete ("Number"). }* t1 E& |# J! a ( T$ R/ l# n* Q+ H4 r5 ~ CustPropMgr.Delete ("作者")' D* y4 c, s" ^) M$ h' W9 X; t
; [! N" c, [' X2 p8 p) nCustPropMgr.Delete ("图样名称") , q/ V4 Z7 m. l3 R+ b" w" R2 ]7 p$ G9 b( [0 F8 h
1 S- ^0 k: S5 \1 e' H! i 7 b# _' k7 s( R9 U, V . {1 j& e% T$ m" c6 N: K8 Y 6 X- \4 v8 P/ W, u9 b! v! z6 y% ? 4 D+ m/ l. A; ?1 d'新增 8 ?2 B) t2 y& `" }5 x3 o. H* ` ! P i2 a! J; @CustPropMgr.Add2 "Number", swCustomInfoText, e . a+ O* t; f9 `1 E5 q+ I1 C 7 J/ x9 v0 g% t, a. D" {CustPropMgr.Add2 "作者", swCustomInfoText, "刘腾qq420221716" : ]- e: Q2 i) R. h0 n7 T; e/ O% }, t/ s9 l1 E( K' h+ F CustPropMgr.Add2 "图样名称", swCustomInfoText, m6 b+ U6 u0 X- F) Q. z5 C
0 {$ I" d4 b! ?" B) | 3 ?" \" C) c6 O0 P3 B5 d6 l . _2 N8 D6 \9 h, M$ [6 H" ? K! u 7 P8 q. u P2 \. L7 X$ zEnd Sub ( B" H4 E" o# }5 n5 o 9 \1 \ s/ e' R. ~. ^# \( K p" [; X |