arter 发表于 2018-11-22 17:21:43

SOLIDWORKS 宏合并执行的问题

是这样的,想做一个宏,通过这个宏,会先后调用其它的宏,请问如何编写?非常感谢。
宏的名称分别是:
删除所有配置属性.swp
删除自定义属性.swp
partitionTM.swp


yjyeming 发表于 2018-11-30 13:46:02

Sub main()

Dim swApp As SldWorks.SldWorks
Dim swModel2 As SldWorks.ModelDoc2
Dim SelMgr As SldWorks.SelectionMgr
Dim vCustInfoNameArr2 As Variant
Dim vCustInfoName2 As Variant
Dim CurCFGname As Variant
Dim CurCFGnameCount As Integer
Dim Vnamearr As Variant
Dim CusPropMgr As CustomPropertyManager
Dim bRet As Boolean
Dim Vnamearr2 As Variant
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
Set swApp = Application.SldWorks
Set swModel2 = swApp.ActiveDoc
Set SelMgr = swModel2.SelectionManager
swApp.ActiveDoc.ActiveView.FrameState = 1
vCustInfoNameArr2 = swModel2.GetCustomInfoNames
If Not IsEmpty(vCustInfoNameArr2) Then
   For Each vCustInfoName2 In vCustInfoNameArr2
         bRet = swModel2.DeleteCustomInfo(vCustInfoName2)
      Next
End If
CurCFGname = swModel2.GetConfigurationNames
CurCFGnameCount = swModel2.GetConfigurationCount
For i = 0 To CurCFGnameCount - 1
    Set CusPropMgr = swModel2.Extension.CustomPropertyManager(CurCFGname(i))
    Vnamearr = CusPropMgr.GetNames
    If Not IsEmpty(Vnamearr) Then
      For Each Vnamearr2 In Vnamearr
            bRet = swModel2.DeleteCustomInfo2(CurCFGname(i), Vnamearr2)
      Next
    End If
Next
c = swApp.ActiveDoc.GetTitle()
strmat = Chr(34) + Trim("SW-Material" + "@") + c + Chr(34)
bRet = swModel2.DeleteCustomInfo2("", "代号")
bRet = swModel2.DeleteCustomInfo2("", "名称")
bRet = swModel2.DeleteCustomInfo2("", "材料")
a = InStr(c, " ") - 1
If a > 0 Then
    k = Left(c, a)
    t = Left(LTrim(e), 3)
    If t = "GBT" Then
      e = "GB/T" + Mid(k, 4)
    Else
      e = k
    End If

    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
bRet = swModel2.AddCustomInfo3("", "代号", swCustomInfoText, e)
bRet = swModel2.AddCustomInfo3("", "名称", swCustomInfoText, m)
bRet = swModel2.AddCustomInfo3("", "材料", swCustomInfoText, strmat)
bRet = swModel2.AddCustomInfo3("", "单重", swCustomInfoText, " ")
bRet = swModel2.AddCustomInfo3("", "备注", swCustomInfoText, " ")

End Sub

arter 发表于 2018-11-24 15:10:30

上面提到的,就是想把附件压缩包里的三个宏联合执行。

苏战鹏 发表于 2018-11-25 09:28:24

把三个宏文件的程序合并到一起不就行了吗!

super 发表于 2018-11-25 16:33:44

是的,合并在一起,然后做几个按钮,通过按钮执行不同宏命令

arter 发表于 2018-11-26 15:25:00

苏战鹏 发表于 2018-11-25 09:28
把三个宏文件的程序合并到一起不就行了吗!

关键是不知道如何合并啊,我只会录制简单的宏。
我在桌面上设置了这三个宏各自的按钮,然后在录制一个新宏,这个新宏的内容就是连续点击这三个宏按钮。这样录制出来的宏不能用。

arter 发表于 2018-11-26 15:26:39

super 发表于 2018-11-25 16:33
是的,合并在一起,然后做几个按钮,通过按钮执行不同宏命令

我希望的是执行一个按钮,结果等于执行了这三个宏。

arter 发表于 2018-11-28 13:52:24

哪位高人能解决此问题啊?非常感谢。

arter 发表于 2018-11-30 14:34:16

yjyeming 发表于 2018-11-30 13:46
Sub main()

Dim swApp As SldWorks.SldWorks


高手,真是高手!非常感谢.

vincent3166 发表于 2018-12-5 09:42:07

这些功能,在ICTBox V3都已经有现成的了

http://www.ict.com.cn/dingzhi/3.htm

SW属性功能。
页: [1] 2
查看完整版本: SOLIDWORKS 宏合并执行的问题