[Solved] Deleting a follower by script

meipemeipe Posts: 82

I'm writing a script to quickly remove some followers from a figure.


So I iterate all nodes from the root, and check their label to find the one to delete.


I was wondering what's the best way to delete the node... do I have to use removeNodeChild (DzNode child, Boolean inPlace=false) /removeAllNodeChildren () or is there another way? I believe removeNodeChild only unparents the node?

Post edited by meipe on

Comments

  • MikeDMikeD Posts: 78
    edited September 2

    You don't even have to unparent the node if you wanna delete it.

    Use the Scene.removeNode(DzNode) method,

    in your case Scene.removeNode(oNodeToBeDeleted)

    I have writen the next script to delete many copies of an item, attached to a figure. Use it as you want. It is well commented.

    I used it when I made my Rock Jewelry products. When I tried the rings on the figure (1 to each finger), I ended up with a Genesis with 10 copies of the same ring, so I wrote the next script to easily remove them.

     

    // DAZ Studio version 4.10.0.123 filetype DAZ Script
    //              MikeD
    //
    //
    //
    /*=====================================================
    //  A function to remove multiple copies of an item
    // labeled sItem from a Figure labeled sFigureLabel
    ========================================================*/
    (function (){
    	var sFigureLabel = "Genesis 8 Male"; // the main figure
    	var sItem = "MDRJ Ring 06"; // the label of the itmem to be deleted
    
    	//deselect all nodes
    	Scene.selectAllNodes(false);
    	
    	
    	if(Scene.findNodeByLabel(sFigureLabel)==null){
    		
    		//no figure in the scene
    		debug("Find no "+ sFigureLabel+ " Figure Node!");
    		
    		//done
    		return;
    		
    	}
    	
    	//if there is a figure in the scene
    	var oNode = Scene.findNodeByLabel(sFigureLabel);
    		
    	// select the figure
    	Scene.setPrimarySelection(oNode);
    		
    	var nNodeId = Scene.findNodeIndex(oNode);
    	debug("Figure in Node: "+nNodeId);
    
    				
    	//tale the children nodes
    	var aFigureChildren = Scene.getNode(nNodeId).getNodeChildren(true);
    	
    	//set an arry for the items
    	var aItems = new Array;
    	
    	//take the item's 'Name'
    	var sItemName = Scene.findNodeByLabel(sItem).name;
    	
    	//iterate over the figure's children nodes
    	for (var i=0; i<aFigureChildren.length; i++){
    		
    		//find all other items on Figure with the same name
    		if( aFigureChildren[i].name == sItemName ){
    			aItems.push(aFigureChildren[i]);
    		}
    		
    	}
    	//check if there is any item in the array
    	if (aItems.length ==0 ){
    		print ("No " + sItem + " in the scene!");
    		//done
    		return;
    	}
    	
    	//iterate over items
    	for (var i=0; i<aItems.length;i++){
    		
    		//delete items from the scene
    		Scene.removeNode(aItems[i]);
    		
    	}
    	
    })();

     

    dsa
    dsa
    Delete an object (multiple copies) from a figure by MikeD.dsa
    2K
    Post edited by MikeD on
  • meipemeipe Posts: 82

    Works great, superthanks! :) :) :)

Sign In or Register to comment.