Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
nishantkumat5921
462 Views, 6 Replies

Delete workpoints and workaxis using API

Hello,

I am trying to delete the work points but getting an unspecified error in the delete line.

      public static void DeletePoints(string wpoint)
        {
            AssemblyComponentDefinition assCompDef = assyDoc.ComponentDefinition;
            for (int i = 1; i <= assCompDef.WorkPoints.Count; i++)
            {
                try
                {
                    if (assCompDef.WorkPoints[i].Name== wpoint)
                    {
                        assCompDef.WorkPoints[i].Delete();
                    }
                }
                catch (Exception)
                {

                  
                }
               
            }
        }

 

Thanks in advance.

 

This is because some workpoints is undeletable (Origin workpoint for example) and work point collection changes after each delete. Use following iLogic snippet for delete all workpoints in part. You need to translate it to C#.

 

 

Dim part As PartDocument = ThisDoc.Document
Dim wPoints As WorkPoints = part.ComponentDefinition.WorkPoints

Dim undeletablePoints As Integer = 0

Do While wPoints.Count > undeletablePoints
	Dim wPoint As WorkPoint = wPoints(undeletablePoints + 1)
	Try
		wPoint.Delete()
	Catch
		undeletablePoints += 1
	End Try
Loop

 

Thanks @Michael.Navara for the quick reply. But the below code does not delete the work points. It goes to the catch statement and adds on undeletablePoints.

This code deletes all workpoints which can be deleted. Some workpoints can't be deleted. Part origin, USS origins, derived workpoints, etc.

Hi @nishantkumat5921 the delete method will fail for derived parts . Check this link for inventor docs

Inventor 2022 Help | WorkPoint.Delete Method | Autodesk



Fidel Makatia
Developer Advocate

href=https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GUID-0BD48573-7193-4285-87B7-6727555D053E rel= "noopener noreferrer">Inventor 2022 Documentation |

Hi @fidel.makatiaD5W7V I have tried both the Booleans option and still get an unspecified error. The part is not derived.

Can you provide a screenshot of the workpoints location in the assembly?

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