Hi All,
I am struggling with a report in which I need to delete models from a group. I have developed a code its its giving me errors, error lines are marked in bold in the below code. Can someone please review the code and suggest me the correctives
var g_nLoc = 1033;
var g_oOutfile = Context.createOutputObject();
function main(){
var oCurrentDatabase=ArisData.getActiveDatabase();
var arrSelectedGroups = ArisData.getSelectedGroups();
var arrSelectedmodels= ArisData.getSelectedModels();
g_nLoc = Context.getSelectedLanguage();
g_oOutfile.Init(g_nLoc);
for( i = 0; i <=(arrSelectedmodels.length() - 1); i++){
var modelGroup=arrSelectedmodels[i].Group();
modelGroup.Delete(arrSelectedmodels[i]);
}
g_oOutfile.WriteReport(Context.getSelectedPath(), Context.getSelectedFile());
}
main();
Hi Sumeet,
arrSelectedmodels.length() should be arrSelectedmodels.length
Also, when deleting objects in an array, delete from the back of the array.
Change your code as follows:
for(i=arrSelectedmodels.length-1; i>=0; i--){
var modelGroup=arrSelectedmodels[i].Group();
modelGroup.Delete(arrSelectedmodels[i]);
}
Regards,
Freddy
Hi Freeddy,
I tried your code but its not going into this FOR loop .
When I decoded it, found the value of arrSelectedmodels.length-1 variable is =0 thats why its not entering into the loop.
But on the folder on which I am executing this script is having models into it..
Kindly please suggest what to do.
Thanks :)
Sumeet
Hi Freddy,
I have created the Script and its working as per the expectation , Below is the code for it.
var g_nLoc = 1033;
var g_oOutfile = null;
function main(){
var oCurrentDatabase=ArisData.getActiveDatabase();
var arrSelectedGroups = ArisData.getSelectedGroups();
var arrSelectedmodels= ArisData.getSelectedModels();
var Ogroups =new Array();
var OModels =new Array();
var oCurrentModel =new Array();
var oTargetGroup=oCurrentDatabase.Group(["Maersk Drilling - Maersk FPSOs","W. To be Deleted Models"],g_nLoc);
var deletedModels=oTargetGroup.ModelList(true);
var x=deletedModels.length;
g_oOutfile = Context.createOutputObject(Context.getSelectedFormat(), Context.getSelectedFile());
g_nLoc = Context.getSelectedLanguage();
g_oOutfile.Init(g_nLoc);
g_oOutfile.OutputLn(x+"' Models Deleted '"+"'", "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, 0);
for(i=deletedModels.length-1; i>=0; i--){
var modelGroup=deletedModels[i].Group();
g_oOutfile.OutputLn(deletedModels[i].Name(g_nLoc), "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, 0);
modelGroup.Delete(deletedModels[i]);
}
g_oOutfile.WriteReport(Context.getSelectedPath(), Context.getSelectedFile());
}
main();
Thanks for your Help :)
Sumeet