View Single Post
  #2  
Old 02-15-2012, 08:43 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
If you have your exampleObject class inherit from the Vizard node class, then your class instance will be returned from the pick command. I modified your example to show this:
Code:
import viz
import vizact

#Sample Environment
ground = viz.add('tut_ground.wrl')
ground.tag = "You missed clicking on a box."

class exampleObject(viz.VizNode):	#Example class containing a mesh
	def __init__(self,classTag,geometryTag,x,y,z,color):

		model = viz.add('box.wrl')
		viz.VizNode.__init__(self,model.id)

		self.class_tag = classTag
		self.geometry_tag = geometryTag
		self.setPosition(x,y,z)
		self.color(color)
		self.setScale(.333,.333,.333)

	def printTag(self):
		print self.class_tag,self.geometry_tag

#Creating some objects
A = exampleObject("classA","geometryA",-.5,1.6,2,viz.RED)
B = exampleObject("classB","geometryB",0,1.6,2,viz.BLUE)
C = exampleObject("classC","geometryC",.5,1.6,2,viz.GREEN)

def clickPick():	#Pick an object
	mesh = viz.pick()
	if isinstance(mesh,exampleObject):
		mesh.printTag()

vizact.onmousedown(viz.MOUSEBUTTON_LEFT, clickPick)	#Pick an object on Left-click

viz.go()
Reply With Quote