cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VBA - Check all possible links for a object

mrajih
Super Contributor

Hi,

 

I'm currently working an a VBA script to clean the repository. This script will be deleting all tagged objects (linked to a specific tag).

 

Before doing so, I need to check if the tagged object has no link to other objects.

 

Can you please help provide the missing code line ?

 

###############################################

oTag = myRoot.GetObjectFromID("l7yGVveJUDp7")

 

For each oObj in oTag.GetCollection("Element avec tags")

     'get oObj Metaclass

     soObjType = oObj.GetOjectType

     'get list of possible MetaAssociations

     cMetAsso = myRoot.GetSelection("Select .... xxxxxxx") 

     For each oMetAsso in cMetaAsso

          If oObj.GetCollection(oMetAsso).count = "0" Then

               oObj.Delete

          End If

     Next

Next

 

##########################################

 

Thank you

Mehdi

2 Replies

mrajih
Super Contributor

Hi,

 

Thank you for pointing out this macro.

 

I updated my code accordingly but still not able to list all possible MetaAssociationEnd from a specific object, only part of them is found. Maybe I'm missing something ?

 

########################################################

oTag = root.GetObjectFromId("43C18E5F5E4E1F33")

 

For Each oObj In oTag.GetCollection("Element avec tags")

    i = 0

   

    For Each oLinkEnd In oObj.GetTypeObject.GetCollection("Collections")   <<< ======  

   

        sLinkEndName = oLinkEnd.GetProp("Name")

        sObjName = oObj.GetProp("Short Name")

       

        'MsgBox (oObj.GetCollection(sLinkEndName).Count)

       

        If sLinkEndName <> "Tag" Then

            If sLinkEndName Like "Change*" Then

               GoTo NextIteration

            ElseIf sLinkEndName Like "*Log" Then

                GoTo NextIteration

            ElseIf oObj.GetCollection(sLinkEndName).Count <> 0 Then

                i = i + 1

            End If

        End If

NextIteration:

    Next

    If i <> 0 Then

        sListElementsAvecLien = sListElementsAvecLien & vbCrLf & sObjName

    Else

        sListElementsSupprimes = sListElementsSupprimes & vbCrLf & sObjName

        'oObj.Delete

    End If

   

Next

#######################################################

 

Thank you

Mehdi

hsoegaard
MEGA Partner
MEGA Partner

Hi,

 

Try abd have a look on the standard macro "Agent - Where used.macro" I think you should find what you need there.