fcsuper
Mechanical
- Apr 20, 2006
- 2,204
I'm offering this here as a gift to this message board, because the board is extremely helpful to me and I wanna give back! I've used some "distribute and modify freely" code from NJ Consulting ( to create this little macro that automatically updates the Revision Block and Revision custom property at the same time. I feel its a good macro for the VB novices out there, like me.
With very little (and hopefully obvious) modifications, any novice can use this macro in their own systems. (Experienced programmers are welcome to suggest quicker alternatives or improvements, of course). This macro assumes you are using custom property "Current Revision" to hold the revision value, and that this property is linked to a text annotation in the title block of the drawing.
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Public CheckCurV As String
Dim RevTable As Object
Dim CurrentRevision As String
Sub MAIN()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
' Error handler for no document loaded
If Part Is Nothing Then MsgBox "No drawing loaded!", vbCritical: End
' Error handler for document not being a drawing
If Part.GetType <> 3 Then swApp.SendMsgToUser "Current document is not a drawing.": End
' Get Current Revision
CheckCurV = Part.CustomInfo2("", "Current Revision")
' Get Revision Table
Set RevTable = Part.GetCurrentSheet.RevisionTable
If RevTable Is Nothing Then MsgBox "No revision table is available!", vbExclamation: End
' Add Row to Revision Table
RevTable.AddRevision (CheckCurV)
nNumCol = RevTable.ColumnCount - 4
nNumRow = RevTable.RowCount - 1
' Interface to add values to new row on the Revision Table
RevTable.Text(nNumRow, nNumCol) = InputBox("Enter the Revision number or letter." & Chr$(13) & Chr$(13) & "| *REV* |Description|Rev By|Date|" & Chr$(13) & "____________________________________________" & Chr$(13), "Revision", CheckCurV)
RevTable.Text(nNumRow, nNumCol + 1) = InputBox("Enter the description of the revision." & Chr$(13) & Chr$(13) & "|Rev| *DESCRIPTION* |Rev By|Date|" & Chr$(13) & "____________________________________________", "Description", "ECO- ")
RevTable.Text(nNumRow, nNumCol + 2) = InputBox("Enter the revision creator's initials." & Chr$(13) & Chr$(13) & "|Rev|Description| *REV BY* |Date|" & Chr$(13) & "____________________________________________", "Rev By", "IP")
' Apply new value for Current Revision
Part.CustomInfo2("", "Current Revision") = RevTable.Text(nNumRow, nNumCol)
' Force Rebuild
boolstatus = Part.ForceRebuild3(False)
End Sub
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Public CheckCurV As String
Dim RevTable As Object
Dim CurrentRevision As String
Sub MAIN()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
' Error handler for no document loaded
If Part Is Nothing Then MsgBox "No drawing loaded!", vbCritical: End
' Error handler for document not being a drawing
If Part.GetType <> 3 Then swApp.SendMsgToUser "Current document is not a drawing.": End
' Get Current Revision
CheckCurV = Part.CustomInfo2("", "Current Revision")
' Get Revision Table
Set RevTable = Part.GetCurrentSheet.RevisionTable
If RevTable Is Nothing Then MsgBox "No revision table is available!", vbExclamation: End
' Add Row to Revision Table
RevTable.AddRevision (CheckCurV)
nNumCol = RevTable.ColumnCount - 4
nNumRow = RevTable.RowCount - 1
' Interface to add values to new row on the Revision Table
RevTable.Text(nNumRow, nNumCol) = InputBox("Enter the Revision number or letter." & Chr$(13) & Chr$(13) & "| *REV* |Description|Rev By|Date|" & Chr$(13) & "____________________________________________" & Chr$(13), "Revision", CheckCurV)
RevTable.Text(nNumRow, nNumCol + 1) = InputBox("Enter the description of the revision." & Chr$(13) & Chr$(13) & "|Rev| *DESCRIPTION* |Rev By|Date|" & Chr$(13) & "____________________________________________", "Description", "ECO- ")
RevTable.Text(nNumRow, nNumCol + 2) = InputBox("Enter the revision creator's initials." & Chr$(13) & Chr$(13) & "|Rev|Description| *REV BY* |Date|" & Chr$(13) & "____________________________________________", "Rev By", "IP")
' Apply new value for Current Revision
Part.CustomInfo2("", "Current Revision") = RevTable.Text(nNumRow, nNumCol)
' Force Rebuild
boolstatus = Part.ForceRebuild3(False)
End Sub