How to delete a CATProduct with a macro

To delete a CATProduct from your tree in V5:

Dim oDoc As ProductDocument

Set oDoc = CATIA.ActiveDocument

Dim oProds As Products

Set oProds = oDoc.Product.Products

Dim iCount As Long

iCount = oProds.Count

If iCount > 0 Then

oProds.Remove iCount

End If

To remove a product in V6 with VBA:

Dim oPrdService As PLMProductService

Set oPrdService = CATIA.ActiveEditor.GetService(“PLMProductService”)

Dim oRoot As VPMRootOccurrence

Set oRoot = oPrdService.RootOccurrence

Dim oSel As Selection

Set oSel = CATIA.ActiveEditor.Selection

oSel.Clear

Dim iCount As Long

iCount = oRoot.Occurrences.Count

If iCount > 0 Then

Dim oOcc As VPMOccurrence

Set oOcc = oRoot.Occurrences.Item(iCount)

oSel.Add oOcc

oSel.Delete

End If

That’s it! Questions? Let us know in the comments below.

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.