hmm.. okay, bummer for me. I thought if in my processLine function, having it to read through all the lines in the self.fileHandle would be a different case scenario... Now I am totally lost...
On Friday, September 19, 2014 3:35:43 PM UTC+8, Justin Israel wrote: > > To be honest, that rewrite is doing a lot of strange things. > > You read the first character of the first line and loop over that single > character string to see if it starts with 'v'. At that point you have > burned the first line and won't process it. Then your processLine function > actually loops over the remaining lines. Is readline() doing what you think > it does? It doesn't always start from the beginning. Every time you read, > you advance the file handle. You would want to just read one character, and > check if it is 'v', and then use seek(0) to move the offset back to the > start and read all the lines. > > I can't write up an example at the moment, but if you don't figure it out > by the time I get to a computer, I will try and post something. > On 19/09/2014 4:42 PM, "likage" <[email protected] <javascript:>> wrote: > >> I rewrite my code again, will this be any better? >> By the way, I am still getting the part where my UI closes itself if it >> found an invalid file >> >> class ReadObjCloud(): >> """ read in vertex data from nuke 3d camera track """ >> >> def __init__(self, objPath): >> >> try: >> fileHandle = open(objPath,"r") >> self.fileHandle = fileHandle >> filePath = os.path.basename(fileHandle.name) >> fileName = os.path.splitext(filePath)[0] >> >> for char in fileHandle.readline()[0]: >> if char.startswith("v"): >> self.processLine() >> >> # Selects all the imported locators, grouped and >> transformed it >> cmds.select(camSel[0] + "_locator*") >> objGroup = cmds.group(n=("pointCloud_" + fileName)) >> cmds.xform(os=True, piv=(0, 0, 0)) >> cmds.scale(0.01, 0.01, 0.01) >> cmds.delete(constructionHistory=True) >> >> cmds.select(objGroup, camSel[0], add=True) >> cmds.group(n="cameraTrack") >> cmds.scale(10, 10, 10) >> >> else: >> self.noProcess() >> >> except: >> sys.stderr.write( "Failed to read file information\n") >> raise >> >> def processLine(self): >> >> for line in self.fileHandle: >> brokenString = string.split(line) >> >> # Creation of locators and they are named with the prefix of >> the imported camera >> cmds.spaceLocator(name = camSel[0] + "_locator", absolute= >> True, position=(\ >> float(brokenString[1])*100\ >> , float(brokenString[2])*100\ >> , float(brokenString[3])*100)) >> cmds.CenterPivot() >> cmds.scale(0.5, 0.5, 0.5) >> >> self.fileHandle.close() >> >> def noProcess(self): >> print "INVALID - Re-import again!!!" >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Python Programming for Autodesk Maya" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/python_inside_maya/091119de-fb86-451b-9162-9fe93ef592a7%40googlegroups.com >> >> <https://groups.google.com/d/msgid/python_inside_maya/091119de-fb86-451b-9162-9fe93ef592a7%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/64c719fb-6b35-4e36-887b-190ad6c5e47b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
