|
经典图书 @wetiuer @Allate 版主
网上找到的宏,有窗体,可不可以改写成没有窗体直接运行的
'Registry Settings import
Public Sub UserForm_Initialize()
Dim stChecked1 As String
stChecked1 = GetSetting("Solidworks", " ropertyRaf", "Description")
If stChecked1 = "true" Then
CheckBox1.Value = True
End If
Dim stChecked2 As String
stChecked2 = GetSetting("Solidworks", " ropertyRaf", "Revision")
If stChecked2 = "true" Then
CheckBox2.Value = True
End If
End Sub
'CheckBox Description
Public Sub CheckBox1_Click()
If CheckBox1.Value = True Then
Call SaveSetting("Solidworks", " ropertyRaf", "Description", "true")
Else
Call SaveSetting("Solidworks", " ropertyRaf", "Description", "false")
End If
End Sub
'Checkbox Revision
Private Sub CheckBox2_Click()
If CheckBox2.Value = True Then
Call SaveSetting("Solidworks", " ropertyRaf", "Revision", "true")
Else
Call SaveSetting("Solidworks", " ropertyRaf", "Revision", "false")
End If
End Sub
'Copy Button
Private Sub Copy_click()
Dim swApp As SldWorks.SldWorks
Dim oDwg As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim sName As String
Dim sValue As String
Dim lType As Long
Dim bRetVal As Boolean
Dim strFilename As String
Dim strDoRebuild As String
On Error Resume Next
Set swApp = CreateObject("SldWorks.Application")
Set oDwg = swApp.ActiveDoc
If (oDwg Is Nothing) Or (oDwg.GetType <> swDocDRAWING) Then
MsgBox "Open a drawing first!.", vbCritical, "SOLIDWORKS"
Unload PROPERTY
Exit Sub
End If
Set swView = oDwg.GetFirstView
Set swView = swView.GetNextView
strFilename = swView.ReferencedDocument.GetPathName
If (swView Is Nothing) Then
MsgBox " lace a view first!.", vbCritical, "SOLIDWORKS"
Unload PROPERTY
Exit Sub
End If
If CheckBox1.Value = True Then
sName = "Description"
sValue = swView.ReferencedDocument.CustomInfo2("", sName)
lType = swView.ReferencedDocument.GetCustomInfoType3("", sName)
bRetVal = oDwg.DeleteCustomInfo2("", sName)
bRetVal = oDwg.AddCustomInfo3("", sName, lType, sValue)
Else
End If
If CheckBox2.Value = True Then
sName = "Revision"
sValue = swView.ReferencedDocument.CustomInfo2("", sName)
lType = swView.ReferencedDocument.GetCustomInfoType3("", sName)
bRetVal = oDwg.DeleteCustomInfo2("", sName)
bRetVal = oDwg.AddCustomInfo3("", sName, lType, sValue)
Else
End If
oDwg.ForceRebuild
strDoRebuild = MsgBox("Values copy successfully ", vbOKOnly)
Set swView = Nothing
Set oDwg = Nothing
Set swApp = Nothing
Unload PROPERTY
End Sub
|
|