Return to Snippet

Revision: 65313
at November 18, 2013 12:53 by janusoo


Initial Code
try(destroyDialog polyChecker)catch()
rollout polyChecker "Check Edge Length"
(
	label lbl_info
	group "Check Edge Length"
	(
		spinner spn_edgeLength "Length Limit" range:[0,1000,1] align:#left width:130
		button btn_checkEdge "Check" align:#right
	)
	group "Check Face"
	(
		spinner spn_vertsCount "Verts Limit" range:[1,4,10] type:#integer align:#left width:130
		button btn_checkFace "Check" align:#right
	)
	
	
	local warningNodes = #()
	
	fn checkFace obj =
	(
		modPanel.setCurrentObject obj.baseObject
		subObjectLevel = 4
		faceCount = polyOp.getNumFaces obj
		facelist = for i = 1 to faceCount where (polyOp.getFaceVerts obj i).count > spn_vertsCount.value collect i
		polyOp.setFaceSelection obj facelist
		--subObjectLevel = 0
		if facelist.count > 0 then append warningNodes obj
		return facelist.count
	)
	
	function getEdgeLength theEditablePoly iEdge =
	(
		-- get vertexes defining the edge into an Array
		aiEdgeVerts = polyOp.getEdgeVerts theEditablePoly iEdge
		
		-- get vertexes positions into an Array
		ap3VertPosition = for iVert in aiEdgeVerts collect
		polyOp.getVert theEditablePoly iVert
		
		-- return the distance between vertexes
		result = distance ap3VertPosition[1] ap3VertPosition[2]
		return result
	)
	
	function checkProcess obj edgeLength =
	(
		target = obj
		if isKindOf target.baseObject Editable_Poly do
		(
			modPanel.setCurrentObject target.baseObject
			subObjectLevel = 1
			vertsList = #()
			edgeList = #()
			edgeCount = polyOp.getNumEdges target
			for i = 1 to edgeCount do
			(
				if (getEdgeLength target i) < edgeLength then
				(
					append edgeList i
					for num in (polyOp.getEdgeVerts target i) do append vertsList num			  
				)
			)
			polyOp.setEdgeSelection target edgeList 
			polyOp.setVertSelection target vertsList
			redrawViews()
			return edgeList.count
		)
	)
	
	fn updateInfo str =
	(
		lbl_info.text = str
	)
	
	on btn_checkEdge pressed do
	(
		updateInfo ((checkProcess $ spn_edgeLength.value) as string + " edges are found.")		
	)
	on btn_checkFace pressed do
	(
		errorCount = 0
		for o in selection where isKindOf o.baseObject Editable_Poly do
		(
			errorCount += checkFace o
		)
		subObjectLevel = 0
		if errorCount > 0 then
		(
			select warningNodes
			updateInfo (errorCount as string + " faces got error.")
		) else (
			updateInfo "No error."
		)
		
		redrawViews()
	)
)
createDialog polyChecker

Initial URL


Initial Description
for editable poly only

Initial Title
check editable_poly edge length and face verts count.

Initial Tags


Initial Language
Maxscript