#
# Error: Please import in a relevant Point Cloud Obj file
# Traceback (most recent call last):
# File "/user_data/test/chan.py", line 202, in readFileIn
# ReadObjCloud(self.finalObjPath)
# File "//user_data/test/chan.py", line 261, in __init__
# raise Exception( "Please import in a relevant Point Cloud Obj file\n")
# Exception: Please import in a relevant Point Cloud Obj file #
class CustomNodeTranslator(OpenMayaMPx.MPxFileTranslator):
...
...
def chkBox(self):
importCloudCheck = cmds.checkBox(self.cloudCheckbox, query=True, value=True)
finalObjPath = cmds.textField(self.waveFileAddress, query=True, text=True)
if(importCloudCheck == 1):
if finalObjPath != "":
ReadObjCloud(finalObjPath)
return True
else:
return False
else:
print ("Importing in Camera only")
return True
def readFileIn(self, *args):
if self.chkBox():
chanRotationOrder = cmds.optionMenuGrp(self.rotationOrderControl, value=True, query=True)
self.importTheChan = ChanFileImporter(chanRotationOrder)
try:
for line in self.fileHandle:
self.processLine(line)
self.fileHandle.close()
self.closeWindow()
except:
sys.stderr.write( "Failed to read file information\n")
raise
else:
cmds.warning("Input a valid Point Cloud Path or checked off the Import option ")
class ReadObjCloud():
def __init__(self, objPath):
fileHandle = open(objPath,"r")
filePath = os.path.basename(fileHandle.name)
fileName = os.path.splitext(filePath)[0]
print fileHandle.readline()[0]
if fileHandle.readline()[0] == "v":
for line in fileHandle:
brokenString = string.split(line)
cmds.spaceLocator(name = "camera1_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)
fileHandle.close()
cmds.select("camera1_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, "camera1, add=True)
cmds.group(n="cameraTrack")
cmds.scale(10, 10, 10)
else:
raise Exception( "Please import in a relevant Point Cloud Obj file\n")
This looks like it should be pretty easy to narrow down, since it is obviously in the ReadObjCloud constructor.
You read one line and print the first character. Is that a throw away line or are you accidentally advancing your file handle past the first line when you didn't meant to? Is the first character of the second line supposed to be "v"? Why not just print the file path you are opening and print the second line to confirm it is what you expect?
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ab8ff867-ca94-4e61-8a51-6b1722fe350a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
fileHandle.readline()[0] == "v"
raise Exception( "Please import in a relevant Point Cloud Obj file\n")
v -0.6110637188 0.0093309134 8.1327419281
vn -0.2112581345 -0.7280599689 -0.6521492792
v 0.7267020941 0.0233836491 8.6937112808
vn -0.0528684395 -0.1126191291 -0.9922307493
# This file uses centimeters as units for non-parametric coordinates.
mtllib aaa.mtl
g default
v -7.768849 -7.768849 7.768849
def __init__(self, objPath):
try:
fileHandle = open(objPath,"r")
filePath = os.path.basename(fileHandle.name)
fileName = os.path.splitext(filePath)[0]
for line in fileHandle:
self.processLine(line)
fileHandle.close()
except:
sys.stderr.write( "Failed to read file information\n")
raise
# 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)
def processLine(self, line):
if(line[0] == "v"):
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)
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
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!!!"
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.
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/091119de-fb86-451b-9162-9fe93ef592a7%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
For now, just call self.fileHandle.seek(0) at the start of your processLine function.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/64c719fb-6b35-4e36-887b-190ad6c5e47b%40googlegroups.com.
In your logic you should readline ().strip () then split the line by white space and if splits [0] is 'v' then use splits[1] splits[2] splits[3] as X y z coordinates
On a note. Obj format usually just dumps groups of types together
All v together all vs together all f together mainly because most sections refer to other sections by Id
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3Tf8RNYnZkcwPzthHxJ5q_go151ET%2BQ%2Bggh7OFHXh5Zw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM9RXoLEKKZjotw%3D6XbuNdtBS57UwOLfxuh7NOopp69CMC2A0g%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/091119de-fb86-451b-9162-9fe93ef592a7%40googlegroups.com.
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 python_inside_maya+unsub...@googlegroups.com.
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.
--
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 python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3Tf8RNYnZkcwPzthHxJ5q_go151ET%2BQ%2Bggh7OFHXh5Zw%40mail.gmail.com.
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 python_inside_maya+unsub...@googlegroups.com.
for char in fileHandle.readline()[0]:
if char.startswith("v"
):
fileHandle.seek(0)
self.processLine()
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d540641c-fda2-438c-9ace-2d1c75aa540c%40googlegroups.com.To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
ok... by the way, correct me if I am wrong, in your code, when I tried it, it does not run pass the __init__ function?
Cause it just seems to stop there and not proceeding to print out the verts information. Am I missing a line somewhere?
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/8e121381-5f80-4a5a-9f56-36dd5e2570b0%40googlegroups.com.