Message 1 of 11
VBA Replace title block definitions in drawing from template file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have some code to replace the current title block with a title block from a template file. I just don't like how it adds a new title block definition named "copy of titleblock". I'd like to delete or replace the current title block definition so only the newly added one is listed.
Sub test()
Dim odrawdoc As DrawingDocument
Set odrawdoc = ThisApplication.ActiveDocument
If (odrawdoc.DocumentType <> kDrawingDocumentObject) Then Exit Sub
Dim oTemplate As DrawingDocument
Dim oSourceTitleBlockDef As TitleBlockDefinition
Dim oNewTitleBlockDef As TitleBlockDefinition
Dim oSheet As Sheet
Set oTemplate = ThisApplication.Documents.Open(ThisApplication.FileOptions.TemplatesPath & "template.idw", False)
Set oSourceTitleBlockDef = oTemplate.ActiveSheet.TitleBlock.Definition
Set oNewTitleBlockDef = oSourceTitleBlockDef.CopyTo(odrawdoc)
' Iterate through the sheets.
For Each oSheet In odrawdoc.Sheets
oSheet.Activate
oSheet.TitleBlock.Delete
Call oSheet.AddTitleBlock(oNewTitleBlockDef)
Next
oTemplate.Close
End SubI'm just being picky at this point, but I don't want a buildup of title block definitions. We reuse drawings all the time which is why a simple method of updating a title block would be nice. I can just imagine in some years time after a title block update or two there are 20 "copy of copy of copy of .................. titleblock" listed in a drawing file.
Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
Userscript to edit forum links to jump to first unread post
Jump To First Post Userscript
pball's Autodesk Forum Style
Userscript to edit forum links to jump to first unread post
Jump To First Post Userscript