Notifications
Clear all

[Closed] Undo and polyop.CreatePolygon

Looks like its the same as this.

Theres no need for a “dummy” btw. I have some vert creations before I make polys. But it doesn’t matter…

Disabling undo in any way while creating polys for poly object is breaking undo or object by it self or causes max to crash. I saw somehere in documentation that for meshes you want just do “undo on” on last action and for polys you need to hold whole loop inside “undo on” in order to work propertly. But can’t find where I saw that. So I guess there no way to cheat the system. Undo for poly objects works pretty slow…

And I tested your code and absolutely the same – it breaks undo system and causing max to crash.

Anyway.
Is there a way to attach trimesh to polyobject using polyop.attach method? Help page say something weird about it:

polyop.attach
targetNode:<node=unsupplied> sourceNode:<node=unsupplied>

Attaches “source”, converted to a polymesh if necessary, to “poly”.

If “source” or “poly” is not a node value, the corresponding targetNode: or sourceNode: must be specified.

The source node is deleted after the attach is performed.

What is targetNode and sourceNode? And what do they mean when saying “If “source” or “poly” is not a node value”? If its not a node and not a trimesh so what else it can be?

So I guess there’s no way to aviod node creation? So I have to make a mesh to put my polys inside anyway? Its not a big deal but I was hoping for some “normal” solution.

Still didn’t tested what Serejah suggested, but Im pretty sure max will not make any undo records on that.
I hope I’ll do tests tomorrow.

Ok. I think I did it. And the good news is that I don’t even need to do anything with transformations.
it seems that when you do a polyop.getvert it returns the coordinates using word coordinates.

So. Just to summarize. All we need to know about Undo is:
Every single time you do something with poly object – it will update undo record. Even if you see only one record in undo history – it doesnt matter. And it will be very slow.

According to how it works – you have no choice but to put all of your actions inside undo on (code). There’s no way to walkaround this, except if you use another mesh object as a container and attach it to your poly later.

For mesh object you can just do some multiple actions inside loop with disabled undo, and then do last action with enabled undo – it will put the state of your object in undo history correctly.
And just to be clear: YOU CAN’T DO THE SAME WITH POLY OBJECTS.

So all actions with poly object with enabled undo will be allways slower than with mesh objects.

Here’s the code I used to attach everything to my poly object, in case some one will ever need it.

with undo off
(
   *do all the important stuff and build vertsarray, facearray and (in my case) open edgesarray*
)
  
--some small value for WeldThreshold
local WeldThreshold	= 0.001
   
 with undo "Blah blah blah" on
 (	
 	--creating mesh using VertsArray  and FaceArray 				
 	oMesh = mesh vertices: VertsArray faces: FaceArray								
 
 	--becase mesh will be deleted if user press ctrl+z anyway
 	--we can just disable undo for next actions 
 	with undo off
 	(
 		--sets selection for open edges to weld them later
 		setedgeselection oMesh EdgeArray
 		
 		--making faces to be quads
 		--clearing smothing groups
 		for face = 1 to oMesh.numfaces do 
 		(
 			setEdgeVis oMesh face 3 off
 			setFaceSmoothGroup oMesh face 0
 		)
 	)			
 	
 	--attaching our piece to a main mesh
 	polyop.attach oPoly oMesh				
 
 	--setting up WeldThreshold
 	oPoly.weldThreshold = WeldThreshold				
 	--welding edges
 	polyop.weldEdgesByThreshold oPoly (polyop.getEdgeSelection oPoly)
 )		
 
 --killing all the arrays we created
 free VertsArray
 free FaceArray
 free EdgeArray

Thanks everyone for your help and attention.

BTW for selection of 500 edges my script was doing its job in ~2000 ms, now (after I got rid from all this undo stuff) in ~65 ms.

try to search and find QuickPolyAttach here … you should find a great idea, smart discussion and explanations, and finally the best solution. This is one of my favorite topics on this forum.

Page 2 / 2