3Ds Max crashes while running script

3Ds Max crashes while running script

avi_dews
Explorer Explorer
1,328 Views
12 Replies
Message 1 of 13

3Ds Max crashes while running script

avi_dews
Explorer
Explorer

I need to run this code on multiple files. But sometimes it crashes and 3Ds Max closes ending my loop. I tried the try-catch statement but it didn't work.

Can anyone please guide me?

 

 

	function turnToPoly = (
		for obj in geometry do (
			if isKindOf obj GeometryClass do
			(
				local turnToPolyMod = Turn_to_Poly()
				turnToPolyMod.removeMidEdgeVertices = off
				turnToPolyMod.keepConvex = on
				addModifier obj turnToPolyMod
			)
		)
	)

 

 

0 Likes
Accepted solutions (1)
1,329 Views
12 Replies
Replies (12)
Message 2 of 13

denisT.MaxDoctor
Advisor
Advisor

your code looks quite safe and shouldn't cause any crashes in general.

the problem may be in some specific objects which are GeometryClass but do not have a mesh. You can try to test this situation, but the easiest way is to use a try/catch context:

 

 

 

 

mapped fn _turn_to_poly obj = if iskindof obj GeometryClass do  
(
	try (addmodifier obj (Turn_to_Poly removeMidEdgeVertices:off keepConvex:on)) catch()
)

/*
_turn_to_poly objects
*/

 

 

 

 

I suggest finding these objects anyway to ensure they won't cause issues when treating them as mesh objects (for example, converting them to poly).

 

Message 3 of 13

denisT.MaxDoctor
Advisor
Advisor

@denisT.MaxDoctor wrote:

You can try to test this situation, but the easiest way is to use a try/catch context...

 


In general, I don't recommend using a try/catch context without understanding the cause of the error. Try/catch can significantly slow down the code and “hide” the problem for the next, worse case. 

bugs must be killed before they enter everywhere 😁

Message 4 of 13

avi_dews
Explorer
Explorer

thanks a lot for sharing the code. but I tested to put the modifier on the object manually and it still crashes 3ds max. there could indeed by some error in the mesh, or simply it can't handle turn_to_poly.

but since I have to do this in bulk for many 3ds max files using a maxscript loop, I want to create a way to not let 3ds max crash when such issue arises.

any guidance on this?

0 Likes
Message 5 of 13

denisT.MaxDoctor
Advisor
Advisor

Do you know the object that caused the crash?

You have only two options to complete the batch... The first is to ignore the problematic objects, the second is to fix them... Anyway, you have to find them.

Message 6 of 13

avi_dews
Explorer
Explorer

I come to know when a file crashes, but it happens randomly. i can share the 3ds max file if you want to see. but since I can't resolve the mesh issue (if it is the cause) for the files before hand, this crash issue causes the loop to stop. then I have to manually remove the file from loop and run the loop again. if it was a one time thing it was okay, but at my job I have to do it daily for at least 500 files.

you are right. and I can ignore the problematic objects. but how can it be done in the maxscript, how to leave that object when turn to poly does not work?

0 Likes
Message 7 of 13

denisT.MaxDoctor
Advisor
Advisor

@avi_dews wrote:

I come to know when a file crashes, but it happens randomly. i can share the 3ds max file if you want to see. 


share the file ... could you save it in MAX 2020 version?

Message 8 of 13

avi_dews
Explorer
Explorer

Here is the file. I also use 2020.

Please note that this file has some mesh error, indeed, But that's what I want to do, skip the files when turn to poly fails.

0 Likes
Message 9 of 13

denisT.MaxDoctor
Advisor
Advisor

Problem found... There are some "degenerate" faces that cannot be checked for convexity.
They are not "degenerate" in the poly sense, so they are hard to find and fix.
The only solution I have found is to use ProOtimiser first...

 

mapped fn turn_to_poly_pro obj =
(
	max modify mode
	select obj

	pro_opt = ProOptimizer()

	-- Set Protect Borders, Keep Material, Texture, and UV Boundaries, Keep Normals as Protected, and Merge Vertices
	pro_opt.OptimizationMode = 1
	pro_opt.LockMat = true				
	pro_opt.LockUV = true
	pro_opt.keepTextures = true
	pro_opt.keepNormals = true
	pro_opt.normalMode = 1
	pro_opt.mergeVertices = true

	modPanel.addModToSelection pro_opt
	pro_opt.Calculate = true

	to_poly = Turn_to_Poly()
	to_poly.removeMidEdgeVertices = off
	to_poly.keepConvex = on
		
	modPanel.addModToSelection to_poly
	
	ok
)
turn_to_poly_pro geometry

 

Message 10 of 13

denisT.MaxDoctor
Advisor
Advisor

there is something (a tool ?) in your pipeline for creating these objects that corrupts the mesh. Try to find what it is and exclude it from the pipeline or change the options.

Message 11 of 13

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

here is the better solution:

 

mapped fn _turn_to_poly obj = if iskindof obj GeometryClass do  
(
	addmodifier obj (Turn_to_Poly removeMidEdgeVertices:off keepConvex:off limitPolySize:on maxPolySize:4) 
	addmodifier obj (Turn_to_Poly removeMidEdgeVertices:off keepConvex:on) 
)
_turn_to_poly geometry	

 

 

There may be a topology in which a polyface with a degree greater than 4 may fail when trying to make that face convex. I limit polygon size by 4 first and then make them convex afterward. It works.

 

denisTMaxDoctor_0-1713576322741.png

 

polyop.getfacedeg $ 1604
3340

 

Message 12 of 13

denisT.MaxDoctor
Advisor
Advisor

You can play with different face degree limits... eg 32 works too.

Message 13 of 13

avi_dews
Explorer
Explorer

Wow, I seriously can't thank you enough! You totally came through and fixed a huge problem for me. I really and deeply appreciate it....!

 

Thankyou so much!

0 Likes