Remove all TitleBlocks and Borders VBA

Remove all TitleBlocks and Borders VBA

sgwilliams
Collaborator Collaborator
3,042 Views
6 Replies
Message 1 of 7

Remove all TitleBlocks and Borders VBA

sgwilliams
Collaborator
Collaborator

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 Sub

 Step 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.

Work Station : Custom built, Liquid Cooled, Asus Pro WS X570-ACE Motherboard; AMD Ryzen 9 3900X 3.8 GHz 12-Core Processor; ASUS TUF Gaming NVIDIA GeForce RTX 3060 V2 OC Edition Video Card; 32 GB CORSAIR Dominator Platinum DDR4-2132 Memory ; Samsung 850 EVO 1TB SSD Drive.
Accepted solutions (1)
3,043 Views
6 Replies
Replies (6)
Message 2 of 7

chandra.shekar.g
Autodesk Support
Autodesk Support

@sgwilliams,

 

Thanks for posting valuable information at Inventor customization forum.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 3 of 7

sgwilliams
Collaborator
Collaborator

@chandra.shekar.g No problem chandra.shekar.g, Thanks for the kind words.

 

 On another note do you know what the red bullhorn is on the right side of my post in the listing? I have never seen that before. See photo below!

red loud speaker.PNG

 

Work Station : Custom built, Liquid Cooled, Asus Pro WS X570-ACE Motherboard; AMD Ryzen 9 3900X 3.8 GHz 12-Core Processor; ASUS TUF Gaming NVIDIA GeForce RTX 3060 V2 OC Edition Video Card; 32 GB CORSAIR Dominator Platinum DDR4-2132 Memory ; Samsung 850 EVO 1TB SSD Drive.
0 Likes
Message 4 of 7

chandra.shekar.g
Autodesk Support
Autodesk Support

@sgwilliams,

 

Bullhorn symbol shows that this post has been escalated to Autodesk team.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 7

sgwilliams
Collaborator
Collaborator
Awesome, thanks for clearing that up.
Work Station : Custom built, Liquid Cooled, Asus Pro WS X570-ACE Motherboard; AMD Ryzen 9 3900X 3.8 GHz 12-Core Processor; ASUS TUF Gaming NVIDIA GeForce RTX 3060 V2 OC Edition Video Card; 32 GB CORSAIR Dominator Platinum DDR4-2132 Memory ; Samsung 850 EVO 1TB SSD Drive.
0 Likes
Message 6 of 7

sgwilliams
Collaborator
Collaborator
Accepted solution

Ok So! After a couple of long coding sessions, I now have the completed tool. I shortened it all up into one macro.  The macro is saved as "AutoSheetUpdates.bas" file and there is also a form that is used as well to allow you to choose the correct border for your sheet if the original is named different than the template data. This is named "SheetRenameForm.frm". Both Files can be found in the "AutoSheetUpdates.zip" file.

 

The macro and the form can be imported from the VBA Editor found on the Tools Tab like so:

 

Select the "ApplicationProject(Default.ibv)" as shown
vba editor1.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Then Hit Ctrl+M or on the file menu choose File>Import as shown for each of the files "AutoSheetUpdates.bas" & "SheetRenameForm.frm" :
vba editor2.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

After you import both files, they should appear in the browser tab as shown:vba editor3.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

This what the macro does is:

  1. remove all borders from every sheet in the ".idw" file.
  2. remove all title blocks from every sheet in the ".idw" file.
  3. remove sketch symbols from every sheet in the ".idw" file.
  4. then it iterates through the model tab browser tree > Drawing Resources> all subdirectories, and deletes everything except for "Default Border"(Inventor will not let you delete this file)
  5. once all items are deleted and the drawing is clean, the macro copies everything from the model tab browser tree > Drawing Resources from the template and pastes it to the file your working on. 
  6. After the drawing resources directory is populated with the new data from your template file, then the macro iterates through the sheet list and looks at the 1st view it see's and determines if it is a component or assembly file. If it is a ".ipt" file then it copies the "component" title block to the sheet or if it is a ".iam" file then it copies the "Assembly" Titleblock to the current sheet. Then it reads the sheet name and looks for a Border name that matches in the drawing resources folder if nothing matches then it brings up the form which shows the current sheet name and allows you to choose a new border in a drop-down combo box list which will then add the chosen border to the current sheet.

This code is new and is not completely proven to be flawless so proceed at your own risk and also you will have to update the template path in the macro to your template location. If you do not have a component or assembly title block then you will have to recode to meet your requirements. Good luck. Hope this helps some of you out there improve your drawing efficiencies...I know it will help ours. If anyone has any questions feel free to give me a shout.

Work Station : Custom built, Liquid Cooled, Asus Pro WS X570-ACE Motherboard; AMD Ryzen 9 3900X 3.8 GHz 12-Core Processor; ASUS TUF Gaming NVIDIA GeForce RTX 3060 V2 OC Edition Video Card; 32 GB CORSAIR Dominator Platinum DDR4-2132 Memory ; Samsung 850 EVO 1TB SSD Drive.
0 Likes
Message 7 of 7

tburtonD9T8B
Contributor
Contributor

Can you upload your form again but the the .frx file as well?

0 Likes