Hi Jeff,
Its really difficult for me to produce an example that replicates my error. I have attached my code with as short as possible. As I am using the vizconnect tool. I have also attached the vizconnect_desktop.py
my code is
Code:
import csv
import viz
import vizfx
import vizconnect
import vizact
import makingCSVFile
import zspace
import vizshape
import vizcam
import vizinfo
import viznet
import vizinput
from tools import collision_test
filePath = vizinput.fileOpen(filter=[('DAE Files','*.dae'),('OSG Files','*.ive;*.osgb;*.osg'),('VRML Files','*.wrl'),('All File','*.*')],directory='3DModels')
logoss1=None
Listchilderen=[]
GrabedObject=None
ModelsList=[]
ModelsList.append(logoss1)
DissasembeldPart=False
models=None
grabItems=None
class ExplosiveModel(viz.VizNode):
""" creates a model with a given dae file and gets parts and moves them on specified axes """
def __init__(self, rowData):
self.isu = vizfx.addChild(filePath)
logoss1 = self.isu
Listchilderen = logoss1.getNodeNames()
viz.VizNode.__init__(self, self.isu.id)
self.scale = .035125 #this scale is determined by doc (dividing model size by .035, we get desired size)
self.isu.setScale([self.scale]*30)
self.current = 0 #index of current
self.rowData = rowData[:]
self.layerParents = []
self.partDict = {}
for tool in vizconnect.getToolsWithMode('Grabber'):
tool.getRaw().setCollisionTester(collision_test.Distance(node=tool.getRaw(), distanceThreshold=1000))
def initZSpace():
import zspace
viz.setMultiSample(8)
viz.clearcolor(viz.SLATE)
#initialize zSpace display
display = zspace.init()
#Scale up the zSpace display to avoid having to
#scale down all the models to fit within the display viewport
display.setScale(200)
#save handle to wand tracker
wandTracker = zspace.getWandTracker()
wandTracker.setLedEnabled(True)
SEND_UPDATE_TIMER = 1
UPDATE = viznet.id('update')
CLIENT_DISCONNECTED = viznet.id('client_disconnected')
CHAT = viznet.id('chat')
SERVER_NAME=viz.input('Enter Server Name')
while not viznet.client.connect(SERVER_NAME,port_in=14951,port_out=14950):
if viz.ask('Could not connect to ' + SERVER_NAME + ' would you like to try another?'):
SERVER_NAME=viz.input('Enter Server Name')
else:
viz.quit()
break
#___________________________________________________________________________________
#-----------------------------------------------------------------------------------
def update(e):
# need to edit this
global grabbedObject
global grabItems,models, filePath
global ModelsList,logoss1,DissasembeldPart,Listchilderen, xmodel
if e.client != viz.getComputerName():
try:
if e.DisAssPart==True and DissasembeldPart==False:
for i in Listchilderen:
if i.startswith("Inst"):
xmodel=logoss1.getChild(i)
ModelsList.append(xmodel)
models = viz.cycle(ModelsList)
grabItems = set(models)
DissasembeldPart=True
e.GrabObj.setPosition(e.pos)
e.GrabObj.setEuler(e.ori)
elif e.DisAssPart==False and DissasembeldPart==True:
for i1 in ModelsList:
i1.remove()
logoss1.remove()
logoss1 = viz.add(filePath)
logoss1.setPosition([0,0,0])
logoss1.setScale([0.1,0.1,0.1])
models = viz.cycle([logoss1])
grabItems = set(models)
DissasembeldPart=False
e.GrabObj.setPosition(e.pos)
e.GrabObj.setEuler(e.ori)
else:
e.GrabObj.setPosition(e.pos)
e.GrabObj.setEuler(e.ori)
except KeyError:
print 'errooooooooor'
#print '-------------update client'
viz.callback(UPDATE,update)
#___________________________________________________________________________________
#-----------------------------------------------------------------------------------
def client_disconnected(e):
viz.callback(CLIENT_DISCONNECTED,client_disconnected)
#___________________________________________________________________________________
#-----------------------------------------------------------------------------------
def sendUpdate():
global GrabedObject, DissasembeldPart
if GrabedObject!=None:
ori= GrabedObject.getEuler()
pos = GrabedObject.getPosition()
GrabObj=GrabedObject
DisAssPart=DissasembeldPart
viznet.client.sendAll(UPDATE,client=viz.getComputerName(),pos=pos,ori=ori,GrabObj=GrabObj,DisAssPart=DisAssPart )
vizact.ontimer(.001,sendUpdate)
#___________________________________________________________________________________
#-----------------------------------------------------------------------------------
def onStopServer(e):
viz.quit()
viz.callback(viznet.SERVER_DISCONNECT_EVENT,onStopServer)
#___________________________________________________________________________________
#-----------------------------------------------------------------------------------
#alternatively, you could use the desktop
vizconnect.go('vizconnect_desktop.py') #desktop vizconnect setup
rowData = []
#read csv data for part numbers per step
with open('names.csv', 'rb') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
rowData.append([row[0], row[1], row[2].split()])
print rowData
#Set the animation speed and mode
SPEED = 1200
MODE = viz.SPEED
ROTATE_MODE = viz.PIVOT_ROTATE
def AnimateView(pos):
global GrabedObject
action = vizact.goto(pos,SPEED,MODE,pivot=vizconnect.getViewpointDict(),rotate_mode=ROTATE_MODE)
GrabedObject = vizconnect.getTransport().getRaw()
vizconnect.getTransport().getNode3d().runAction(action)
model = ExplosiveModel(rowData)
model.setScale([0.02]*3)
viz.clearcolor(viz.GRAY) #change background color if desired
#Start off by moving to the first location
AnimateView([0,2,-15])