Notifications
Clear all

[Closed] breakSelected () broken/bug?

Im trying to use breakSelected () on an object for break the uv’s, problem is i need to have clicked the “edit” button first, if i dont bring up the uvw edit window break does not work. Heres my script.

Btw if anyone has an easy way to do the following id like ot know Possibly without using the unwrap modifier?


 
 		mySelection = $.getselection #Face --get currently selected polys
 		macros.run "Modifier Stack" "Convert_to_Poly"
 		subobjectLevel = 0
 		modPanel.addModToSelection (Unwrap_UVW ()) ui:on
 		subobjectLevel = 3
 		$.modifiers[#unwrap_uvw].unwrap.selectPolygons mySelection --select original selection
 		$.modifiers[#unwrap_uvw].unwrap.edit ()
 		$.modifiers[#unwrap_uvw].unwrap.breakSelected () -- break selection before rotate
 		$.modifiers[#unwrap_uvw].unwrap2.RotateSelectedCenter 1.57079633 --rotate selected
 		macros.run "Modifier Stack" "Convert_to_Poly"
 		subobjectLevel = 4
 		$.EditablePoly.SetSelection #Face mySelection --select original selection
 
 
7 Replies

That is a known “problem”.

The maxscript reference says:
<void>breakSelected()
Presses the Break Selected button in the edit floater.

Here is the problem : the function “push the button”… If the interface is not open, nothing occurs.
One solution to resolve this problem is to copy the routines called when the button is pushed. But… Which are these routines ?
A second solution would be to remake the break function…

ok thats ok as it is then just would be nicer not to see the uvw dialog pop up

Thanks

I programmed a function “breakMapfaces” which does work the interface closed.
It is really restricting and inelegant to open the interface, and also slower.

I separated the function which marks unused mapvertices (markAsDeadUnusedMapVertices) because If you use several break, It’s sufficient to execute this function once only at the end.

test: make a plane, add an unwrap and select some faces.

fn markAsDeadUnusedMapVertices objUnwrapMod =
	(
	objUnwrap1=objUnwrapMod.unwrap
	objFaces=#{1..objUnwrap1.numberPolygons()}
	usedMapverts=#{}
	for thisFace in objFaces do (
		numPoints=objUnwrap1.numberPointsInFace thisFace
		for currentFaceVertex=1 to numPoints do (
			currentMapvert=objUnwrap1.getVertexIndexFromFace thisFace currentFaceVertex
			usedMapverts[currentMapvert]=true
			)
		)
	allMapverts=#{1..objUnwrap1.NumberVertices()}
	unusedMapVerts=allMapverts-usedMapverts
	for thisDeadMapvert in unusedMapVerts do ( objUnwrap1.markAsDead thisDeadMapvert )
	unusedMapVerts
	)--fn

fn breakMapfaces theFaces objUnwrapMod =
	(
	objUnwrap1=objUnwrapMod.unwrap
	mapVertsToFacesAndIdx=#()
	mapFacesToVerts=#()
	for thisFace in theFaces do (
		numPoints=objUnwrap1.numberPointsInFace thisFace
		currentMapVerts=#()
		currentMapVertsIdx=#{1..numPoints}
		for currentFaceVertex in currentMapVertsIdx do (
			currentMapvert=objUnwrap1.getVertexIndexFromFace thisFace currentFaceVertex
			append currentMapVerts currentMapvert
			if mapVertsToFacesAndIdx[currentMapvert]==undefined
				then mapVertsToFacesAndIdx[currentMapvert]=#(#(thisFace,currentFaceVertex))
				else append mapVertsToFacesAndIdx[currentMapvert] #(thisFace,currentFaceVertex)
			objUnwrap1.setFaceVertex (objUnwrap1.getVertexPosition 0f currentMapvert) thisFace currentFaceVertex false --break
			)
		mapFacesToVerts[thisFace]=currentMapVerts
		)
	-- linkArray
	linkArrayFacesAndIndex=#()
	for thisFace in theFaces do (
		numPoints=objUnwrap1.numberPointsInFace thisFace
		for currentFaceVertex=1 to numPoints do (
			currentMapvert=objUnwrap1.getVertexIndexFromFace thisFace currentFaceVertex
			oldMapvert=mapFacesToVerts[thisFace][currentFaceVertex]
			if currentMapvert!=oldMapvert do (
				for thisFVI in mapVertsToFacesAndIdx[oldMapvert] do (
					if linkArrayFacesAndIndex[currentMapvert]==undefined
						then linkArrayFacesAndIndex[currentMapvert]=#(#(thisFVI[1],thisFVI[2]))
						else append linkArrayFacesAndIndex[currentMapvert] #(thisFVI[1],thisFVI[2])
					)
				)
			)
		)
	--weld
	linkArrayFacesAndIndexCount=linkArrayFacesAndIndex.count
	for g=1 to linkArrayFacesAndIndexCount where (linkArrayFacesAndIndex[g]!=undefined) do (
		thisGroup=linkArrayFacesAndIndex[g]
		thisGroupCount=thisGroup.count
		if thisGroupCount>1 do (
			firstVert=objUnwrap1.getVertexIndexFromFace thisGroup[1][1] thisGroup[1][2]
			for i=2 to thisGroupCount do ( objUnwrap1.setFaceVertexIndex thisGroup[i][1] thisGroup[i][2] firstVert )
			)
		)
	)--fn



if selection.count==1 do (
	max modify mode
	obj=selection[1]
	select obj
	if classof obj.modifiers[1]==Unwrap_UVW
		then (
			objUnwrapMod=obj.modifiers[1]
			theFaces=objUnwrapMod.unwrap2.getSelectedFaces()
			if theFaces.numberset!=0
				then (
					breakMapfaces theFaces objUnwrapMod
					markAsDeadUnusedMapVertices objUnwrapMod
					)
				else messageBox("no faces selected in the unwrap")
			)
		else messageBox("the top modifier must be an unwrap with a face selection")	
	)

the work around i ended up using is to detatch the face, then weld it back in. Bit dodgey i guess but it works ok for now

Does anyone report the bugs in maxscript? im compiling a little list

I just found a second solution to break a face selection :

I use the instruction “copy” and I paste the result in the same object.
That seems to detach the faces !

But I am not sure that the method does work in all cases ?

I tested this new function “breakMapfaces” in several cases and that seems correct.
I did not encounter any problem.
let me know if there are problems.

fn setUnwrapContext obj objUnwrapMod =
	(
	if modPanel.getCurrentObject()==undefined do max modify mode
	if selection.count!=1 do select obj
	if selection[1]!=obj do select obj
	if modPanel.getCurrentObject()!=objUnwrapMod do modPanel.setCurrentObject objUnwrapMod
	)

fn breakMapfaces objUnwrapMod theFaces =
	(
	objUnwrap2=objUnwrapMod.unwrap2
	thisElementMode=objUnwrap2.getTVElementMode()
	thisSubObjectMode=objUnwrap2.getTVSubObjectMode()
	objUnwrap2.setTVElementMode false
	objUnwrap2.setTVSubObjectMode 3
	thisFaces=objUnwrap2.getSelectedFaces()
	objUnwrap2.selectFaces theFaces
	objUnwrap2.copy()
	objUnwrap2.paste false
	objUnwrap2.selectFaces thisFaces
	objUnwrap2.setTVElementMode thisElementMode
	objUnwrap2.setTVSubObjectMode thisSubObjectMode
	objUnwrapMod
	)



if selection.count==1 do (
	max modify mode
	obj=selection[1]
	select obj
	if classof obj.modifiers[1]==Unwrap_UVW
		then (
			objUnwrapMod=obj.modifiers[1]
			theFaces=objUnwrapMod.unwrap2.getSelectedFaces()
			if theFaces.numberset!=0
				then (
					setUnwrapContext obj objUnwrapMod
					breakMapfaces objUnwrapMod theFaces
					)
				else messageBox("no faces selected in the unwrap")
			)
		else messageBox("the top modifier must be an unwrap with a face selection")	
	)

so this is a rewrite of the break for max? cool