Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Catia v5 remove of broken publication with macro 1

Status
Not open for further replies.

Pawel Chil

Automotive
Apr 19, 2018
10
PL
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!

noElement_ejruq4.png


Publication_m1fyyd.png
 
Replies continue below

Recommended for you

hello, this will give you the publication item:

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
PubName = MyPart.Parent.Product.Publications.Item(k + 1).name
Set PubRef = MyPart.Parent.Product.Publications.Item(PubName).Valuation
msgbox PubRef.DisplayName​
Next
...
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)
MyPartProduct.Publications.Remove (MyElement)​
End Function


regards,
LWolf
 
Thanks for your answer LWolf!
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
 
Thank you HarunMusic 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.
 
I use the some Catia, maybe there are some differences because of Service Pack, Hotfix or Build Number?
I have Service Pack 3, Build Number 26, Hotfix 42.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top