Hello Forum, void recurseObjects(Object currObj) { if(last(currObj) != null) { Object lastObj = last(currObj) softDelete(lastObj) recurseObjects(currObj) } } for obj in mod do { if(!leaf(obj)) { recurseObjects(obj) softDelete(obj) } }
SystemAdmin - Wed Jun 02 10:34:01 EDT 2010 |
Re: Delete Objects with child Objects I'm just scribbling this down, you'll need to debug it yourself: void SoftDeleteObject(Object obj) { // delete the object recursively deleting its children first if (null obj) return Object oChild for oChild in obj do { SoftDeleteObject(oChild) // ** RECURSION HERE ** } DeleteIncomingLinks(obj) // you can write these two DeleteOutgoingLinks(obj) flushDeletions() if (!isDeleted(obj)) softDelete(obj) } // end SoftDeleteObject() SoftDeleteObject(current Object)
|
Re: Delete Objects with child Objects llandale - Wed Jun 02 11:21:41 EDT 2010 I'm just scribbling this down, you'll need to debug it yourself: void SoftDeleteObject(Object obj) { // delete the object recursively deleting its children first if (null obj) return Object oChild for oChild in obj do { SoftDeleteObject(oChild) // ** RECURSION HERE ** } DeleteIncomingLinks(obj) // you can write these two DeleteOutgoingLinks(obj) flushDeletions() if (!isDeleted(obj)) softDelete(obj) } // end SoftDeleteObject() SoftDeleteObject(current Object)
Oh yes. I doubt you should actually delete objects in the middle of a standard object loop. Skip skpDeletes = create() for obj in entire (current Module) do { if(I want to delete this object) put(skpDeletes, obj, obj) } for obj in skpDeletes do SoftDeleteObject(obj) delete(skpDeletes)
|
Re: Delete Objects with child Objects
When I ignore the incoming links problem and any "can not delete object because some weird condition" problem (which are not easy to solve, since you need to take care of a lot of special cases: source modules being locked, only available in shared edit or you have no access, etc.). You can code it as follows: void deleteObject(Object currObj) { Object childObj // delete outlinks Skip sk = create(); Link L; for L in all currObj->"*" do put(sk, L,L); for L in sk do delete L refresh module currObj for childObj in all currObj do { if (cell childObj || row childObj || isDeleted childObj) continue deleteObject childObj } // delete the object softDelete currObj } deleteObject current
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Delete Objects with child Objects Mathias Mamsch - Wed Jun 02 11:32:57 EDT 2010
When I ignore the incoming links problem and any "can not delete object because some weird condition" problem (which are not easy to solve, since you need to take care of a lot of special cases: source modules being locked, only available in shared edit or you have no access, etc.). You can code it as follows: void deleteObject(Object currObj) { Object childObj // delete outlinks Skip sk = create(); Link L; for L in all currObj->"*" do put(sk, L,L); for L in sk do delete L refresh module currObj for childObj in all currObj do { if (cell childObj || row childObj || isDeleted childObj) continue deleteObject childObj } // delete the object softDelete currObj } deleteObject current
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Delete Objects with child Objects llandale - Wed Jun 02 11:52:56 EDT 2010 |
Re: Delete Objects with child Objects This will help me to create a script that will fit my intension. Regards Chris |
Re: Delete Objects with child Objects llandale - Wed Jun 02 11:21:41 EDT 2010 I'm just scribbling this down, you'll need to debug it yourself: void SoftDeleteObject(Object obj) { // delete the object recursively deleting its children first if (null obj) return Object oChild for oChild in obj do { SoftDeleteObject(oChild) // ** RECURSION HERE ** } DeleteIncomingLinks(obj) // you can write these two DeleteOutgoingLinks(obj) flushDeletions() if (!isDeleted(obj)) softDelete(obj) } // end SoftDeleteObject() SoftDeleteObject(current Object)
Hello, void deleteObjects(Object obj){ Object objChild if (null obj) return if(obj."Variabilitaet" "" == "variabel"){ if(last obj != null) for objChild in obj do deleteObjects objChild delete obj } } Object obj; for obj in current module do deleteObjects obj;
|
Re: Delete Objects with child Objects Tekka - Mon Nov 08 10:26:59 EST 2010
Hello, void deleteObjects(Object obj){ Object objChild if (null obj) return if(obj."Variabilitaet" "" == "variabel"){ if(last obj != null) for objChild in obj do deleteObjects objChild delete obj } } Object obj; for obj in current module do deleteObjects obj;
Is it your intention to set that attribute "Variabilitaet" to "variabel" for an object, and have your code delete that object and all descendants, without bothering to set the value for each descendant? If so, you need a top level loop that looks at each object and its attribute value, and if it indicates 'delete', then call the recursive function that deletes that object, first recursively deleting all child objects, second deleting all in-links, and lastly deleting the object. that loop should, BTW, check if the objet is already deleted, and if so will indeed recurse child objects and dlete any inlinks, but won't try to actually delete it again.
|
Re: Delete Objects with child Objects llandale - Mon Nov 08 14:53:30 EST 2010
Thanks Louie, delete obj with softdelete obj and also check if the object is already deleted. Now it works fine :) |
Re: Delete Objects with child Objects Tekka - Thu Nov 11 04:25:58 EST 2010
Thanks Louie, delete obj with softdelete obj and also check if the object is already deleted. Now it works fine :) Hello All Greetings whatever proposed solution and code didnot work and getting the error of: cannot delete Object: object has descendants. Based on my understanding, DXL will mark the object has to be deleted,but delete operation will be executed once DXL execution complete. Script is marking all child object has to delete, when parent comes it says object has descendants, but all child are deleted at end of the execution any help will be very useful. |
Re: Delete Objects with child Objects senthilsubbu2020 - Wed Nov 22 02:03:56 EST 2017 Hello All Greetings whatever proposed solution and code didnot work and getting the error of: cannot delete Object: object has descendants. Based on my understanding, DXL will mark the object has to be deleted,but delete operation will be executed once DXL execution complete. Script is marking all child object has to delete, when parent comes it says object has descendants, but all child are deleted at end of the execution any help will be very useful. pragma encoding, "UTF-8" pragma runLim, 0 Module m = current Object startObj, endObj, o = current(m) getSelection(m, startObj, endObj) Skip skChildCache = create(); Object deleteInLinks(Object o) { Link l = null LinkRef lr = null ModName_ otherMod = null Object othero = null Skip deleteLinks = create for lr in all(o<-"*") do { ModuleVersion otherVersion = sourceVersion lr otherMod = module (otherVersion) edit(rootName_(otherMod), true, true, true) if ( !null otherMod ) { if ( (!isDeleted otherMod) && (null data(otherVersion)) ) { edit(rootName_(otherMod), true, true, true) } } delete otherVersion } for l in all(o<-"*") do { ModuleVersion otherVersion = sourceVersion l otherMod = module(otherVersion) delete otherVersion if (null otherMod || isDeleted otherMod) continue othero = source l if (null othero) {edit(rootName_(otherMod), true, true, true)} othero = source l if (null othero) continue put(deleteLinks, l, l, true) //overwrite if already exists. } for l in deleteLinks do { delete(l) } delete deleteLinks flushDeletions() return(o) } Object deleteOutLink (Object o) { Skip deleteLinks = create bool ret = false Link L for L in o->"*" do { put(deleteLinks, L, L, true) //overwrite if already exists. } for L in deleteLinks do { delete(L) } delete deleteLinks flushDeletions() return(o) } void recursiveAddChilds (Skip sk, Object oParent) { put(sk, oParent, oParent, true); //overwrite if already exists. Object oChild; for oChild in all oParent do { recursiveAddChilds(sk, oChild); // Cleanup current delete Object(s) too. } } if ( !null(startObj) ) { //if range has been selected, otherwise do nothing while ( !null(startObj) && isSelected(startObj) ) { recursiveAddChilds(skChildCache, startObj); startObj = next(startObj) } } else { if ( !null(o) ) { recursiveAddChilds(skChildCache, o); } } { //Clean up linkage even if already deleted for o in skChildCache do { deleteInLinks(deleteOutLink(o)) } for o in skChildCache do { //print (o."Absolute Number") "\n" if ( isDeleted(o) ) continue; softDelete(o, false) } } delete skChildCache bringToFront(m)
|
Re: Delete Objects with child Objects EHcnck - Wed Nov 22 13:55:45 EST 2017 pragma encoding, "UTF-8" pragma runLim, 0 Module m = current Object startObj, endObj, o = current(m) getSelection(m, startObj, endObj) Skip skChildCache = create(); Object deleteInLinks(Object o) { Link l = null LinkRef lr = null ModName_ otherMod = null Object othero = null Skip deleteLinks = create for lr in all(o<-"*") do { ModuleVersion otherVersion = sourceVersion lr otherMod = module (otherVersion) edit(rootName_(otherMod), true, true, true) if ( !null otherMod ) { if ( (!isDeleted otherMod) && (null data(otherVersion)) ) { edit(rootName_(otherMod), true, true, true) } } delete otherVersion } for l in all(o<-"*") do { ModuleVersion otherVersion = sourceVersion l otherMod = module(otherVersion) delete otherVersion if (null otherMod || isDeleted otherMod) continue othero = source l if (null othero) {edit(rootName_(otherMod), true, true, true)} othero = source l if (null othero) continue put(deleteLinks, l, l, true) //overwrite if already exists. } for l in deleteLinks do { delete(l) } delete deleteLinks flushDeletions() return(o) } Object deleteOutLink (Object o) { Skip deleteLinks = create bool ret = false Link L for L in o->"*" do { put(deleteLinks, L, L, true) //overwrite if already exists. } for L in deleteLinks do { delete(L) } delete deleteLinks flushDeletions() return(o) } void recursiveAddChilds (Skip sk, Object oParent) { put(sk, oParent, oParent, true); //overwrite if already exists. Object oChild; for oChild in all oParent do { recursiveAddChilds(sk, oChild); // Cleanup current delete Object(s) too. } } if ( !null(startObj) ) { //if range has been selected, otherwise do nothing while ( !null(startObj) && isSelected(startObj) ) { recursiveAddChilds(skChildCache, startObj); startObj = next(startObj) } } else { if ( !null(o) ) { recursiveAddChilds(skChildCache, o); } } { //Clean up linkage even if already deleted for o in skChildCache do { deleteInLinks(deleteOutLink(o)) } for o in skChildCache do { //print (o."Absolute Number") "\n" if ( isDeleted(o) ) continue; softDelete(o, false) } } delete skChildCache bringToFront(m)
Thank you so much EHcnck. your code worked perfectly. This is my first post and response. I am very much impressed. |