////// function Delete Outgoing Links ///////// //This function will delete all outgoing links in the passed object void fvDeleteOutLinks(Object o) { Link l //loop through and delete outlinks in object for l in o->"*" do { delete l } flushDeletions() //needed so can delete the object } //// Delete Incoming Links function //////// //This function will delete the incoming links of the passed in object //It returns true if there were no inlinks or link deletion was successful //Otherwise returns false. bool fbDelIncomingLinks(Object o){ Link l Object os ModName_ srcModRef string sSrcModName = "" Module srcMod = null Module cm = current //save it so we can restore it after we are done saving source modules bool bLinksDeleted = true //assume no links or they can be deleted //preload all incoming link source modules and store in skip list if opened in editable mode Skip skipModCache = create //skip list of source modules of incoming links opened for editing for srcModRef in o<-"*" do { sSrcModName = fullName(srcModRef) srcMod = edit(sSrcModName) //open the module in exclusive edit mode and display it if (srcMod != null) {//check to see if was opened put (skipModCache, srcMod, sSrcModName) //opened in exclusive, so save it. key is module, data is module name } else { //can't open in exclusive edit mode, try shareable edit mode srcMod = share(sSrcModName) //open up module in shareable edit mode and display it if (srcMod != null){ put (skipModCache, srcMod, sSrcModName) //opened in shareable so save it } else { //can't open source module so log this. User will be told later srcMod = read(sSrcModName) //open up module in read only mode at least so we can loop through all inlinks } } }//end of for loop //go through inlinks and delete them for l in o<-"*" do { os = source l //get source object srcModRef = source l //get source module handle sSrcModName = fullName(srcModRef) //get source module name and path if (!canModify os) { //can't modify object, so see if can lock section first string sLockResult = lock os if (!null sLockResult) { //can't lock section, so flag it so can tell the user later that object was not deleted and why SCR_Change_Log = SCR_Change_Log "Unable to lock section in " sSrcModName " with OID: " identifier os " to delete link to object " identifier o "\n" } } if (canModify os) { //gotta use this instead of else because we may have been able to lock section //can make a change, so delete the link and log it SCR_Change_Log = SCR_Change_Log "OID: " identifier o " Deleting incoming link from " sSrcModName " OID: " (int sourceAbsNo(l)) "\n" delete l } else { bLinksDeleted = false //couldn't modify and delete links, so set flag } } //end for l loop flushDeletions() //delete links now before end of dxl so the object can be deleted //go through skip list and save modules for sSrcModName in skipModCache do { srcMod =(Module key skipModCache) //check if still open and not current module if (open module sSrcModName && sSrcModName != cm."Name" ""){ SCR_Change_Log = SCR_Change_Log "Closing and saving changes (if any) to module: " fullName(srcMod) "\n" //close (srcMod, true) //prompts to save first if any changes!! Requires user interaction save (srcMod) //these 2 lines will automatically save and close without user prompt close (srcMod) } }// end for sScrcModName delete skipModCache current = cm //reset current module return bLinksDeleted } //end delete incoming links function ////// Delete Object Function //////// //This function will delete the passed in object o. //First deletes outgoing links, then delete incoming links //then deletes the object. If incoming links can not be //deleted, then the object is not deleted and the user will //be informed to manually do it. //This function will be done recursively to also delete the children //since DOORS deletes an object's children when it deletes the object, //we need to delete the childrens in and out links as well. void fvDeleteProcessing(Object o){ Object oc string errmsg //recursively call to delete any children first. for oc in o do { fvDeleteProcessing(oc) } fvDeleteOutLinks(o) //delete outgoing links if (fbDelIncomingLinks(o)) { //check to see if there are incoming links and delete them if possible //no inlinks or was able to delete them if (!isDeleted o) { //check if object is already deleted. This might have been because of children getting deleted with parent softDelete(o) //delete the object with any children } else { //object is already deleted so log error //save object to undeleted objects log if (sUndeleted_Objects == ""){ sUndeleted_Objects = identifier o } else { sUndeleted_Objects = sUndeleted_Objects " " identifier o } } } else { //was not able to delete inlinks and so could not delete object, so inform user current = o //set selection to the bad object so user knows which one it is refresh curmod //save objects to undeleted objects log if (sUndeleted_Objects == ""){ sUndeleted_Objects = identifier o } else { sUndeleted_Objects = sUndeleted_Objects " " identifier o } //make message to user string sTemp = "Object " identifier o " will NOT be deleted. It has incoming links I am unable to delete.\n" sTemp = sTemp "Please delete incoming links and run apply script again.\n\n" sTemp = sTemp "Confirm to continue, Cancel to halt the script." if(!confirm sTemp) fvHALT } }//end fvDeleteProcessing