(MEL)delete unused History and shape nodes of selected objects.

(MEL)delete unused History and shape nodes of selected objects.

absoluteKelvin
Collaborator Collaborator
4,399 Views
5 Replies
Message 1 of 6

(MEL)delete unused History and shape nodes of selected objects.

absoluteKelvin
Collaborator
Collaborator

I know there is a command MLdeleteUnused that deletes unused nodes. But its destructive and delete all unused nodes even textures as well. What I need specifically is shapes nodes and construction history that gets left behind even after delete history.

 

Thanks

https://www.artstation.com/kelvintam
0 Likes
Accepted solutions (1)
4,400 Views
5 Replies
Replies (5)
Message 2 of 6

mcw0
Advisor
Advisor

Yes, those pesky extra shape nodes.  You can get to those by using listRelatives a couple of times.

 

delete (stringArrayRemove(`listRelatives -shapes -ni`, `listRelatives -shapes`))

 

As for construction history nodes that are left hanging around, you can try "optimize scene size".  

Message 3 of 6

absoluteKelvin
Collaborator
Collaborator

thanks mcw0. elegant solution. unfortunately optimize scene size couldn't get rid of some of the lingering history.

 

I went with a less elegant solution by running DeleteHistory first> then run this

 

{
  string $mesh[] = `ls -sl -o`;
  string $mainShape[] = `listHistory -leaf true $mesh[0]`;
  string $allShapes[] = `listRelatives -s $mesh[0]`;
  string $emptyShapes[] = stringArrayRemove($mainShape, $allShapes);
  string $extrudes[] = `listConnections -type "polyExtrudeFace" $mainShape[0]`;
  string $cirulars[] = `listConnections -type "polyCircularize" $mainShape[0]`;
  string $chamfers[] = `listConnections -type "polyChamfer" $mainShape[0]`;
      catchQuiet(`delete $extrudes`);
      catchQuiet(`delete $cirulars`); 
      catchQuiet(`delete $emptyShapes`);
      catchQuiet(`delete $chamfers`);
}
https://www.artstation.com/kelvintam
Message 4 of 6

mcw0
Advisor
Advisor

It's true that optimize scene size doesn't catch everything.  But luckily in your case, you know the node types you are looking for.  I was thinking of a scene where you didn't know anything.  And you wanted to clean up all "loose ends".  There really is no elegant way that I know of other than going through each node type and checking for connections, as you've done.

0 Likes
Message 5 of 6

absoluteKelvin
Collaborator
Collaborator

I will keep digging away at it until i find a better solution. but for now I will use this for a script im writing right now.

https://www.artstation.com/kelvintam
0 Likes
Message 6 of 6

absoluteKelvin
Collaborator
Collaborator
Accepted solution

after some extensive digging. I think i found a more elegant solution.  got the idea from http://discourse.techart.online/t/get-all-construction-history-nodes-in-a-file/3465/2

 

global proc delSelEmptyGeoNodes()
{
	string $mesh[] = `ls -sl -o`;
	string $mainShape[] = `listHistory -leaf true $mesh[0]`;
	string $allShapes[] = `listRelatives -s $mesh[0]`;
	delete (stringArrayRemove(`listRelatives -shapes -ni`, `listRelatives   -shapes`)); 
	catchQuiet (delete (`listConnections -type "polyBase" $mainShape[0]`));
}

 in my case using type "polyBase" is good enough.  There is also "polyModifier", both gave me the same results. I haven't test it extensively so im unsure what the differences are.

https://www.artstation.com/kelvintam
0 Likes