PDA

View Full Version : Remove Raster Image- VBA Code



habeebpm
2008-10-06, 07:10 AM
Hi Gurus,

Kindly help with VBA code for removing a raster image from a drawing

Is there any reverse for ModelSpace.Addimage method?

Please Help!!!!!!!!!!!

fixo
2008-10-06, 10:08 AM
Try this one



Option Explicit

Sub DeleteImages()
Dim oEnt As AcadEntity
Dim oDict As AcadDictionary
Set oDict = ThisDrawing.Dictionaries("ACAD_IMAGE_DICT")

If oDict.Count < 0 Then
MsgBox "No image definitions in this database."
Exit Sub
Else
MsgBox "There are " & oDict.Count & "image definitions"

Dim oSset As AcadSelectionSet
Dim ftype(0) As Integer
Dim fdata(0) As Variant
Dim dxfCode As Variant
Dim dxfValue As Variant
ftype(0) = 0: fdata(0) = "IMAGE"
dxfCode = ftype
dxfValue = fdata

With ThisDrawing.SelectionSets
While .Count > 0
.Item(0).Delete
Wend
Set oSset = .Add("$IMAGE$")
End With

oSset.SelectOnScreen dxfCode, dxfValue


If oSset.Count > 0 Then

Dim oImage As AcadRasterImage
Dim oImageDef As Object
Dim imgName As String
Dim cnt As Integer
For cnt = oSset.Count - 1 To 0 Step -1
Set oEnt = oSset.Item(cnt)
Set oImage = oEnt
For Each oImageDef In oDict
imgName = oDict.GetName(oImageDef)
If imgName = oImage.Name Then
oImage.Delete
oImageDef.Delete
End If
Next

Next
Else
MsgBox "No images inserted."
Exit Sub
End If
End If

oSset.Delete
Set oSset = Nothing
End Sub


~'J'~

habeebpm
2008-10-08, 02:07 AM
Thank u soooo much..

fixo
2008-10-08, 06:18 AM
You're welcome
Happy computing :)

~'J'~