Handling grouped objects considered unlogical
If I find a graphic object to be deleted and it is within a group, then this is simple:
if (sSearch == "" && sFType == "TXTL") { // --- empty TextLine
if (object.GroupParent.constructor.name === "Group") {
object.GroupParent.Delete(); // ungroup
}
object.Delete();
}
However, If I want to process the found object further, it must be ungrouped from the group.
The following just ungroupes the first item in the group from the rest.
oGraphic = oGroup.FirstGraphicInGroup;
while (oGraphic.ObjectValid()) {
oGraphic.GroupParent = 0;
oGraphic = oGoup.NextGraphicInGroup;
nObjects += 1;
}
Even replacing oGoup.NextGraphicInGroup by oGraphic.NextGraphicInGroup does not help, because there is no group anymore for this object.
A more sophisticated algorithm is required:
function UnGroup (oGroup) {
var aItems = [], j, k= 0, oGraphic;
oGraphic = oGroup.FirstGraphicInGroup;
while (oGraphic.ObjectValid()) {
aItems[k] = oGraphic;
oGraphic = oGraphic.NextGraphicInGroup;
k ++;
}
for (j = 0; j < k; j++) {
aItems[j].GroupParent = 0;
}
return k;
}
However, in a process where I need to ungroup the found item for further processing I need to be able to distinguish whether the group is resolved or still exists. To query GroupParent for undefined gives no solution. For an ungrouped object.GroupParent is still a valid object, but properties of the GroupParent are mostly 0. For a grouped object the properties of GroupParent are mostly not 0:
if (KLD_F.IsGroupableObject (oFound) && (oFound.GroupParent.BorderWidth > 0)) {
// Borderwidth: arbitrary property to indicate validity of Group - no other criterion found
alert ("object is grouped - needs to be ungrouped; For further processing start over");
KLD_F.UnGroup (oFound.GroupParent); // ungroup the items
KLD_F.oLstObjFound.object = undefined; // start over
}
Do you have a different experience?

