Updating Revision Table with VBA

Updating Revision Table with VBA

eric.frissell26WKQ
Advocate Advocate
1,052 Views
6 Replies
Message 1 of 7

Updating Revision Table with VBA

eric.frissell26WKQ
Advocate
Advocate

Hi, my company is switching drawing templates and I've wrote a script that updates our drawing template but I'm having trouble with getting the revision table to work right.  I've seen some code that uses RevisionTableStyles.Item and claims to work but I'm having an issue with mine and was wondering if anyone had any suggestions.  The error I am getting is improper use of item, however I'm not sure what would be a better method.



Public Sub CopyDrawingResources()
If ThisApplication.ActiveDocument Is Nothing Then
Exit Sub
Else
If ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then
Dim InvDoc As DrawingDocument
Set InvDoc = ThisApplication.ActiveDocument
Else
Exit Sub
End If
End If


Dim SourceDoc As DrawingDocument
Dim RevTab As RevisionTable
Dim RevTabStyle As RevisionTableStyle

Set SourceDoc = ThisApplication.Documents.Open("my drawing template", False)

On Error Resume Next
For Each Item In InvDoc.SheetFormats
If Item.IsRferenced = False Then Item.Delete
Next
For Each Item In InvDoc.BorderDefinitions
If Item.IsReferenced = False Then Item.Delete
Next
For Each Item In InvDoc.TitleBlockDefinitions
If Item.IsReferenced = False Then Item.Delete
Next
For Each Item In InvDoc.SketchedSymbolDefinitions
If Item.IsReferenced = False Then Item.Delete
Next

For Each Item In SourceDoc.BorderDefinitions
Set TargetBorder = Item.CopyTo(InvDoc, True)
Next
For Each Item In SourceDoc.TitleBlockDefinitions
Set TargetHeader = Item.CopyTo(InvDoc, True)
Next
For Each Item In SourceDoc.SketchedSymbolDefinitions
Set TargetSymbol = Item.CopyTo(InvDoc, True)
Next
For Each Item In SourceDoc.SheetFormats
'Caution: this creates a new copy of the TitleBlock used for EACH SheetFormat,
'regardless if the TitleBlockDefinition already exists or not!!!
Set TargetSheet = Item.CopyTo(InvDoc)
Next
On Error GoTo 0

SourceDoc.ReleaseReference
SourceDoc.Close (True)
Set SourceDoc = Nothing

'Set RevTab = RevTab.Style

'InvDoc.StylesManager.RevisionTableStyles.Item.Delete
InvDoc.StylesManager.ActiveStandardStyle.UpdateFromGlobal
InvDoc.StylesManager.RevisionTableStyles.Item ("My Revision Table")

InvDoc.Update


End Sub

 

0 Likes
1,053 Views
6 Replies
Replies (6)
Message 2 of 7

DRoam
Mentor
Mentor

I suspect it's because of this line:

 

InvDoc.StylesManager.RevisionTableStyles.Item("My Revision Table")

 

When you access a property, you must either assign it to a variable, like this:

 

Set myStyle = InvDoc.StylesManager.RevisionTableStyles.Item("My Revision Table")

 

Or use one of its methods, like this:

 

InvDoc.StylesManager.RevisionTableStyles.Item("My Revision Table").UpdateFromGlobal()

 

0 Likes
Message 3 of 7

eric.frissell26WKQ
Advocate
Advocate

Crazy, was just looking at this post when you responded.  Anyways though...

 

The original Revblock is the By Standard rev block and the sheet that the drawing is on does not have the "My Revision Table."  Is it the case that I'll need to update the global style manager to see the new "My Revision Table", and once that's updated I can set it with myStyle = ......?  Or will using the methods update the global style manager, then change it to "My Revision Table" without it saying "My Revision Table" does not exist?

 

Edit: Just wanted to let you know the line you suspected was right, it errored when I added the line and didn't understand why

0 Likes
Message 4 of 7

eric.frissell26WKQ
Advocate
Advocate

So tried using the property method and added Dim myStyle as StylesManager just under Set SourceDoc = .... and then I set the variable at the bottom under InvDoc.StylesManager.ActiveStandards.... and getting a type mismatch error

 

Is the variable dimensioned wrong up at the top?  From what I've seen that dimension seems to work

0 Likes
Message 5 of 7

DRoam
Mentor
Mentor

Can you clarify what you're wanting to do with the revision tables/revision table styles? Are you wanting to set every revision table in your drawing to use the "My Revision Table" style?

0 Likes
Message 6 of 7

DRoam
Mentor
Mentor

Also, is there a specific reason you're using VBA rather than iLogic? Could you use iLogic instead? iLogic is much more friendly to work with and opens up some additional possibilities for us.

0 Likes
Message 7 of 7

eric.frissell26WKQ
Advocate
Advocate

So what I'm trying to do is update our drawing template.  Titleblock had changed, sheet format changed, and revision table changed.  I'm using this macro to copy everything over to the new drawing by having it sit as a button on the User Commands ribbon.  The hope is to get the macro to change the revision table from "By Standard" to a new rev table with a new style which the rev table is only on sheet 1.  It does not need to copy the revision table information, just change the table.

 

I didn't use iLogic because I'm more familiar with VBA and am able to get more support (since VBA is used to a much larger degree as many other programs can use it).  Secondly I figured if there was an iLogic command for it there would also be a VBA command, and not knowing much about iLogic or Add-Ins I wasn't sure if I could add a button to the ribbon, which is much faster than navigating to the iLogic tab as the button is right there when the drawing is open.  The reason I want to make the change is because I run the macro, then go to the annotate tab and change to the new revision table while everything else updates automatically.  It seems small but we have 6 people doing this and 10 seconds that takes becomes a minute, which becomes nearly an hour of combined labor by the end of the workday for what looks like it should be 2 lines of code.

0 Likes