|
楼主 |
发表于 2021-1-5 14:38:45
|
显示全部楼层
加了条语句,已经搞定了。谢谢大家的帮助。3 Q3 `7 ~! y5 q5 v) k N$ u7 q
'设定变量
8 T/ \9 u. r, L1 u. xc = swApp.ActiveDoc.GetTitle() '零件名
9 N8 a/ k. B# D, vIf Asc(c) > 0 Then
- i, o; j9 o# \% {% @
! K) g6 A. u+ F2 ?( kstrmat = Chr(34) + Trim("SW-Material" + "@") + c + Chr(34)
0 C$ v+ q+ P4 O% q; l, H! O' v" S3 kblnretval = Part.DeleteCustomInfo2("", "代号")
" u1 L/ m+ J1 n4 t( A% }0 @blnretval = Part.DeleteCustomInfo2("", "名称")
8 w2 b5 U! l# Q: t4 {8 ua = InStr(c, " ") - 1 '重点:分隔标识符,这里是一个空格
( _. |2 J2 K/ S, g) G# PIf a > 0 Then! N& {! ~2 C3 f3 H3 Q, F9 A
k = Left(c, a)
# ]8 G6 ~+ q, i4 }! @5 O t = Left(LTrim(e), 3)8 h/ x7 k9 H+ U) p) m. |! n% H4 Q8 m
If t = "GBT" Then6 H8 A! O7 z3 I3 Y% V& f
e = "GB/T" + Mid(k, 4)$ b& R( W4 S7 @/ B7 V% W
Else( ~ S% b" `2 h+ ^" R3 u2 t* k
e = k
7 V) u3 C* q6 z& D. y6 ? End If2 m" z9 w' l& j; R% t: E, w. d9 s
b = Mid(c, a + 2)
' y+ J* x+ Z* @: d t = Right(c, 7); i& G x1 g2 x, ~1 @/ \" Y. x
If t = ".SLDPRT" Or t = ".SLDASM" Or t = ".sldprt" Or t = ".sldasm" Then. T7 F5 y( _0 l% Y$ i
j = Len(b) - 7 '消除后缀(区分大小写共4种)
; ]1 }0 _6 `% t1 M( {5 f7 J, [ Else
9 W% r4 }9 ?8 f+ f j = Len(b)
7 Y9 _3 D. M: j8 l" f2 F: I End If [0 M6 e* ?- S: U0 i/ m! t. x
m = Left(b, j)
" x4 m+ \9 A, s2 ?$ w* c- I, fEnd If8 I* d/ t" O1 y& y! A2 ?8 ^1 A0 C- a
blnretval = Part.AddCustomInfo3("", "代号", swCustomInfoText, e) '代号
& V, K: L9 r# W9 `" B! d% A0 M: |blnretval = Part.AddCustomInfo3("", "名称", swCustomInfoText, m) '名称
( i/ e; U C/ \4 l: B'blnretval = Part.AddCustomInfo3("", "图号", swCustomInfoText, e) '图号+ j6 c( X3 @/ h/ b
End If! P1 D; |+ i! }9 g1 R: {& V& Q
|
|