Delete CATIA publication
Problem
First of all we found this problem on https://www.eng-tips.com/viewthread.cfm?qid=443335 . So we decided to write code for it.
Hello every one. It happend many times that I received Catproducts where somebody had deleted published element but didn’t remove linked publication.
Hence Catia shows it as broken publication. Due to I get problem with some checks. So I want to find and remove automatically broken publication from my Catparts. I can find them 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.
So can anybody help me?
Thanks in advance!
Solution
Sub CATMain() ' We want to select all parts from all product first, because of that we must define selection. Dim oSel As Selection Set oSel = CATIA.ActiveDocument.Selection oSel.Search "CATAsmSearch.Part,all" 'Now we wan to set for loop for previous selection. This loop will go trough every part in every product. For i = 1 To oSel.Count 'We need all publications from part. Here we will also use that part from selection, here you can see how selection is important. Dim num_of_publ_existing As Integer num_of_publ_existing = oSel.item(i).value.Publications.count 'We will define one array to store publication names. ReDim aa(num_of_publ_existing) 'We have now number of publication in part, let's use this info to create one more loop through publication inside part. For k = 1 To num_of_publ_existing PubName = oSel.item(i).value.Publications.Item(k).name Set PubRef =oSel.item(i).value.Publications.Item(PubName).Valuation 'Next few lines are very important. If publication has no element it's displayname is empty, use this to make if statement. If statement will put that publication in one array, so we can use it later. if PubRef.DisplayName = "" then aa(k-1)=PubName end if Next 'Here ends publiaction for loop, but we saved our publication with no element into array. 'Let's loop through array and delete publications with no element. for j=0 to num_of_publ_existing 'Our array length is num_of_publ_existing and it's more element that we need. We must to use if statement again. if aa(j) "" then oSel.item(i).value.Publications.Remove(aa(j)) end if next 'end of for loop for deleting publications Next 'end of for loop for parts oSel.Clear End Sub
So you can read more about selection and publication .
Certainly if you have any issues feel free to contact me.
Thank you for great 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!
Hmm i tested in my environment all was good, are you sure it will not delete all publications? That If statement allow to delete only with broken link? I use CATIA V5-6 2016. It can also be to the version of CATIA.
Hi,
I have also removed second If statement, and macro now delete publications with “no element”, but also delete publicated parameters. I would like avoid that, is it possible instead PubRef.DisplayName = “”, examine Publication Status “OK” or “No element” ?
Hello, I think this is the way to do it. How is possible that you parameters have display name “”? Or other word no name?
Hi,
Thank you for your code, it helps lot in my daily activity.
Will it possible to delete “Useless Elements” and “Remove Broken Publications”.
hi,
Publcation also including status OK/PROTECTED/NO ELEMENTS.
Your macro is great,but it deletes all except status OK.
How can I just delete status No Elements,and keep status Protect?