Delete nodes from part browser

Delete nodes from part browser

DavidTruyens
Advocate Advocate
1,471 Views
1 Reply
Message 1 of 2

Delete nodes from part browser

DavidTruyens
Advocate
Advocate

Hi,

 

i would like to delete all nodes in a part below a specific node. I've found this code to delete all features below EOP: https://forums.autodesk.com/t5/inventor-customization/how-to-delete-feature-below-end-of-part-in-inv...

 

I've tried to use that and change the "End Of Part" to the name of my feature. That does create a collection, but on the delete step it fails. So now I was trying to move the EOP to a specific position, but you can only move it to top or bottom?

 

Any suggestions?

 

Thanks,

David



David Truyens
Technical Specialist
Twitter | LinkedIn | IDCM | GitHub

0 Likes
Accepted solutions (1)
1,472 Views
1 Reply
Reply (1)
Message 2 of 2

DavidTruyens
Advocate
Advocate
Accepted solution

I've found a solution. I'm not sure but I think there's a limit to an object collection to delete (I have more than 100 features).

 

So here's my code, replace "My Feature" with your feature and it'll move the EOP above that feature and start deleting features from bottom to top:

 

 Sub DeleteMyFeatureAndEverythingBelow()

        Dim BrsPanes As BrowserPanes = _invApp.ActiveDocument.BrowserPanes
        Dim BrsPan As Inventor.BrowserPane = (From _Pan As BrowserPane In BrsPanes Where _Pan.TreeBrowser Select _Pan).FirstOrDefault
        Dim DoDelete As Boolean = False
        Dim ObjCollection As ObjectCollection = _invApp.TransientObjects.CreateObjectCollection()

        For Each wkpln As WorkPlane In _CompDef.WorkPlanes
            If wkpln.Name = "My Feature" Then
                wkpln.SetEndOfPart(True)
                Exit For
            End If
        Next

        Dim godelete As Boolean = True

        While godelete
            Dim _node As BrowserNode = BrsPan.TopNode.BrowserNodes.Item(BrsPan.TopNode.BrowserNodes.Count)
            If _node.BrowserNodeDefinition.Label = ("End of Part") Then
                godelete = False
            Else
                Dim objtest = _node.NativeObject
                ObjCollection.Add(objtest)
                _CompDef.DeleteObjects(ObjCollection)
                ObjCollection.Clear()
            End If
        End While

        For Each obody As SurfaceBody In _CompDef.SurfaceBodies
            obody.Visible = True
        Next
    End Sub


David Truyens
Technical Specialist
Twitter | LinkedIn | IDCM | GitHub

0 Likes