Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Example Code for auto updating Rev Block and Rev

Status
Not open for further replies.

fcsuper

Mechanical
Apr 20, 2006
2,204
0
0
US
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
 
Replies continue below

Recommended for you

Thanks.
It worked OK, but inserted the info in the wrong columns.
I will look into it more later.

Chris
Systems Analyst, I.S.
SolidWorks 06 4.1/PDMWorks 06
AutoCAD 06
ctopher's home (updated 06-21-06)
 
I used the inputbox lines to define what information to request from the user, and where to put it. At my company, we have a simple rev block with only 4 columns: Rev, Desc, Rev By and Date. Date is automatically entered when a new row is created, so that leaves the need for three inputbox lines in the code. To adjust the location, it's prolly easiest to change the requested info in the inputbox line, and add new inputbox lines. For example, with 5 columns of Rev, Desc, Rev By, Approved By, Date, the inputbox lines would look something like this (including row adding):

' Add Row to Revision Table
RevTable.AddRevision (CheckCurV)
nNumCol = RevTable.ColumnCount - 5
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), "Revision", CheckCurV)

RevTable.Text(nNumRow, nNumCol + 1) = InputBox("Enter the description of the revision." & Chr$(13) & "____________________________________________", "Description", "ECO- ")

RevTable.Text(nNumRow, nNumCol + 2) = InputBox("Enter the revision creator's initials." & Chr$(13) & "____________________________________________", "Rev By", "IP")

RevTable.Text(nNumRow, nNumCol + 3) = InputBox("Enter the revision approver's name." & Chr$(13) & "____________________________________________", "Approved By", "M. LORONO")



Also, the order of how thangs are entered can be changed by playing with the "nNumCol + X" section of the RevTable.Text instruction.
 
I am trying to edit the rev block to work on our drawings. Our rev block is at the bottom left, so when I use the code above, it adds rows in the wrong direction (down instead of up). What part of the code controls this?

ALSO, anyone figure out a way to edit existing revisions? This would be a nice feature so the user wouldnt have to double click the table if they need to edit text.
 
bb007,

I didn't even think to try using this macro for a bottom rev table. You simply need to change your table to point up. I just tried it. Edit Table by right clicking on it, and choose Properties. In the Properties screen, select "Table Format" button. Under "Header", select the icon with the red bar on the bottom, then accept. The macro should work correctly at that point.

About the editing of existing revisions, this macro code would not be good for that. This a simple Inputbox based macro. We'd need to develop a macro with forms that will collect all that data of the rev table and display it in a user friendly window. Any volunteers for this project? :)



Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
 
@fsuper,

My rev tables are setup like that. When I run the macro, a line is added, but the text is added to the line below it (first line above the header). Each time I click the macro, another rev row is added, but the data is added to the same line above the header.
 
bb007,

Ok, I was able to replicate the issue. The basica solution is pretty easy. Delete the lines that define nNumRow, and replace all instances where nNumRow is used with the number 0.

More tweaking may be necessary to the macro to get it to work properly with your particular rev block, but this should be a big step in the right direction.





Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
 
Status
Not open for further replies.
Back
Top