delete links

i know how to create links between two objects

Object source -> string linkModuleName -> Object target
Object target <- string linkModuleName <- Object source

now how do i go about deleting links? help please?
phan423 - Wed Feb 15 19:40:31 EST 2012

Re: delete links
SystemAdmin - Wed Feb 15 21:33:03 EST 2012

You'll need to read the section on Link Management in the DOORS DXL Reference Manual (click here and download a copy - you need to look for the hyperlink though)

In summary - here's the library declaration.

void delete(Link l)

So you'll need to get a handle on link l first then delete it.

The trick here of course is determining which links in which objects to delete, a DXL skip list of the objects that have incoming\outgoing links that match your desired criteria for deletion is useful. If the links are incoming, you'll need to open and have edit access to the formal module that is the source of links......and so on....have a look at the DXL manual.... I've copied a utility script I've used in the past below - this only deletes incoming links to the current object but it might give you some clues.

There is no undo function if it all goes horribly wrong, so try it out on a copy of the project first - having said that, the deletion and creation of links is not fully executed until the formal module containing the source end of the links is saved - so if you make a mistake, close the source formal module without saving.
 

Object o=current
Module m=current
int count=0
 
void deleteIncomingLinks(Object o) {
    Module modSrc=null
        Module sourceMod=null
        Link l
        bool allModsOpen = true
      ModuleVersion sourceModVersion = null
 
        // Open all modules that are the source of incoming links in edit mode
        ModName_ srcModRef
        string srcModName=""
        for srcModRef in o<-"*" do {
                srcModName=fullName(srcModRef)
                modSrc=edit(srcModName, false)
                if (null modSrc) {  //provide a warning if a source cannot be opened in edit mode
                        infoBox "Cannot open for Edit module: " srcModName
                        allModsOpen = false
                        }
        }
 
        // Delete all incoming links
        if(allModsOpen) {  
                for l in o<-"*" do {
                        Object objSrc=source l
                        sourceModVersion = sourceVersion l
                        srcModRef = module(sourceModVersion)
                        modSrc=edit(fullName(srcModRef), false)
                        count++
                        delete l
                        flushDeletions  
                        save modSrc
                }
        
        }
        else print "Failed to get access to source module(s) \n"
} //End of deleteIncomingLinks
 
 
//***************** MAIN ********************
 
if(null o) {
        warningBox "No Object has been selected"
        halt
}
 
o = current
if(!null o) {
        if(!confirm "Delete all incoming links to this object?") halt
        deleteIncomingLinks(o)
        infoBox "Deleted " count " links"
        save m
        }
else    {
        warningBox "No object selected"
        }

 

 


Paul Miller
Melbourne, Australia

 

 

Re: delete links
llandale - Thu Feb 16 12:12:32 EST 2012

SystemAdmin - Wed Feb 15 21:33:03 EST 2012

You'll need to read the section on Link Management in the DOORS DXL Reference Manual (click here and download a copy - you need to look for the hyperlink though)

In summary - here's the library declaration.

void delete(Link l)

So you'll need to get a handle on link l first then delete it.

The trick here of course is determining which links in which objects to delete, a DXL skip list of the objects that have incoming\outgoing links that match your desired criteria for deletion is useful. If the links are incoming, you'll need to open and have edit access to the formal module that is the source of links......and so on....have a look at the DXL manual.... I've copied a utility script I've used in the past below - this only deletes incoming links to the current object but it might give you some clues.

There is no undo function if it all goes horribly wrong, so try it out on a copy of the project first - having said that, the deletion and creation of links is not fully executed until the formal module containing the source end of the links is saved - so if you make a mistake, close the source formal module without saving.
 

Object o=current
Module m=current
int count=0
 
void deleteIncomingLinks(Object o) {
    Module modSrc=null
        Module sourceMod=null
        Link l
        bool allModsOpen = true
      ModuleVersion sourceModVersion = null
 
        // Open all modules that are the source of incoming links in edit mode
        ModName_ srcModRef
        string srcModName=""
        for srcModRef in o<-"*" do {
                srcModName=fullName(srcModRef)
                modSrc=edit(srcModName, false)
                if (null modSrc) {  //provide a warning if a source cannot be opened in edit mode
                        infoBox "Cannot open for Edit module: " srcModName
                        allModsOpen = false
                        }
        }
 
        // Delete all incoming links
        if(allModsOpen) {  
                for l in o<-"*" do {
                        Object objSrc=source l
                        sourceModVersion = sourceVersion l
                        srcModRef = module(sourceModVersion)
                        modSrc=edit(fullName(srcModRef), false)
                        count++
                        delete l
                        flushDeletions  
                        save modSrc
                }
        
        }
        else print "Failed to get access to source module(s) \n"
} //End of deleteIncomingLinks
 
 
//***************** MAIN ********************
 
if(null o) {
        warningBox "No Object has been selected"
        halt
}
 
o = current
if(!null o) {
        if(!confirm "Delete all incoming links to this object?") halt
        deleteIncomingLinks(o)
        infoBox "Deleted " count " links"
        save m
        }
else    {
        warningBox "No object selected"
        }

 

 


Paul Miller
Melbourne, Australia

 

 

When using any of the numerous "for Handle1 in Handle2 do" loops in DOORS it's a big mistake to be deleting or adding any Handle1 entries for Handle2 as this messes up the loop. It's something like this, something all Coding 101 folks know not to do:

for i = 0 to 99
{  i = something else
}

 


In this case "for Link in Object <- "*" do" loop, you must not delete or add any such links .. while in the loop. Instead, routinely do something like this:

 

 

Skip skpLinksToDelete = create()  // KEY and DATA both 'Link'
for lnk in obj <-"*" do
{  if (I want to delete this link) then put(skpLinksToDelete, lnk, lnk)
}
   // now delete the links:
for lnk in skpLinksToDelete do
{  delete(lnk)
}
flushDeletions()
delete(skpLinksToDelete)


Notice that the "for lnk in skpLinksToDelete do" is not a "for Handle in Handle" loop, its a "for Handle in Structure" loop, and you MAY add or remove entries while inside the loop.

-Louie

Others:
for oChild in oSection do
for Item in Folder do
for AttrDef in Module do

 

Re: delete links
SystemAdmin - Thu Feb 16 18:47:59 EST 2012

llandale - Thu Feb 16 12:12:32 EST 2012

When using any of the numerous "for Handle1 in Handle2 do" loops in DOORS it's a big mistake to be deleting or adding any Handle1 entries for Handle2 as this messes up the loop. It's something like this, something all Coding 101 folks know not to do:

for i = 0 to 99
{  i = something else
}

 


In this case "for Link in Object <- "*" do" loop, you must not delete or add any such links .. while in the loop. Instead, routinely do something like this:

 

 

Skip skpLinksToDelete = create()  // KEY and DATA both 'Link'
for lnk in obj <-"*" do
{  if (I want to delete this link) then put(skpLinksToDelete, lnk, lnk)
}
   // now delete the links:
for lnk in skpLinksToDelete do
{  delete(lnk)
}
flushDeletions()
delete(skpLinksToDelete)


Notice that the "for lnk in skpLinksToDelete do" is not a "for Handle in Handle" loop, its a "for Handle in Structure" loop, and you MAY add or remove entries while inside the loop.

-Louie

Others:
for oChild in oSection do
for Item in Folder do
for AttrDef in Module do

 

...."for Handle1 in Handle2 do" loops in DOORS it's a big mistake to be deleting or adding any Handle1 entries for Handle2 as this messes up the loop....

Yep, good point, makes sense....but I'm scratching my head as to why does my 60 second late night hack utility script work then?

My perspective (not saying I'm right, just want to know where it's wrong), once you're in the loop, a handle has been passed to the next link, the link is deleted which effectively kills the handle to that link, but why does the loop itself care at this point? I'm not attempting to use the same link handle again (maybe that's where I get away with it), the loop then just increments to the next link handle if one is there.


Paul Miller
Melbourne, Australia

Re: delete links
Mathias Mamsch - Fri Feb 17 09:13:41 EST 2012

SystemAdmin - Thu Feb 16 18:47:59 EST 2012
...."for Handle1 in Handle2 do" loops in DOORS it's a big mistake to be deleting or adding any Handle1 entries for Handle2 as this messes up the loop....

Yep, good point, makes sense....but I'm scratching my head as to why does my 60 second late night hack utility script work then?

My perspective (not saying I'm right, just want to know where it's wrong), once you're in the loop, a handle has been passed to the next link, the link is deleted which effectively kills the handle to that link, but why does the loop itself care at this point? I'm not attempting to use the same link handle again (maybe that's where I get away with it), the loop then just increments to the next link handle if one is there.


Paul Miller
Melbourne, Australia

Well the way those for a in b do loops in DXL work is dependent on the datatype. For columns its a prominent example, that:
 

for col in mod do delete col

 


will not delete all columns. Why? Probably because columns are stored in an array like type, and the loop is implemented like:

 

 

 

void ::do (Column &c, Module m, void codeBlock) {
    iCount = get_number_of_columns in current view of m 
    for (i = 0; i < iCount; i++) do {
         c = get_column_nr i
         execute codeBlock
    }
}



when you now delete a column, then the other columns will shift their index by -1. Therefore if you delete column 6, then column 7 will become 6 but the loop will continue at 7, therefore skipping the old column 7. But this really depends on the data type and how the loop is implemented. Hope that explains it. Regards, Mathias



 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: delete links
llandale - Fri Feb 17 13:55:19 EST 2012

SystemAdmin - Thu Feb 16 18:47:59 EST 2012
...."for Handle1 in Handle2 do" loops in DOORS it's a big mistake to be deleting or adding any Handle1 entries for Handle2 as this messes up the loop....

Yep, good point, makes sense....but I'm scratching my head as to why does my 60 second late night hack utility script work then?

My perspective (not saying I'm right, just want to know where it's wrong), once you're in the loop, a handle has been passed to the next link, the link is deleted which effectively kills the handle to that link, but why does the loop itself care at this point? I'm not attempting to use the same link handle again (maybe that's where I get away with it), the loop then just increments to the next link handle if one is there.


Paul Miller
Melbourne, Australia

"... +why does my 60 second late night hack utility script work then+?"

I was scratching my own head as I wrote my retort, knowing you wouldn't have posted the code that you have not already proven to work. I specifically recall this being an issue with deleting links, but perhaps you don't have a problem because you are dealing with INcoming links, and this Object's list of incoming links is not adjusted when you indeed delete the underlying link.

Perhaps incoming links are stored as LinkRef's which then point to a null Link.

Anyway, maybe someone can prove me wrong using a script like your's but for outgoing links. And even if I'm wrong for "Link"s, what I said holds true for many other such loops.

Its also very possible they have fixed this feature in v9, since my previous understanding was from v7 and perhaps v8.

-Louie

I'd be tempted to put the Handles of the SourceModules that have deleted links into a Skip list, and after your big loop then flushDeletions and plow through the Skip saving those modules (just once).

Re: delete links
kavitharassou - Fri Jul 13 05:06:50 EDT 2012

SystemAdmin - Wed Feb 15 21:33:03 EST 2012

You'll need to read the section on Link Management in the DOORS DXL Reference Manual (click here and download a copy - you need to look for the hyperlink though)

In summary - here's the library declaration.

void delete(Link l)

So you'll need to get a handle on link l first then delete it.

The trick here of course is determining which links in which objects to delete, a DXL skip list of the objects that have incoming\outgoing links that match your desired criteria for deletion is useful. If the links are incoming, you'll need to open and have edit access to the formal module that is the source of links......and so on....have a look at the DXL manual.... I've copied a utility script I've used in the past below - this only deletes incoming links to the current object but it might give you some clues.

There is no undo function if it all goes horribly wrong, so try it out on a copy of the project first - having said that, the deletion and creation of links is not fully executed until the formal module containing the source end of the links is saved - so if you make a mistake, close the source formal module without saving.
 

Object o=current
Module m=current
int count=0
 
void deleteIncomingLinks(Object o) {
    Module modSrc=null
        Module sourceMod=null
        Link l
        bool allModsOpen = true
      ModuleVersion sourceModVersion = null
 
        // Open all modules that are the source of incoming links in edit mode
        ModName_ srcModRef
        string srcModName=""
        for srcModRef in o<-"*" do {
                srcModName=fullName(srcModRef)
                modSrc=edit(srcModName, false)
                if (null modSrc) {  //provide a warning if a source cannot be opened in edit mode
                        infoBox "Cannot open for Edit module: " srcModName
                        allModsOpen = false
                        }
        }
 
        // Delete all incoming links
        if(allModsOpen) {  
                for l in o<-"*" do {
                        Object objSrc=source l
                        sourceModVersion = sourceVersion l
                        srcModRef = module(sourceModVersion)
                        modSrc=edit(fullName(srcModRef), false)
                        count++
                        delete l
                        flushDeletions  
                        save modSrc
                }
        
        }
        else print "Failed to get access to source module(s) \n"
} //End of deleteIncomingLinks
 
 
//***************** MAIN ********************
 
if(null o) {
        warningBox "No Object has been selected"
        halt
}
 
o = current
if(!null o) {
        if(!confirm "Delete all incoming links to this object?") halt
        deleteIncomingLinks(o)
        infoBox "Deleted " count " links"
        save m
        }
else    {
        warningBox "No object selected"
        }

 

 


Paul Miller
Melbourne, Australia

 

 

This is what i have searched for..Thank you!great job!

Re: delete links
mcnairk - Fri Jul 13 08:55:02 EDT 2012

kavitharassou - Fri Jul 13 05:06:50 EDT 2012
This is what i have searched for..Thank you!great job!

There's also the attached Kitchen script (you'll need to update the paths to the locations of the include files). It's a bit more powerful and therefore dangerous. I find the delete links to objects in current display set the most useful, since it is then then responsibility of the user requesting the deletions to craft the filter...

Ken.
Attachments

attachment_14856393_Delete_Links.zip

Re: delete links
bmohamed - Fri Apr 08 15:28:13 EDT 2016

SystemAdmin - Wed Feb 15 21:33:03 EST 2012

You'll need to read the section on Link Management in the DOORS DXL Reference Manual (click here and download a copy - you need to look for the hyperlink though)

In summary - here's the library declaration.

void delete(Link l)

So you'll need to get a handle on link l first then delete it.

The trick here of course is determining which links in which objects to delete, a DXL skip list of the objects that have incoming\outgoing links that match your desired criteria for deletion is useful. If the links are incoming, you'll need to open and have edit access to the formal module that is the source of links......and so on....have a look at the DXL manual.... I've copied a utility script I've used in the past below - this only deletes incoming links to the current object but it might give you some clues.

There is no undo function if it all goes horribly wrong, so try it out on a copy of the project first - having said that, the deletion and creation of links is not fully executed until the formal module containing the source end of the links is saved - so if you make a mistake, close the source formal module without saving.
 

Object o=current
Module m=current
int count=0
 
void deleteIncomingLinks(Object o) {
    Module modSrc=null
        Module sourceMod=null
        Link l
        bool allModsOpen = true
      ModuleVersion sourceModVersion = null
 
        // Open all modules that are the source of incoming links in edit mode
        ModName_ srcModRef
        string srcModName=""
        for srcModRef in o<-"*" do {
                srcModName=fullName(srcModRef)
                modSrc=edit(srcModName, false)
                if (null modSrc) {  //provide a warning if a source cannot be opened in edit mode
                        infoBox "Cannot open for Edit module: " srcModName
                        allModsOpen = false
                        }
        }
 
        // Delete all incoming links
        if(allModsOpen) {  
                for l in o<-"*" do {
                        Object objSrc=source l
                        sourceModVersion = sourceVersion l
                        srcModRef = module(sourceModVersion)
                        modSrc=edit(fullName(srcModRef), false)
                        count++
                        delete l
                        flushDeletions  
                        save modSrc
                }
        
        }
        else print "Failed to get access to source module(s) \n"
} //End of deleteIncomingLinks
 
 
//***************** MAIN ********************
 
if(null o) {
        warningBox "No Object has been selected"
        halt
}
 
o = current
if(!null o) {
        if(!confirm "Delete all incoming links to this object?") halt
        deleteIncomingLinks(o)
        infoBox "Deleted " count " links"
        save m
        }
else    {
        warningBox "No object selected"
        }

 

 


Paul Miller
Melbourne, Australia

 

 

hi paul,

I tried to add a loop to your code to run through all objects in a module that have a status of 'deleted'.  thats an enumerated type i use.

im having issues getting it to run with my placement of the loop and my criteria.  i've tried diff placements of the loop and criteria with no luck

 

for o in m do {
string sstatus = probeAttr_(obj,"Status")
if (sstatus == "Deleted") {
}
                }