@version 2.6 @warnings @name "MF HierClone" // Created by Petter Sundnes / MentalFish // July 11, 2011 // Updated by Alexandre Labedade // July 12, 2011 // some fixes to prevent the problems of clones numbers var childIndex = 0; var hierarchy = array; var targets = array; var tagIndex = 1; // arbitrary tag index generic { reqbegin("MentalFish HierClone"); reqsize(200,60); c1 = ctlinteger("Clones: ",0); ctlposition(c1,10,5,180); return if !reqpost(); var numOfClones = getvalue(c1); reqend(); var origSelection; (origSelection) = Scene().getSelect(); origParent = origSelection.parent; var parentList = array; if(origParent != nil){ var parentName = getCloneNameNoNum(origParent.name); var childcnt = childCount(origParent); var obj = getfirstitem(origParent.genus); while(obj){ if(getCloneNameNoNum(obj.name)==parentName){ if(childCount(obj) != childcnt){ parentList += obj; } } obj = obj.next(); } } parentIndex=1; origSelection.setTag(tagIndex,"root"); childIndex = 1; targets = array; record_target(origSelection,childIndex); origSelection.setTag(tagIndex,string(childIndex)); visitnodes(origSelection,"process_node"); for(i=1; i <= numOfClones; i++) { CommandInput("Generic_clonehierarchy"); var currentItem; (currentItem) = Scene().getSelect(); childIndex = 1; hierarchy = array; hierarchy[childIndex]= currentItem; visitnodes(currentItem,"process_hierarchy"); visitnodes(currentItem,"checkTarget"); if(currentItem.parent!=nil && parentList!=nil) { SelectItem(currentItem.name); ParentItem( parentList[parentIndex].name ); parentIndex++; if(parentIndex>sizeof(parentList)) parentList=nil; } SelectItem(origSelection.name); } } // get the number of children childCount: parent { var child = parent.firstChild(); var childcount = 0; while(child){ childcount++; child = parent.nextChild(); } return childcount; } // store the current hierarchy in an array process_hierarchy: parent, child { childIndex++; hierarchy[childIndex]=child; } // set tags and targets process_node: parent, child { childIndex++; child.setTag(tagIndex,string(childIndex)); record_target(child,childIndex); } record_target: parent,index { if(parent.target != nil){ targets[index]= parent.target.getTag(tagIndex).asInt(); }else{ targets[index]= 0; } } // Iterate through all the children checkTarget:parent,child { if(child.target != nil) { var index = child.getTag(tagIndex).asInt(); if(targets[index] > 0){ SelectItem(child.name); TargetItem(hierarchy[targets[index]].name); } } } // Get the clone number of an item without its brackets getCloneNum: cloneName { for(p=cloneName.size(); p >= 1; p--) { if(cloneName[p]=="(") { return strsub(cloneName,p+1,cloneName.size() - p - 1); } } return ""; } // Get the name of an item, without its " (2)" number behind it getCloneNameNoNum: cloneName { for(p=cloneName.size(); p >= 1; p--) { if(cloneName[p]=="(") { return strsub(cloneName,1,p - 2); } } return cloneName; }