Notifications
Clear all

[Closed] Crashing on Edit_poly mod Subobject Commands

Hi Everyone,

I am working with an basic mesh with a single Edit_poly modifier in the stack. The user makes a face selection in the Edit_Poly modifier and then runs my script.

My script is designed to execute a series of insets, bevels and extrudes, to make frame like structures. I am also detaching face selections to new objects, then selecting those objects and operating on them. Each time I run a command I make sure I select the object I want to operate on, and I move to the modify menu and to the subobject level (4 – cause I am always dealing with face selections).

The trouble I am getting is running these commands back to back (see example below) is causing ” ** system exception ** ” errors, epecially on complex geometry.

The commands I am running are like



Obj = (getcurrentselection())[1]
Obj.name = uniquename "Building_Frame" 

addmodifier Obj (edit_poly())

--Count faces and select all the faces to start modelling commands
Faceno = getnumfaces Obj 
Obj .modifiers[1].SetSelection #face #{1..Faceno}

--I am then running a series of commands, examples are;

--Insets
max modify mode
subobjectlevel = 4 
Obj.modifiers[1].insetamount = 200
Obj.modifiers[1].insettype = 1
Obj.modifiers[1].ButtonOp #inset

--Add new poly modifer in preparation for more modelling commands
addmodifier Obj (edit_poly())

--Bevels 
max modify mode
subobjectlevel = 4 
Obj.modifiers[1].bevelHeight = -20
Obj.modifiers[1].bevelOutline = -25
Obj.modifiers[1].bevelType = 2 
Obj.modifiers[1].ButtonOp #bevel

--Add new poly modifer in preparation for 
addmodifier Obj (edit_poly())

--Extrude
max modify mode
subobjectlevel = 4 
Obj.modifiers[1].extrudeFaceHeight  = -200
Obj.modifiers[1].extrudeFaceType = 2 
Obj.modifiers[1].ButtonOp #ExtrudeFace


Then I might detach the object from this selection and start operations on a new Object. To do this I have been using the commands: (multiple detachments will occur in a single script)



max modify mode
subobjectlevel = 4 
NewObjName = uniquename "Fresh_Object"
Obj.modifiers[1].DetachtoObject NewObjName

--Select and start work on the beading

NewObj = getnodebyname NewObjName
select NewObj


--Then continue with commands as before


From my testing the code seems to break down on the command (normally when I am working on a object that I have detached from a previous object, and I am looking to then detach a sub object face selection from this detached object (a little confusing… sorry!)):

Obj.modifiers[1].DetachtoObject NewObjName

This seems to most often cause the system exception. The trouble is that even if I run the commands successfully, then I will save the file. But when Itry and open it again Max crashes instead of opening the file! (Although if I collapse all the stacks to Editable_Meshes before saving, then the file seems to then load fine)

Could there be some sort of mesh update that I need to call? Like an equivalent of the “update MeshObj” command, to update the internal meshes or something!? (I am guessing).

I am very confused by this instability, any help would be really really appreciated, since it is seriously stalling some of the programs that I am trying to develop!

Thanks everyone

Rich

4 Replies

Hi,

You probably get this error because you loop through the faces and after detaching, the face count changes.

You should either update the face count in your loop, or loop it backwards (from faceCount to 1)

I am not sure, cause the commands that I am using such as:



--Insets
max modify mode
subobjectlevel = 4 
Obj.modifiers[1].insetamount = 200
Obj.modifiers[1].insettype = 1
Obj.modifiers[1].ButtonOp #inset


Just run off the current subobject face selection, just as if you were to hit the UI button. Doesnt this mean that it wouldnt be able to get the face count wrong, since it would simply run the command on the faces selected in the currently selected object?

Additionally, if I select any detached object then I always check the face count and select all the faces from that check…

I have run some further tests, and the instability does not seem to be caused by these UI commands for Bevels/Extrudes etc. It seems to be an instability in the command:

Obj.modifiers[1].DetachtoObject NewObjName

which again uses the currently selected faces when subobjectlevel is at face level (4). It always seems to detach the first object fine when using this command. But if I then select the newly detached object, and then do a series of modelling commands, and then try and detach a sub selection of that object, then that is where I normally get the system exception error. Sometimes it successfully passes this point, but if it crashes out then it is at this point. Even if the script completes successfully, then the file wont reload when saved.

If I dont use the

Obj.modifiers[1].DetachtoObject NewObjName

command at all, then the scene seems to reload, in all cases that I have tested so far…

Most strange. I am new to this area of scripting modifier modelling changes, so if I am doing something really obviously stupid in the way that I am approaching it, then please feel free to point it out!

Thanks for replying Zbuffer

Rich

For the record the problem did seem to be associated with manipulating the detached objects.

As soon as I detached an object (which detaches as an editable_poly) I converted this object to an editable_mesh, and then back to an editable_poly. I realise that this is a complete hack, but what ever it did in my particular case, it has solved all the stability issues as far as I can tell…

If someone could offer me an explanation for why this might be the case then I would be really grateful, I would prefer to understand what was causing the instability if I can…

Cheers,

Rich

Everzen

I can not reproduce that system exception with the following script:

(
	clearlistener()
	resetmaxfile(#noprompt)
	local obj = box()
	
	addmodifier obj (edit_poly())
	select obj
	--Count faces and select all the faces to start modelling commands
	local numFaces = getnumfaces obj
	max modify mode
	subobjectlevel = 4 
	-- obj.modifiers[1].SetSelection #Face #{1..numFaces} BUG: doesn't work
	obj.modifiers[1].Select #Face #{1..numFaces}
	
	local newObjName = uniquename "Fresh_Object"
	obj.modifiers[1].DetachtoObject newObjName
	
	-- Now to view our results...
	local newObj = objects[2]
	move newObj [50,-10,0]
	newObj.wirecolor = blue
	
	--deletemodifier obj 1
)

I tried it in Max 9, Max 2008, and even Max 2009 (which is still under development), and I couldn’t find that system exception.

If you can come up with more concrete repro steps by modifying my script above, then by all means post it back here or PM me, and I’ll try to get it fixed.

Chris Johnson