Jump to content

findVertexAttrib return


majikal

Recommended Posts

Hi!

if geo.findVertexAttrib("uv") == ():
    uv_attrib = geo.addAttrib(hou.attribType.Vertex, "uv" , vertPos )
else:
    uv_attrib = geo.findVertexAttrib("uv")

It say that findVertexAttrib return None if attribute doesnt exist. I tried to compare it to () and "None" but nothing works.

To what should i compare return of findVertexAttrib to see if it exist. What is None? Empty touple?

ty

Link to comment
Share on other sites

Comparing to () will definitely not give you the correct result because an empty tuple is not equal to None. Comparing to None should work no problem; it always has for me.

>>> geo.findVertexAttrib("asdf") is None
True
>>> geo.findVertexAttrib("asdf") == None
True
>>> geo.findVertexAttrib("asdf") == ()
False
>>> geo.findVertexAttrib("uv")
<hou.Attrib Vertex 'uv' (3 Floats) of geometry in /obj/geo1/texture1>

If you want to test for an attribute and if not create it then your code should work fine. I personally always use this since it's slightly less work.

uv_attr = geo.findVertexAttrib("uv")
if uv_attr is None:
    geo.addAttrib(hou.attribType.Vertex, "uv", (0.0, 0.0, 0.0))

Edited by graham
Link to comment
Share on other sites

thank you... it works..

i looked it up and saw that none is type.

is it possible to solve the same problem with try except

something like this:

try:
    uv_attrib = geo.addAttrib(hou.attribType.Vertex, "uv" , vertPos )
except hou.OperationFailed:
    uv_attrib = geo.findVertexAttrib("uv")

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...