Jump to content
  • 0

How do i remove unused sprites on all files in a folder using ACT Editor?


pazaway12

Question


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  10
  • Reputation:   0
  • Joined:  06/20/20
  • Last Seen:  

It can be done manually one by one, 

can someone help me with a script to do it for all the act files inside a folder?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  657
  • Reputation:   662
  • Joined:  11/12/12
  • Last Seen:  

Heya,

The original script can be opened with Scripts > Open scripts folder > script5_remove_unused_sprites.cs. In your case, you'd want something like this:

foreach (var actPath in Directory.GetFiles(@"C:\Test\", "*.act")) {
	var sprPath = actPath.ReplaceExtension(".spr");
	
	if (!File.Exists(sprPath))
		continue;
	
	var actFile = new Act(actPath, sprPath);
	
	for (int i = actFile.Sprite.Images.Count - 1; i >= 0; i--) {
		if (actFile.FindUsageOf(i).Count == 0) {
			actFile.Sprite.Remove(i, actFile, EditOption.AdjustIndexes);
		}
	}
	
	actFile.SaveWithSprite(actPath, sprPath);
}
  • Love 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  10
  • Reputation:   0
  • Joined:  06/20/20
  • Last Seen:  

12 hours ago, Tokei said:

Heya,

The original script can be opened with Scripts > Open scripts folder > script5_remove_unused_sprites.cs. In your case, you'd want something like this:

foreach (var actPath in Directory.GetFiles(@"C:\Test\", "*.act")) {
	var sprPath = actPath.ReplaceExtension(".spr");
	
	if (!File.Exists(sprPath))
		continue;
	
	var actFile = new Act(actPath, sprPath);
	
	for (int i = actFile.Sprite.Images.Count - 1; i >= 0; i--) {
		if (actFile.FindUsageOf(i).Count == 0) {
			actFile.Sprite.Remove(i, actFile, EditOption.AdjustIndexes);
		}
	}
	
	actFile.SaveWithSprite(actPath, sprPath);
}

Thanks a lot! This did the job right!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...