Catia v5 remove of broken publication with macro
Catia v5 remove of broken publication with macro
(OP)
Hello every one,
It happend many times that I receive Catpruducts where somebody has deleted published element but didn't remove linked publication.
And of course Catia shows it as broken publication and I got problem with some checks.
I want to find and remove automatically broken publication from my Catparts.
I can find publications with macro but I don't know how to write in macro following things:
- open from Tools -> Publications window
- select publications with status "no element" and remove it
Can anybody help me??
thanks in advance!

It happend many times that I receive Catpruducts where somebody has deleted published element but didn't remove linked publication.
And of course Catia shows it as broken publication and I got problem with some checks.
I want to find and remove automatically broken publication from my Catparts.
I can find publications with macro but I don't know how to write in macro following things:
- open from Tools -> Publications window
- select publications with status "no element" and remove it
Can anybody help me??
thanks in advance!


RE: Catia v5 remove of broken publication with macro
Dim num_of_publ_existing As Integer
num_of_publ_existing = MyPart.Parent.Product.Publications.count
For k = 0 To MyPart.Parent.Product.Publications.count - 1
Set PubRef = MyPart.Parent.Product.Publications.Item(PubName).Valuation
msgbox PubRef.DisplayName
so PubRef.DisplayName contains the published name. If there is nothing there, then it is just empty i.e "".
and then you can call a function that removes that element.
Function RemovePublication(MyPartProduct, MyElement)
regards,
LWolf
RE: Catia v5 remove of broken publication with macro
Unfortunatelly my knowledge of catia scripting is not enough to implement your solution into my code.
Could you help me?
My code below:
Sub CATMain()
Dim foundPublications() As Publication
Dim iNbPublications ' As Integer
Dim iPublication ' As Integer
iNbPublications = 0
ReDim foundPublications(iNbPublications) As Publication
Dim oSel As Selection
Set oSel = CATIA.ActiveDocument.Selection
oSel.Search "CATAsmSearch.Product,all"
Dim iProduct ' As Integer
Dim foundProduct As Product
For iProduct = 1 To oSel.Count
Set foundProduct = oSel.Item(iProduct).Value
Dim productPublications As Publications
Set productPublications = foundProduct.Publications
For iPublication = 1 To productPublications.Count
ReDim Preserve foundPublications(iNbPublications) As Publication
Set foundPublications(iNbPublications) = productPublications.Item(iPublication)
iNbPublications = iNbPublications + 1
Next
Next
oSel.Clear
For iPublication = 1 To iNbPublications
Dim publishedReference As Reference
Set publishedReference = foundPublications(iPublication - 1).Valuation
oSel.Add publishedReference
Dim publishedElement As AnyObject
Set publishedElement = oSel.Item(iPublication).Value
MsgBox "Found published element!" & vbCr & "Name (Type): " & publishedElement.Name & "(" & TypeName(publishedElement) & ")"
Next
End Sub
regards
Pawel Chil
RE: Catia v5 remove of broken publication with macro
i wrote solution for your problem, you can copy code and read more on here https://catiavbmacro.com/2018/08/27/delete-catia-p...
RE: Catia v5 remove of broken publication with macro
I have removed lines 36 and 38, otherwise it doesn't remove any element(I think because already selected publications have just ordinary name not "" like condition in if ).
Without these lines works perfectly!
Thanks a lot!
RE: Catia v5 remove of broken publication with macro
RE: Catia v5 remove of broken publication with macro
I have Service Pack 3, Build Number 26, Hotfix 42.
RE: Catia v5 remove of broken publication with macro