Jump to content

Python handle testing

Recommended Posts

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?



Link to comment

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?



Link to comment

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__ )


Link to comment
  • 3 weeks later...

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)

Link to comment

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.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...