I am using Inventor 2024.1.1 and I have the following iLogic code, in which I am trying to delete certain images from a drawing border. I have confirmed that the loop is finding the correct images that I am trying to delete (I did this by adding msgbox(sketchImg.Name) inside the If statement in the For loop, and it does show the correct names of the images I want to delete). However, the images are not actually getting deleted. The program is also not erroring out. It seems as if the "sketchImg.Delete()" line simply isn't actually doing anything.
I am wondering if anybody could give me any insight into this. Perhaps I am just missing something simple? Any thoughts are very much appreciated!
'Get the drawing document and its first sheet Dim doc As DrawingDocument = ThisApplication.ActiveDocument Dim sht As Sheet = doc.Sheets(1) 'Get the sheet's border Dim border As Border = sht.Border 'Get the border's definition, sketch, and sketch images Dim borderDef As BorderDefinition = border.Definition Dim borderSketch As DrawingSketch = borderDef.Sketch Dim sketchImages As SketchImages = borderSketch.SketchImages 'Edit the border by deleting the barcodes borderDef.Edit(borderSketch) For Each sketchImg As SketchImage In sketchImages If sketchImg.Name.ToUpper().Contains("MYIMAGE") sketchImg.Delete() End If Next borderDef.ExitEdit(True)
It took me a few tries but just one simple thing incorrect. The Drawing sketch being edit was incorrectly set. It should be picked up as a variable when the definition is edited. Looking at the border sketch object the tool tip indicates a read only status.
The manual object selection using pick command was a starting point to diagnose as the object was being deleted correctly using that method.
'Dim selectedObj As SketchImage = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Select a drawing view")
'selectedObj.Delete
'Get the drawing document and its first sheet
Dim doc As DrawingDocument = ThisApplication.ActiveDocument
Dim sht As Sheet = doc.Sheets(1)
'Get the sheet's border
Dim border As Border = sht.Border
'Get the doc's definition it is the same as getting the sheets border definition as they are linked.
'Dim borderDef As BorderDefinition = doc.BorderDefinitions.Item("image border")
'Get the sheet's border
Dim borderDef As BorderDefinition = border.Definition
'Declare object as a Drawing Sketch otherwise cannot access the objects.
Dim borderSketch As DrawingSketch
borderDef.Edit(borderSketch)
For Each sketchImg As SketchImage In borderSketch.SketchImages
Try
sketchImg.Delete
Catch
Logger.Info("Error deleting.")
End Try
Next
borderDef.ExitEdit(True)
Can't find what you're looking for? Ask the community or share your knowledge.