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 Bend Notes only in selected drawing view

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
chewy_robot
237 Views, 3 Replies

Delete Bend Notes only in selected drawing view

I have an ilogic rule started that is intended to delete flat pattern bend notes only in the selected flat pattern drawing view that is clicked on. I think I am close but can't quite get it. When I run this rule and click on the drawing view I want to delete the existing bend notes on (if any exist), it deletes the bend notes found on the entire drawing for all views. I want it so it only deletes the bend notes (if they exist) on the view that is selected after the rule is ran. How can I do this? Here is my current iLogic rule:

Imports System
Imports Inventor

Sub Main()
' Ensure you are in a drawing document
If ThisApplication.ActiveDocument.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MessageBox.Show("This tool can only be run in a drawing file!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
	Return
End If

Dim oDoc As DrawingDocument = CType(ThisApplication.ActiveDocument, DrawingDocument)
Dim oView As DrawingView = Nothing
Dim continueSelection As Boolean = True

While continueSelection
	Try
		' Use SelectionFilterEnum.kDrawingViewFilter for selecting drawing views
		oView = CType(ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a Drawing View to delete bend notes or ESC to exit."), DrawingView)
	Catch ex As Exception
		' User cancelled the selection or an error occurred
		MessageBox.Show("Selection cancelled or error occurred: " & ex.Message, "Selection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
		continueSelection = False
		Exit While
	End Try

	If oView Is Nothing Then
		MessageBox.Show("No valid view selected.", "Selection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
		continueSelection = False
	Else
		' Directly delete bend notes in the drawing sheet of the selected view
		For Each oSheet As Sheet In oDoc.Sheets
			If oSheet Is oView.Parent Then
				Dim bendNotesToDelete As New List(Of BendNote)
				For Each oNote As DrawingNote In oSheet.DrawingNotes
					If TypeOf oNote Is BendNote Then
						bendNotesToDelete.Add(CType(oNote, BendNote))
					End If
				Next
				' Delete the collected bend notes
				For Each bn In bendNotesToDelete
					bn.Delete()
				Next
			End If
		Next

		MessageBox.Show("Bend notes deleted successfully from the selected view's sheet.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
		continueSelection = False ' Exit after processing
	End If
End While
End Sub
Labels (3)
3 REPLIES 3
Message 2 of 4

You need to check the attached geometry is member of the selected view. Here is relevant part of your code.

...
For Each oNote As DrawingNote In oSheet.DrawingNotes
    If TypeOf oNote Is BendNote Then
        Dim oBendNote As BendNote = oNote
        If oBendNote.BendEdge.Parent Is oView Then
            bendNotesToDelete.Add(oBendNote)
        End If
    End If
Next
...
Message 3 of 4

Thanks for the feedback! This helped me to get it to work. Here is the full code for anyone that may need it:

Imports System
Imports Inventor

Sub Main()
' Ensure you are in a drawing document
If ThisApplication.ActiveDocument.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MessageBox.Show("This tool can only be run in a drawing file!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
	Return
End If

Dim oDoc As DrawingDocument = CType(ThisApplication.ActiveDocument, DrawingDocument)
Dim oView As DrawingView = Nothing
Dim continueSelection As Boolean = True

While continueSelection
	Try
		' Use SelectionFilterEnum.kDrawingViewFilter for selecting drawing views
		oView = CType(ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a Drawing View to delete bend notes or ESC to exit."), DrawingView)
	Catch ex As Exception
		' User cancelled the selection or an error occurred
		MessageBox.Show("Selection cancelled or error occurred: " & ex.Message, "Selection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
		continueSelection = False
		Exit While
	End Try

	If oView Is Nothing Then
		MessageBox.Show("No valid view selected.", "Selection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
		continueSelection = False
	Else
		' Collect bend notes associated with the selected view
		Dim bendNotesToDelete As New List(Of BendNote)
		For Each oNote As DrawingNote In oView.Parent.DrawingNotes
			If TypeOf oNote Is BendNote Then
				Dim oBendNote As BendNote = CType(oNote, BendNote)
				' Check if the bend note's associated edge's parent is the selected view
				If oBendNote.BendEdge.Parent Is oView Then
					bendNotesToDelete.Add(oBendNote)
				End If
			End If
		Next

		' Delete the collected bend notes
		For Each bn In bendNotesToDelete
			bn.Delete()
		Next

		MessageBox.Show("Bend notes deleted successfully from the selected view.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
		continueSelection = False ' Exit after processing
	End If
End While
End Sub
Message 4 of 4

Plase use code sample block instead of plain text and keep indentation for better readability. You can find it in editor menu under </> button.

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

Post to forums  

Autodesk Design & Make Report