Deleting Everything from Part - Workplane Problem!

Deleting Everything from Part - Workplane Problem!

1211212212112122
Explorer Explorer
613 Views
6 Replies
Message 1 of 7

Deleting Everything from Part - Workplane Problem!

1211212212112122
Explorer
Explorer

Hi,

 

I often need to delete the entire content of a part which mostly holds Extrusion, Lofting Features, 3d Sketches, 2d Sketches and Workplanes.

I got a working code for deleting everything except for Workplanes:

' iLogic code to delete all features and sketches in an Inventor part document

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

If oPartDoc Is Nothing Then
    MessageBox.Show("No active part document found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
    ' Deactivate the document's automatic update to improve performance
    oPartDoc.Update2(False)

    ' Delete all features
    For Each oFeature In oPartDoc.ComponentDefinition.Features
        oFeature.Delete()
    Next

    ' Delete all sketches
    For Each oSketch In oPartDoc.ComponentDefinition.Sketches
        oSketch.Delete()
    Next
	
	' Loop through all 3D sketches
    For Each oSketch In oPartDoc.ComponentDefinition.Sketches3D
        oSketch.Delete()
    Next
	
	' Loop through all WorkPoints
    For Each oWorkPoint In oPartDoc.ComponentDefinition.WorkPoints
        oWorkPoint.Delete()
    Next
	
	' Loop through all WorkAxes
    For Each oWorkAxe In oPartDoc.ComponentDefinition.WorkAxes
        oWorkAxe.Delete()
    Next
	
	' Loop through all Planes !!! This Part Does not work!!!
'    For Each WorkPlane In oPartDoc.ComponentDefinition.WorkPlanes
'        WorkPlane.Delete()
'    Next
	
    ' Reactivate the document's automatic update
    oPartDoc.Update2(True)

    MessageBox.Show("All features and sketches have been deleted.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

 

As far as I am understanding the Error which I am getting is telling me that it is simply not possible to delete workplanes from a part? (Sorry it is in German)

Regelkompilierungsfehler in Features_löschen, in B_3D_011.ipt

Fehler in Zeile 39 : "Delete" ist kein Member von "Autodesk.iLogic.Interfaces.ICadWorkPlane".

 

Is there any workaround?

 

Thank you!

 

 

0 Likes
Accepted solutions (2)
614 Views
6 Replies
Replies (6)
Message 2 of 7

m_baczewski
Advocate
Advocate
Accepted solution

Hello,

 

In my opinion, you are trying to delete planes and axes that are initial elements and cannot be removed. You can only delete elements that you have created.

 

Although I'm not sure. Please check and let me know if you succeeded

 

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

Dim oWorkPlane As WorkPlane

For Each oWorkPlane In oPartDoc.ComponentDefinition.WorkPlanes
	If oWorkPlane.Name <> "Płaszczyzna YZ" And oWorkPlane.Name <> "Płaszczyzna XZ" And oWorkPlane.Name <> "Płaszczyzna XY"
		oWorkPlane.Delete()
	End if
Next

m_baczewski_0-1706274187883.png

 

0 Likes
Message 3 of 7

WCrihfield
Mentor
Mentor

Hi @1211212212112122.  Although @m_baczewski is correct that you will not be able to delete the original 3 WorkPlanes, due to them being part of the document origin structure, I see something different there, which is likely causing problems.  You are using the same exact spelling and capitalization for your variable in that loop as the object's Type, which is not allowed, and can cause problems.  Maybe just add a lowercase letter "o" to that variable (for example "oWorkPlanes"), like you did with all the other variables.

Edit:  Also, just as additional insight into what you are seeing within that error message, there is both an Inventor API WorkPlane type object, and an iLogic variable named WorkPlane, and that iLogic variable represents the Autodesk.iLogic.Interfaces.ICadWorkPlane Interface.  Below is a link to the documentation about that iLogic variable.

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=4c0fcba1-6986-ca53-d3f0-3547c3356506 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 7

1211212212112122
Explorer
Explorer

Thank you very much for the quick replies. The same as m_baczewski stated also applies for deleting workAxes and workPoint. The following code is working now: (For anyone who wants to use this code: Update the names of Planes, points, and centerpoint to your language!)

 

' iLogic code to delete all features and sketches in an Inventor part document
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

If oPartDoc Is Nothing Then
    MessageBox.Show("No active part document found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
    ' Deactivate the document's automatic update to improve performance
    oPartDoc.Update2(False)

    ' Delete all features
    For Each oFeature In oPartDoc.ComponentDefinition.Features
        oFeature.Delete()
    Next

    ' Delete all sketches
    For Each oSketch In oPartDoc.ComponentDefinition.Sketches
        oSketch.Delete()
    Next
	
	' Loop through all 3D sketches
    For Each oSketch In oPartDoc.ComponentDefinition.Sketches3D
        oSketch.Delete()
    Next
	
	' Loop through all WorkPoints
	Dim oWorkPoint As WorkPoint
	For Each oWorkPoint In oPartDoc.ComponentDefinition.WorkPoints
		If oWorkPoint.Name <> "Mittelpunkt"
			oWorkPoint.Delete()
		End If
	Next
	
	' Loop through all WorkAxes
	Dim oWorkAxe As WorkAxis
	For Each oWorkAxe In oPartDoc.ComponentDefinition.WorkAxes
		If oWorkAxe.Name <> "X-Achse" And oWorkAxe.Name <> "Y-Achse" And oWorkAxe.Name <> "Z-Achse"
			oWorkAxe.Delete()
		End If
	Next
	
	' Loop through all WorkPlanes
	Dim oWorkPlane As WorkPlane
	For Each oWorkPlane In oPartDoc.ComponentDefinition.WorkPlanes
		If oWorkPlane.Name <> "YZ-Ebene" And oWorkPlane.Name <> "XZ-Ebene" And oWorkPlane.Name <> "XY-Ebene"
			oWorkPlane.Delete()
		End If
	Next
	
    ' Reactivate the document's automatic update
    oPartDoc.Update2(True)

    MessageBox.Show("All features and sketches have been deleted.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

 

 

0 Likes
Message 5 of 7

WCrihfield
Mentor
Mentor

Hi @1211212212112122.  Just in case you were not aware, there is an easier way to check for if the work feature belongs to the origin structure.  Each of those object types has a direct property for that exact distinction.

WorkPlane.IsCoordinateSystemElement 

WorkPoint.IsCoordinateSystemElement 

WorkAxis.IsCoordinateSystemElement 

You could check the value of that ReadOnly Boolean property, instead of checking their names.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 7

J-Camper
Advisor
Advisor
Accepted solution

FYI You can also do something as simple as this to empty all user created objects:

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then Exit Sub
ThisApplication.CommandManager.ControlDefinitions.Item("PartMoveEOPToTopCmd").Execute()
Thisapplication.CommandManager.ControlDefinitions.Item("PartDeleteBelowStopNodeCtxCmd").Execute()

 

Message 7 of 7

1211212212112122
Explorer
Explorer
Wow, that is a much much faster way to delete everything, tank you!
0 Likes