Delete workpoints and workaxis using API

Delete workpoints and workaxis using API

nishantkumat5921
Enthusiast Enthusiast
1,054 Views
6 Replies
Message 1 of 7

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
1,055 Views
6 Replies
Replies (6)
Message 2 of 7

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

 

Message 3 of 7

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
Message 4 of 7

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
Message 5 of 7

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
Message 6 of 7

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
Message 7 of 7

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