iCAx开思网

标题: SOLIDWORKS 宏合并执行的问题,已解决 [打印本页]

作者: arter1983    时间: 2018-11-29 10:29
标题: SOLIDWORKS 宏合并执行的问题,已解决
本帖最后由 arter1983 于 2018-12-4 08:07 编辑

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

作者: arter1983    时间: 2018-11-29 10:30
' ******************************************************************************
' C:\Users\admin\AppData\Local\Temp\swx8144\Macro1.swb - macro recorded on 11/22/18 by arter
' ******************************************************************************
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Dim SelMgr As Object
Dim Feature As Object
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

Sub main() '刪除所有配置属性
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
CurCFGname = Part.GetConfigurationNames
CurCFGnameCount = Part.GetConfigurationCount
For i = 0 To CurCFGnameCount - 1
    Set CusPropMgr = Part.Extension.CustomPropertyManager(CurCFGname(i))
    Vnamearr = CusPropMgr.GetNames
    If Not IsEmpty(Vnamearr) Then
        For Each Vnamearr2 In Vnamearr
            bRet = Part.DeleteCustomInfo2(CurCFGname(i), Vnamearr2)
        Next
    End If
Next
Call 刪除自定义属性
Call partitionTM

End Sub

'~~~ 刪除自定义属性 ~~~
Sub 刪除自定义属性()
'Dim swApp As Object
Dim swModel2 As SldWorks.ModelDoc2
Dim vCustInfoNameArr2 As Variant

Set swApp = Application.SldWorks




Set swModel2 = swApp.ActiveDoc
vCustInfoNameArr2 = swModel2.GetCustomInfoNames
  If Not IsEmpty(vCustInfoNameArr2) Then
     For Each vCustInfoName2 In vCustInfoNameArr2
         bRet = swModel2.DeleteCustomInfo(vCustInfoName2)
      Next
  End If
End Sub

'~~~ partitionTM ~~~
Sub partitionTM() 'partitionTM

'link solidworks
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager
swApp.ActiveDoc.ActiveView.FrameState = 1
'设定变量
c = swApp.ActiveDoc.GetTitle() '零件名
strmat = Chr(34) + Trim("SW-Material" + "@") + c + Chr(34)
'tempvalue = Part.CustomInfo2("", "材料")
blnretval = Part.DeleteCustomInfo2("", "代号")
blnretval = Part.DeleteCustomInfo2("", "名称")
blnretval = Part.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
blnretval = Part.AddCustomInfo3("", "代号", swCustomInfoText, e)
blnretval = Part.AddCustomInfo3("", "名称", swCustomInfoText, m)
blnretval = Part.AddCustomInfo3("", "材料", swCustomInfoText, strmat)
blnretval = Part.AddCustomInfo3("", "单重", swCustomInfoText, " ")
blnretval = Part.AddCustomInfo3("", "备注", swCustomInfoText, " ")

End Sub



作者: arter1983    时间: 2018-11-29 10:35
arter1983 发表于 2018-11-29 10:30
' ******************************************************************************
' C:%users\admin\A ...

上面这个宏,是ryouss坛友帮我编制的,在此对ryouss表示诚挚的谢意。在SW2012,2015,2017皆可以(因其没有SW2018、2014),但在sw2018、SW2014里不可以用,调试也没发现问题。不知何故?非常感谢指点。

作者: 幻想柏拉图    时间: 2020-8-29 17:42
你好楼主!是怎么解决会先后调用其它的宏的方法的,我咋没看懂呢?求指导
作者: left1221    时间: 2020-9-28 10:09
谢谢分享
作者: igxoqve1978    时间: 2020-9-28 19:14
幻想柏拉图 发表于 2020-8-29 17:42
你好楼主!是怎么解决会先后调用其它的宏的方法的,我咋没看懂呢?求指导

把所有宏定义按顺序放一起,在最前面,再把宏代码SUB到END SUB一个宏一个宏的按顺序排就可以了


作者: yanhuozlh    时间: 2022-6-24 21:41
谢谢,正需要




欢迎光临 iCAx开思网 (https://www.icax.org/) Powered by Discuz! X3.3