马上注册,结识高手,享用更多资源,轻松玩转三维网社区。
您需要 登录 才可以下载或查看,没有帐号?注册
x
本帖最后由 jianmuguo 于 2016-11-8 08:31 编辑 h6 U; y7 C$ J& B, J/ i& ?# W
/ t, c# d3 O- K& y0 y3 g/ s' z
执行宏前图号名称没有分离
未执行前的图号名称没有分离1 e- [1 a/ ?: }0 K- r6 w8 m) j
宏按钮设置
9 y7 E/ T% r' h' w$ r" N
关键是宏按钮的新建:打开工具-宏-新建-另存为对话框-自己给起名字-复制填写代码
1 L$ e* @) J; h" i! Z
另存为对话框! f* t/ j& ~: X9 ^) Q
1 i) J8 j7 R& [4 ?. n4 h" O
代码可以复制下面的-最后点保存
% u- ^3 |: m9 Y; B下面是按钮制作
' b$ q- j# X" N B
5 H' @. Z6 p+ H7 ~" s- o. G- r% f! N4 H! \) k9 h
Dim swApp As Object Dim Part As Object Dim SelMgr As Object Dim boolstatus As Boolean Dim longstatus As Long, longwarnings As Long Dim Feature As Object " a0 Z5 _! d0 {' [' H
3 m+ S5 a7 D1 H( z
Dim a As Integer Dim b As String Dim m As String Dim e As String Dim k As String Dim t As String Dim c As String Dim j As Integer Dim strmat As String Dim tempvalue As String
7 b' s# A$ R0 {. x" T3 C/ y
, D/ l; k4 A% R% G! W9 M$ d; S2 |- \; D. h ?- p
Sub main() ! F2 X6 M% q) F& N; f
'link solidworks Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc Set SelMgr = Part.SelectionManager swApp.ActiveDoc.ActiveView.FrameState = 1 " F* F! _) t# u5 r
'设定变量 c = swApp.ActiveDoc.GetTitle() '零件名
" `# m+ Z1 o) ^+ |0 Rstrmat = Chr(34) + Trim("SW-Material" + "@") + c + Chr(34)
6 a& i9 Q) r4 D; Y/ `( o( Zblnretval = Part.DeleteCustomInfo2("", "代号") blnretval = Part.DeleteCustomInfo2("", "名称") blnretval = Part.DeleteCustomInfo2("", "材料")
8 Z0 g6 ?0 T# g8 R3 J/ o+ u q. O+ \3 J) d% p9 x. s
a = InStr(c, " ") - 1 '重点:分隔标识符,这里是一个空格 If a > 0 Then k = Left(c, a) t = Left(LTrim(e), 3) 4 a1 x7 S* Z8 N( b" ]7 O! i
If t = "GBT" Then e = "GB/T" + Mid(k, 4) Else e = k End If # {/ r! l9 E! E0 V2 \2 b
b = Mid(c, a + 2) t = Right(c, 7) If t = ".SLDPRT" Or t = ".SLDASM" Then j = Len(b) - 7 Else j = Len(b) End If m = Left(b, j) End If * K3 y/ x% z( O* A
blnretval = Part.AddCustomInfo3("", "代号", swCustomInfoText, e) '代号 blnretval = Part.AddCustomInfo3("", "名称", swCustomInfoText, m) '名称 blnretval = Part.AddCustomInfo3("", "表面处理", swCustomInfoText, " ")
$ a, U( T; x2 g" HEnd Sub
0 C8 w) K2 f! e2 h, |& k. `5 R, Y8 h) O, U* X' y
8 d0 V- V! q- ?* J
$ r8 E# u' i# n4 T; L9 i
- u3 H m5 R5 g& ^& h9 b7 n5 v- Y+ t5 G* `$ E
执行宏后图号分离
( d& U$ c: i) q) f0 D- z3 C点击按钮,执行后得到的结果。后续出工程图调用时使用。
/ C1 M9 w! z2 _, j' R- X! q9 [% I( i& h2 H1 b
5 F0 F5 l3 S! |( l
% X$ t* v# }1 g- H9 M' r |