- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Finally started this side project to help our Inventor users be a little more efficient in there daily workload. We have a Drawing Library with over 6,000 component and assembly drawings. OUr company policy to maintain this library is by attrition. While the parts are being manufactured if we find something that needs to be changed we create an Engineering Change Order (ECO) which flags us the next time the part number is added to our production schedule to update the drawing. Some of these items have not been added for many years and are seriously in need of a complete makeover to our current engineering standards. One of the steps in updating our drawings is deleting the Titleblocks and borders from each Sheet in the Drawing file, then Emptying the Drawing Resources folder in the Browser View which has 4 subdirectories, these include:
- Sheet Formats
- Borders
- Title Blocks
- Sketch Symbols
This is a time-consuming process when you update 25 to 30 prints a day. Not to mention all the additional mouse clicks. I created a post in the Inventor Idea forum seen HERE, hoping to get Autodesk to add an auto update feature. But while I patiently wait for the powers that be to accommodate my request I have started to write some macros in VBA to do just this.
So here is what I have so far. In order to accomplish our goal, you must run these in the following order or it won't work.
Step 1:
Open the VBA Editor this can be found in the tools tab on the Inventor ribbon, then create 4 new modules in ApplicationProject(Default.ivb).
Step 2: Paste the following code in the 1st module:
Option Explicit
Sub DeleteAllSheetTB_B() Dim oDoc As DrawingDocument Set oDoc = ThisApplication.ActiveDocument Dim oSheet As Sheet Dim oBorderDefinition As BorderDefinition Dim oTitleBlockDefinition As TitleBlockDefinition For Each oSheet In oDoc.Sheets If Not oSheet.Border Is Nothing Then oSheet.Border.Delete If Not oSheet.TitleBlock Is Nothing Then oSheet.TitleBlock.Delete Next On Error Resume Next For Each oBorderDefinition In oDoc.BorderDefinitions If Not oBorderDefinition.IsDefault Then oBorderDefinition.Delete Next For Each oTitleBlockDefinition In oDoc.TitleBlockDefinitions oTitleBlockDefinition.Delete Next End Sub
Step 3: Paste the following code into the 2nd Module:
Option Explicit
Public Sub EmptyDrawingResources()
Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oPane As BrowserPane
Set oPane = oDoc.BrowserPanes.ActivePane
Dim oDocNode As BrowserNode
Set oDocNode = oPane.TopNode
'------------------------------------------------------------------------
'Identify Model Tab > Browser > Drawing Resourses Folder
Dim oDrawingResourceNode As BrowserNode
Set oDrawingResourceNode = oDocNode.BrowserNodes.Item("Drawing Resources")
'-------------------------------------------------------------------------
'Identify Model Tab > Browser > Drawing Resourses > Sheet Formats Folder, then Loop through the folder and delete all items
Dim oSheetFormatsNode As BrowserNode
Set oSheetFormatsNode = oDrawingResourceNode.BrowserNodes.Item("Sheet Formats")
Dim oSheetFormatNode As BrowserNode
For Each oSheetFormatNode In oSheetFormatsNode.BrowserNodes
oSheetFormatNode.DoSelect
ThisApplication.CommandManager.ControlDefinitions.Item("AppDeleteCmd").Execute
Next
'-------------------------------------------------------------------------
'Identify Model Tab > Browser > Drawing Resourses > Borders Folder, then Loop through the folder and delete all items
Dim oSheetBordersNode As BrowserNode
Set oSheetBordersNode = oDrawingResourceNode.BrowserNodes.Item("Borders")
Dim oSheetBorderNode As BrowserNode
For Each oSheetBorderNode In oSheetBordersNode.BrowserNodes
' Select the node in the browser.
oSheetBorderNode.DoSelect
' Execute the delete command.
ThisApplication.CommandManager.ControlDefinitions.Item("AppDeleteCmd").Execute
Next
'-------------------------------------------------------------------------
'Identify Model Tab > Browser > Drawing Resourses > Title Blocks Folder, then Loop through the folder and delete all items
Dim oSheetTitleBlocksNode As BrowserNode
Set oSheetTitleBlocksNode = oDrawingResourceNode.BrowserNodes.Item("Title Blocks")
Dim oSheetTitleBlockNode As BrowserNode
For Each oSheetTitleBlockNode In oSheetTitleBlocksNode.BrowserNodes
oSheetTitleBlockNode.DoSelect
ThisApplication.CommandManager.ControlDefinitions.Item("AppDeleteCmd").Execute
Next
'-------------------------------------------------------------------------
'Identify Model Tab > Browser > Drawing Resourses > Sketch Symbols Folder, then Loop through the folder and delete all items
Dim oSheetSketchSymbolsNode As BrowserNode
Set oSheetSketchSymbolsNode = oDrawingResourceNode.BrowserNodes.Item("Sketch Symbols")
Dim oSheetSketchSymbolNode As BrowserNode
For Each oSheetSketchSymbolNode In oSheetSketchSymbolsNode.BrowserNodes
oSheetSketchSymbolNode.DoSelect
ThisApplication.CommandManager.ControlDefinitions.Item("AppDeleteCmd").Execute
Next
End SubStep 4: Paste the following code into the 3rd Module:
Option Explicit
Public Sub AppDelay(ai_Count As Long) Dim Start As Long Dim i As Long i = 0 Start = Timer ' Set start time. Do While Timer < Start + ai_Count DoEvents ' Yield to other processes. Loop End Sub
Step 5: Paste the following code into the 4th Module:
Option Explicit Sub DrawingStandardUpdates() DeleteAllSheetTB_B AppDelay (6) EmptyDrawingResources End Sub
The DrawingStandardUpdates Sub is the macro that you will run, this ties all four macros together. The following is a brief description of what each one does.
- DeleteAllSheetsTB_B macro Looks at each sheet in the drawing file and deletes the title block and border. This has to be done before you can remove any of the items in the drawing resources folder.
- EmptyDrawingResources macro removes all items from each of the 4 subdirectories in the Drawing Resources folder.
- AppDelay macro is a timer delay function that is adjusted by typing the number of seconds you would like to delay running the 1st macro to the 3rd. This has to be adjusted to suit your requirements. Mine runs best at about 6 seconds.
This is all I have currently. I will update and add more to the post as I progress so everyone can benefit. This is a big time saver and should be part of the Inventor toolbox for anyone who does a lot of drawings as we do. Good luck and feel free to give feedback.
Solved! Go to Solution.
