For the obj files, it should be in the following format:
*Correct Version* (This obj file actually contains the 'vertex' positional 
values and so the first line always contains this v character then vn... )

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





*Wrong Version* (This is about the same format when exporting of obj.)
# This file uses centimeters as units for non-parametric coordinates.

mtllib aaa.mtl
g default
v -7.768849 -7.768849 7.768849


And the reason that I have coded for it to read and check if the first 
character is 'v', is to counter the function that was previously written.
Previously, my code for the processLine is something like this:

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)
This has actually caused me some issues, thus I wrote it this way. Maybe it 
is not a good idea after all?




On Thursday, September 18, 2014 7:55:57 PM UTC+8, Justin Israel wrote:
>
> 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? 
> On 18/09/2014 9:55 PM, "likage" <[email protected] <javascript:>> wrote:
>
>> I am still having some trouble where my UI just closes when it is hitting 
>> upon a warning where the UI should still be present for users to go back 
>> and change some stuff.
>>
>> In the following are three functions:
>>
>>    - chkBox : when enabled, it will also enables the textfield. So if 
>>    the textfield is blank, it will prompt a warning else it will carry on.
>>    - readFileIn : the function for the Creation button in my UI, so 
>>    supposedly if everything is working fine and dandy, it should creates the 
>>    locator and group it else it will halt any if the obj parse is wrong.
>>    - ReadObjCloud : parses the information of the obj file. So if the 
>>    first character is not V, it will prompts and Invalid warning. But this 
>>    portion seems to be the one giving me the most problem, as while it is 
>> able 
>>    to differentiate whether there are V characters in the first character, 
>> the 
>>    ui closes on me instead of the user going back to the ui and reimport a 
>>    working obj file...
>>    
>> Even though it seems to be 'working', I have also got the following error 
>> in my editor:
>>
>> #
>> # 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 # 
>>
>>
>> This is my code, and I think it is happening somewhere in either of the 
>> three functions but I am unable to figure it out the hell of me.
>>
>> 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")
>>
>>
>>
>>  -- 
>> 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/ab8ff867-ca94-4e61-8a51-6b1722fe350a%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/python_inside_maya/ab8ff867-ca94-4e61-8a51-6b1722fe350a%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/913eae5a-9b77-43da-89d8-4e11c3a73ebd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to