python states and setAttribValue

   1055   4   1
User Avatar
Member
55 posts
Joined: 3月 2016
Offline
Hello

I am working in a HDA, and using Python Viewer States... I would like to modify (write) a primitive attribute (primnum 0 for example) with the mouse wheel.
so my code is:

    def onMouseWheelEvent(self, kwargs):
        ui_event = kwargs["ui_event"]
        state_parms = kwargs["state_parms"]
        dev = ui_event.device()
        self.myValue += dev.mouseWheel()/100
        myPrim = self.node.node("myNode").geometry().prim(0)
        myPrim.setAttributeValue("myAttr", self.myValue)

but it gives me an error:
... AttributeError: 'Polygon' object has no attribute 'setAttributeValue'

but the polygon class has that method, why it does not work?

how can I do write values on primitives using python viewer states?.. any advice?

Thanks you


I
Gerardo Castellanos
www.gerardocastellanos.com
User Avatar
Member
30 posts
Joined: 11月 2016
Offline
Maybe setAttribValue instead of setAttributeValue will work?

https://www.sidefx.com/docs/houdini/hom/hou/Prim.html [www.sidefx.com]
User Avatar
Member
8839 posts
Joined: 7月 2007
Offline
Gerardo Castellanos
but it gives me an error:
... AttributeError: 'Polygon' object has no attribute 'setAttributeValue'

but the polygon class has that method, why it does not work?
the method is called setAttribValue()

However even with correct method call I assume you will get permission error as its not allowed to modify geometry of SOP nodes with external scripts,( only Python SOP can modify its own geo during its cook)

So you may want to consider modifying a geometry stashed in a data parm on your HDA which can be then referenced in internal Stash SOP for example
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
55 posts
Joined: 3月 2016
Offline
ohh yep.. my bad, sorry... but even with the setAttribVale()... it says:

hou.GeometryPermissionError: Geometry is read-only.

as I said, I am running this script from a a Python HDA states... how can I modify it if it is read-pnly?
Gerardo Castellanos
www.gerardocastellanos.com
User Avatar
Member
8839 posts
Joined: 7月 2007
Offline
Gerardo Castellanos
ohh yep.. my bad, sorry... but even with the setAttribVale()... it says:

hou.GeometryPermissionError: Geometry is read-only.

as I said, I am running this script from a a Python HDA states... how can I modify it if it is read-pnly?
https://www.sidefx.com/forum/topic/98033/#post-430783 [www.sidefx.com]
Tomas Slancik
FX Supervisor
Method Studios, NY
  • Quick Links