Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove Broken Publications from CAITA V5 Using VBA 1

Status
Not open for further replies.

Sidtha

Aerospace
Nov 25, 2012
30
Hello All,

I wanted to remove the broken publication link as shown below.
Written basic to get all publications.
My question is macro listing all publications but it has to list out only broken publication as it was having yellow "!" symbole.
RemovePub_lc7xre.png

Sub CATMain()

Set CATIA = GetObject(, "CATIA.APPLICATION")
Set oSelection = CATIA.ActiveDocument.Selection
oSelection.Search "CATAsmSearch.Part,all"

For i = 1 To oSelection.Count
Dim num_of_publ_existing As Integer
num_of_publ_existing = oSelection.Item(i).Value.Publications.Count
ReDim aa(num_of_publ_existing)

For k = 1 To num_of_publ_existing
PubName = oSelection.Item(i).Value.Publications.Item(k).Name
Set PubRef = oSelection.Item(i).Value.Publications.Item(PubName).Valuation
'Debug.Print PubRef.DisplayName
'Debug.Print PubRef.Name

If PubRef.DisplayName > 0 Then
aa(k - 1) = PubName
'Debug.Print PubRef.DisplayName
Debug.Print PubName
End If
Next

For j = 0 To num_of_publ_existing
' Debug.Print PubRef.DisplayName
' Debug.Print PubName
' If aa(j) = "" Then
' oSelection.Item(i).Value.Publications.Remove (aa(j))
' End If
Next

Next

oSelection.Clear

End Sub

Please help me to resolve this thank you
 
Replies continue below

Recommended for you

Code:
Dim uPart As Part
Set uPart = CATIA.ActiveDocument.Part

Dim partPubs As Publications
Set partPubs = uPart.Parent.Product.Publications

For Z = partPubs.Count To 1 Step -1
    Dim ThisPub As Publication
    Set ThisPub = partPubs.Item(Z)
      
    If ThisPub.Valuation.DisplayName = "" Then
        partPubs.Remove (ThisPub.Name)
    End If
Next
 
Thank you weagan22

It works fine
 
Hi. This is a useful macro. However I can't apprehend what happens after running the macro. The publications are deleted but they are still showing in the tree. What's the next step? Update? Or save? Please enlighten me.
 
The reason you have exclamation marks on your publications is because the geometry linked to said publication labels has been deleted (i.e no elements associated with the publication tag).
The script removes those lines from the publications window (tools-publications). This action is not immediately refreshed (the publication tree remains outdated, but after a while, the publication tree updates to show the correct contents of the publications.)


regards,
LWolf
 
Thanks LWolf,

I was testing this macro on a quickly made part and was surprised nothing happened, but after a while they disappeared. So there's no workaround, it will happen when it should.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor