Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Delete SketchImage from drawing border

1 REPLY 1
Reply
Message 1 of 2
jgerads4KMWR
181 Views, 1 Reply

Delete SketchImage from drawing border

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)

  

1 REPLY 1
Message 2 of 2
A.Acheson
in reply to: jgerads4KMWR

Hi @jgerads4KMWR 

 

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. 

AAcheson_0-1709183289211.png

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)

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report