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

Delete workpoints and workaxis using API

nishantkumat5921
Enthusiast

Delete workpoints and workaxis using API

nishantkumat5921
Enthusiast
Enthusiast

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.

 

0 Likes
Reply
463 Views
6 Replies
Replies (6)

Michael.Navara
Advisor
Advisor

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

 

nishantkumat5921
Enthusiast
Enthusiast

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.

0 Likes

Michael.Navara
Advisor
Advisor

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

0 Likes

fidel.makatiaD5W7V
Alumni
Alumni

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 |
0 Likes

nishantkumat5921
Enthusiast
Enthusiast

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

0 Likes

A.Acheson
Mentor
Mentor

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
0 Likes