HI
Simple VBA code to replace title block on the open document to the one from template.
Inventor keeps crashing on oTemplate.Close and I can not figure out why any idea?
Dim odrawdoc As DrawingDocument
Set odrawdoc = ThisApplication.ActiveDocument
If odrawdoc Is Nothing Then
MsgBox "Please Open Inventor Drawing"
closeForm
Else
Dim oTemplate As DrawingDocument
Dim oSourceTitleBlockDef As TitleBlockDefinition
Dim oNewTitleBlockDef As TitleBlockDefinition
Dim oSheet As Sheet
Set oTemplate = ThisApplication.Documents.Open("D:\Vault\Templates\Inventor\Template.idw", False)
Set oSourceTitleBlockDef = oTemplate.ActiveSheet.TitleBlock.Definition
For Each oSheet In odrawdoc.Sheets
oSheet.Activate
Set oNewTitleBlockDef = oSourceTitleBlockDef.CopyTo(odrawdoc, True)
Next
oTemplate.Close
End If
Since you are opening the template 'in the background' or invisibly, you might also be able to use an alternative to Close. You could try using ReleaseReference and Documents.CloseAll(True), like this:
oTemplate.ReleaseReference
ThisApplication.Documents.CloseAll(True)
In that CloseAll method, True means only close all of the 'unreferenced' documents.
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS :light_bulb: or you can Explore My CONTRIBUTIONS
Wesley Crihfield
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.