Gonda Posted March 21, 2015 Share Posted March 21, 2015 Hi All, So, I've been working on a script that uses vs.NextObj to iterate through a list of objects. I know that when it gets to the end of the list, according to the function reference, it will return NIL. The problem I'm running into is what exactly 'NIL' is and how to test for it. Canonically, testing for existence in Python uses: "if foo is None"...I've tried testing the returned handle again pretty much everything I can think of (0, 1, NIL, nil, Nil, False) and all of them fail...I did discover that if you try to type() the returned handle, it comes back as a member of class vs.Handle...is there a method of this class to test for existence? Cheers, -gonda Quote Link to comment
JBenghiat Posted March 22, 2015 Share Posted March 22, 2015 There are two ways to test for NIL. As you inferred, a handle object has attributes, so you can test varname.Handle = none. NIL is also defined as a member of vs, so test if the handle equals vs.NIL -- or possibly vs.NIL() -- I don't have the reference in frontof me. HTH, Josh Quote Link to comment
Gonda Posted March 22, 2015 Author Share Posted March 22, 2015 Thanks for the info Josh...I figured there was something like this...unfortunately, the class vs.HandleContainer doesn't seem to have a Handle (or HANDLE) method and all the permutations I've tried of vs.NIL generate undefined errors... I don't suppose you know of a documentation source that describe the internal object classes and there supported methods/variables? Cheers, -gonda Quote Link to comment
JBenghiat Posted March 23, 2015 Share Posted March 23, 2015 I had a chance to check my notes. Apparently vs.NIL isn't part of the final Python implementation. You can check if a handle !=None. If the functions returns a handle, that should evaluate as True. You can also check: if h != vs.Handle() Essentially, if the variable equals a new instance of the handle object, it is empty. (This was counterintuitive to me at first). The following will list the properties of a vs.Handle. Note that in vs, print will output to the Error Output dialog, so when this script raises an error, view the error message to see the output. theType = vs.Handle for a in dir(theType): if not a.startswith('__'): print( a + ' - ' + theType.__dict__[a].__doc__ ) -Josh Quote Link to comment
DomC Posted April 8, 2015 Share Posted April 8, 2015 The required constants in Python are True, False and None (NIL ist None) I got something like this in one of my python-script-testing, that works. tempHandle1 = vs.LNewObj() tempHandle2 = None objectHandle = vs.CreateCustomObjectPath('Part', tempHandle1, tempHandle2) Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.