Delete linked image file from title block

<?xml encoding=”UTF-8″>By Adam Nagy

If an image file was inserted into a drawing’s title block with the “LINK” option and the file got moved or deleted, then when you try to edit the title block definition you get this dialog:

Referencetest

You can remove those images programmatically as well. Here is a VBA code that does this:

Sub DeleteSketchImage()
Dim dwg As DrawingDocument
Set dwg = ThisApplication.ActiveDocument
Dim s As Sheet
Set s = dwg.ActiveSheet
Dim tbd As TitleBlockDefinition
Set tbd = dwg.TitleBlockDefinitions("ANSI - Large")
' This is to avoid any dialog popping up
ThisApplication.SilentOperation = True
Dim sk As DrawingSketch
Call tbd.Edit(sk)
Dim si As SketchImage
Set si = sk.SketchImages(1)
If si.LinkedToFile Then
Dim fso As Object
Set fso = ThisApplication.FileManager.FileSystemObject
If Not fso.FileExists(si.Name) Then
Call si.Delete
End If
End If
Call tbd.ExitEdit(True)
ThisApplication.SilentOperation = False
End Sub

Comments

3 responses to “Delete linked image file from title block”

  1. I just want to say a big Thank you to you and your colleagues for the excellent posts! Without them my Inventor Toolbox would not exist!
    https://docs.google.com/document/d/1qJ5ns8pj9hOUp_SQnupx8S4Q2Crjl5p6ioEWMl0Nq68/pub
    Jürgen

  2. Modification to edit the active Title Block
    […]
    Dim skName As String
    skName = s.TitleBlock.Name
    Dim tbd As TitleBlockDefinition
    Set tbd = dwg.TitleBlockDefinitions(skName)
    […]

  3. We’re glad you like the blog :)
    And thanks for the code update.

Leave a Reply to JürgenCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading