understanding problem vertex_groups method

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
drlolig
Posts: 1
Joined: Tue Nov 27, 2012 1:21 pm

understanding problem vertex_groups method

Post by drlolig » Tue Nov 27, 2012 1:28 pm

hello,

i want to check the wall thickness of an object, i ve a good working script for blender 2.49,
i converted all the code to python blender 2.6, because blender 2.6 can run in the background.

Code: Select all

def PaintVertices(me, vertIndList, paintAmt, group):
		if paintAmt >= 0.1:  # Prevents float rounding errors and so forth from potentially troubling us; we refuse to paint anything under 10%.
			for vertInd in vertIndList:
				try:
					currentState = me.getVertsFromGroup(group, 1, [vertInd])
					if currentState and currentState[0][1]:
						curPaint = currentState[0][1]
					else: curPaint = 0.0
				except AttributeError: curPaint = 0.0
				except RuntimeError: curPaint = 0.0
			
				if not curPaint:
					me.assignVertsToGroup(group, [vertInd], paintAmt, AssignModes.ADD)
					#print "Newly painting vert {0:d} to {1:.1%}.".format(vertInd, paintAmt)
				elif paintAmt > curPaint:
					me.assignVertsToGroup(group, [vertInd], paintAmt, AssignModes.REPLACE)
					#print "Repainting vert {0:d} from {2:.1%} to {1:.1%}.".format(vertInd, paintAmt, curPaint)
				else:
					#print "Declining to paint vert {0:d} to {1:.1%}, since it's already at {2:.1%}.".format(vertInd, paintAmt, curPaint)
					pass
i don t know to do some thing with me.getVertsFromGroup(group, 1, [vertInd])

my code, but don t work:



Code: Select all

        def PaintVertices(ob, vertIndList, paintAmt, group):
                if paintAmt >= 0.1:
                       for vertInd in vertIndList:         
                                try:
                                        currentState = ob.vertex_groups[group]
                                        if currentState.index == vertInd:
                                                if currentState and currentState[0][1]:
                                                        curPaint = currentState[0][1]
                                                else: curPaint = 0.0
                                except AttributeError: curPaint = 0.0
                                except RuntimeError: curPaint = 0.0
                                
                                if not curPaint:
                                        ob.vertex_groups[group].add([vertInd], paintAmt, type='ADD')
                                elif paintAmt > curPaint:
                                        ob.vertex_groups[group].add([vertInd], paintAmt, type='REPLACE' )
                                else:
                                        pass

mfg drlolig

Post Reply

Who is online

Users browsing this forum: Yahoo [Bot] and 0 guests