Does anybody have an example of a script where find the "function" objects in an EPC and assign them a "ID" attribute according to their order in the EPC?
2 Replies
var modelList=ArisData.getSelectedModels();
for(m in modelList)
DFSindex(modelList[m], Context.getSelectedLanguage())
function DFSindex(model, locale)
{
var index = 0;
var used = new java.util.HashSet()
model.BuildGraph(true)
var startOccList = ArisData.sort( model.StartNodeList(), Constants.SORT_Y, Constants.SORT_X, locale)
for(i in startOccList)
{
var occ = model.DFSGetFirstNode(startOccList[i])
while(occ!=null && occ.IsValid())
{
if(occ.getSymbol()==Constants.ST_FUNC && !used.contains(occ.ObjectID()) )
{
occ.ObjDef().Attribute(Constants.AT_ID,locale).setValue("index " + index);
used.add(occ.ObjectID())
index++;
}
occ = model.DFSNextNode()
}
}
}
Shashi Pal on
var omodel=ArisData.getSelectedModels(); var gloc=Context.getSelectedLanguage(); function main(){ for(var i=0;i<omodel.length;i++){ var objOccList=omodel[i].ObjOccListBySymbol(335); var sortedObjOccList=objOccList.sort(sortObjOccByPosition); for(var j=0;j<sortedObjOccList.length;j++){ //provide the id which u want to assign for id attribute //updating the id attribute by 0,1,2..... sortedObjOccList[j].ObjDef().Attribute(Constants.AT_ID,gloc).setValue(j); } } } main(); function sortObjOccByPosition(a,b){ if( a.Y() < b.Y() ) return -1; if( (a.Y() == b.Y()) && (a.X() < b.X()) ) return 1; if( (a.Y() == b.Y()) && (a.X() > b.X()) ) return -1; if( a.Y() > b.Y() ) return 1; return 0; }