def onMouseEvent(self, kwargs): """ Process mouse events """ ui_event = kwargs["ui_event"] device = ui_event.device() origin, direction = ui_event.ray() inputs = self.node.inputs() reason = ui_event.reason() # Only try intersecting geometry if this node has input geo_intersector = None if inputs and inputs[0]: geometry = inputs[0].geometry() geo_intersector = su.GeometryIntersector(geometry, scene_viewer=self.scene_viewer) isGeo = None if geo_intersector: isGeo = geo_intersector.intersect(origin, direction) position = geo_intersector.position if self.bSel == True: #Create/move point if LMB is down if device.isLeftButton(): if isGeo == True: self.start() self.setPoint(self.index, position) else: self.finish() elif self.MouseDragAction == True and self.bSel == False: if device.isLeftButton(): if isGeo == True and self.noSel == True: self.setPointPos(position, self.CurrentPt) if reason == hou.uiEventReason.Changed: # <--- when the position is changed or stopped dragging the point isnt selected anymore so when the user lets go of left mouse button. self.noSel = False self.CurrentPt = None else: self.finish() # Must return True to consume the event return self.bSel
Found 97 posts.
Search results Show results as topic list.
Technical Discussion » Viewer State noSelection?
- Shadowjonny
- 97 posts
- Offline
found a way that worked for me but dont know if it'll work for anyone else but my solution was:
Technical Discussion » Viewer State noSelection?
- Shadowjonny
- 97 posts
- Offline
Is there a noSelection event handle or a way to check no selected on scene view? should i use runSelectors from utils.py? or can i call onSelection somewhere else cause when i tried that i got an error: KeyError: ('selection',).
I need a way to get a True or False if there is something selected.
def onMouseEvent(self, kwargs): bType = self.onSelection(kwargs) #error: KeyError: ('selection',).
bType = self.node.geometry().selection() #prints out None
I need a way to get a True or False if there is something selected.
Technical Discussion » Convert Geo Selection to num?
- Shadowjonny
- 97 posts
- Offline
Ok got it my solution was this:
sel = kwargs['selection'] selection = sel.selections()[0] count = selection.numSelected() namept = selection.selectionString(geo) self.CurrentPt = int(namept)
Technical Discussion » Convert Geo Selection to num?
- Shadowjonny
- 97 posts
- Offline
How do i convert the selection i selected to a int number? i keep getting errors.
-TypeError: int() argument must be a string or a number, not ‘GeometrySelection’
-TypeError: %d format: a number is required, not GeometrySelection
trying to change teh position of the point selected with:
-TypeError: int() argument must be a string or a number, not ‘GeometrySelection’
-TypeError: %d format: a number is required, not GeometrySelection
trying to change teh position of the point selected with:
self.node.parmTuple("pt%d" % ptnum).set(position)// ptnum is the point i selected but says the second error // when i print sel = kwargs['selection'] i get the right number the one i selected.
self.CurrentPt = int(sel) //Gives me the first error
Technical Discussion » Viewer State Browser help
- Shadowjonny
- 97 posts
- Offline
Technical Discussion » Viewer State Browser help
- Shadowjonny
- 97 posts
- Offline
mabelzileShadowjonnykwargs is the dictionary holding the arguments passed to event handlers, it's documented documented here [www.sidefx.com]AlanZShadowjonny
Also quick question where can i find what “ui_event” does cause i see it with all the states, isnt that the same as hou.UIEvent but i get an error when i put that in the code snippet for the State.
Hi Jonny, not sure if I get your question, but I thinkindeed returns an instance of hou.UIEvent? You can then call its methods like hou.UIEvent.device(), hou.UIEvent.reason(), etc.kwargs["ui_event"]
Indeed i agree it is that but i want to know where i can get a list of things i can put inside kwargs. Cause i got an error when i put:node = kwargs['node'] #inside OnMouseEvent for State got an error
yet i see it in the code snippet for example in the python state viewer documentation.
Been stuck with trying to select a point in the viewport, what would you say im missing or doing wrong? been going through the selection_demo and it doesnt really help me understand how it got to be able to select from prim to points. Im trying to select self points not the points from the connected node in 0.
import hou import hdefereval import viewerstate.utils as su def _refreshDrawables(state): """ Creates a drawable for each point added. """ pointCount = state.pointCount() if state.clear_drawables: state.drawables = [] for index in range(pointCount): state.addDrawable(index) state.clear_drawables = False elif state.add_drawable: state.addDrawable(pointCount-1) state.add_drawable = False state.scene_viewer.curViewport().draw() state.post = True class State(object): def __init__(self, state_name, scene_viewer): self.state_name = state_name self.scene_viewer = scene_viewer self.pressed = False self.index = 0 self.node = None self.drawables = [] self.post = True self.clear_drawables = False self.add_drawable = False def onEnter(self,kwargs): """ Called on node bound states when it starts """ self.node = kwargs["node"] self.node.addEventCallback([hou.nodeEventType.ParmTupleChanged], self.nodeParmCB) # post a refresh to draw a point for the existing multiparms self.postRefreshDrawables(clear=True) def onExit(self,kwargs): """ Called when the state terminates """ self.node.removeAllEventCallbacks() def onInterrupt(self, kwargs): """ Called when the state is interrupted e.g when the mouse moves outside the viewport """ self.finish() def onMouseEvent(self, kwargs): """ Process mouse events """ ui_event = kwargs["ui_event"] device = ui_event.device() origin, direction = ui_event.ray() inputs = self.node.inputs() # Only try intersecting geometry if this node has input geo_intersector = None if inputs and inputs[0]: geometry = inputs[0].geometry() geo_intersector = su.GeometryIntersector(geometry, scene_viewer=self.scene_viewer) isGeo = None if geo_intersector: isGeo = geo_intersector.intersect(origin, direction) position = geo_intersector.position # Create/move point if LMB is down if device.isLeftButton(): if isGeo == True: self.start() self.setPoint(self.index, position) else: self.finish() # Must return True to consume the event return True def onDraw(self, kwargs): """ Called for rendering a state e.g. required for hou.AdvancedDrawable objects """ handle = kwargs["draw_handle"] for drawable in self.drawables: drawable.draw(handle) def onDrawInterrupt(self, kwargs): """ Called for rendering an interrupted state e.g. required for hou.AdvancedDrawable objects """ self.onDraw(kwargs) def PointSel(self,kwargs): sel = kwargs['selection'] ss = sel.selections() print(ss) def onSelection(self, kwargs): """ Called when a selector has selected something """ state_parms = kwargs["state_parms"] self.log(kwargs) # Must return True to accept the selection return self.PointSel(kwargs) def onStartSelection(self, kwargs): """ Called when a bound selector has been started """ self.log(kwargs) def nodeParmCB(self, **kwargs): """ Clear the point drawables if something has changed on the multiparm. """ self.postRefreshDrawables(clear=True) def postRefreshDrawables(self, **kwargs): """ Post a job on the UI queue to refresh the drawables. Only one job at a time can be posted. """ if self.post: try: self.clear_drawables = kwargs['clear'] self.add_drawable = False except: try: self.add_drawable = kwargs['add'] self.clear_drawables = False except: pass hdefereval.executeDeferred(_refreshDrawables, self) self.post = False def addDrawable(self, index): """ Creates a sphere drawable for each multiparm point. """ pt_name = "pt%d" % index parm_tuple = self.node.parmTuple(pt_name) geo = hou.Geometry() sph_verb = hou.sopNodeTypeCategory().nodeVerb("sphere") # We want a polygon mesh sphere sph_verb.setParms({ "type": 2 }) sph_verb.execute(geo, []) drawable = hou.GeometryDrawable(self.scene_viewer, hou.drawableGeometryType.Line, "pt_hilite", geo ) drawable.show(True) rad = 0.05 pos = hou.Vector3(parm_tuple[0].evalAsFloat(), parm_tuple[1].evalAsFloat(), parm_tuple[2].evalAsFloat()) parms = { 'translate': (pos[0],pos[1],pos[2]), 'scale': (rad, rad, rad), "color1": (1.0,0.0,0.0,0.7) } drawable.setParams(parms) self.drawables.append(drawable) def pointCount(self): """ This is how you get the number of instances in a multiparm. """ try: multiparm = self.node.parm("points") return multiparm.evalAsInt() except: return 0 def insertPoint(self): index = self.pointCount() multiparm = self.node.parm("points") multiparm.insertMultiParmInstance(index) return index def setPoint(self, index, position): self.node.parm("usept%d" % index).set(1) self.node.parmTuple("pt%d" % index).set(position) def start(self): if not self.pressed: self.scene_viewer.beginStateUndo("Add point") self.postRefreshDrawables(add=True) self.index = self.insertPoint() self.pressed = True def finish(self): if self.pressed: self.scene_viewer.endStateUndo() self.pressed = False def createViewerStateTemplate(): """ Mandatory entry point to create and return the viewer state template to register. """ state_typename = kwargs["type"].definition().sections()["DefaultState"].contents() state_label = "Pipe Setup System" state_cat = hou.sopNodeTypeCategory() template = hou.ViewerStateTemplate(state_typename, state_label, state_cat) template.bindFactory(State) template.bindIcon(kwargs["type"].icon()) KeyStart = su.hotkey(state_typename, 'Point Selection','1') template.bindGeometrySelector(prompt="Point Selection", allow_drag=True, quick_select=True, auto_start=True, use_existing_selection=False, consume_selection=True, secure_selection=hou.secureSelectionOption.Off, initial_selection="*", initial_selection_type=hou.geometryType.Points, geometry_types=(hou.geometryType.Points,), hotkey=KeyStart, name="PointSelector") return template
Edited by Shadowjonny - Jan. 21, 2020 16:28:32
Technical Discussion » Problem with a VEXpression code
- Shadowjonny
- 97 posts
- Offline
agimenez13
Hello, I just started using Houdini and I'm following a youtube tutorial to attempt a coiled wall.
I have added a point wrangle and I started writing the code in the Edit expression for.. manager, in the tutorial this window comes up as Edit String for.. I don't know if that makes a difference.
When I write the code the words don't seen to make links or change colour as they do in the tutorial I'm watching and I don't understand why this is happening.
If someone could assist I would truly appreciate it.
If you could paste the code, I'll take a look at it.
Technical Discussion » Viewer State Browser help
- Shadowjonny
- 97 posts
- Offline
Im sorry for so many question but python in houdini is confusing comapred to maya or blender for me somehow.
Technical Discussion » Viewer State Browser help
- Shadowjonny
- 97 posts
- Offline
Technical Discussion » Viewer State Browser help
- Shadowjonny
- 97 posts
- Offline
AlanZShadowjonny
but i want to know where i can get a list of things i can put inside kwargs
I see. kwargs is different for different methods in your State. Since it's a dictionary, you can just print out its keys to inspect.def onMouseEvent(self, kwargs): print kwargs.keys() # or "print (kwargs.keys())" in Python 3 #['node', 'state_flags', 'state_parms', 'ui_event']shouldn't generate an error though. Can u post a screenshot or something?kwargs['node']
just tested again and its working guess i typed it wrong when i first was typing it last night. My bad
Technical Discussion » Viewer State Browser help
- Shadowjonny
- 97 posts
- Offline
AlanZShadowjonny
Also quick question where can i find what “ui_event” does cause i see it with all the states, isnt that the same as hou.UIEvent but i get an error when i put that in the code snippet for the State.
Hi Jonny, not sure if I get your question, but I thinkindeed returns an instance of hou.UIEvent? You can then call its methods like hou.UIEvent.device(), hou.UIEvent.reason(), etc.kwargs["ui_event"]
Indeed i agree it is that but i want to know where i can get a list of things i can put inside kwargs. Cause i got an error when i put:
node = kwargs['node'] #inside OnMouseEvent for State got an error
yet i see it in the code snippet for example in the python state viewer documentation.
Edited by Shadowjonny - Jan. 11, 2020 14:14:36
Technical Discussion » Viewer State Browser help
- Shadowjonny
- 97 posts
- Offline
mabelzileShadowjonnymabelzile
Here's an OBJ state I created with the viewer state code generator.Image Not Found
Thank you for the video, got it working but how come the documentation does it different. Are they out of date? also i check what stateutils module has and theres nothing in it also, so why is it in the the code snippet for example?
Which example are you referring to ? stateutils is just a module importing everything from viewerstate.utils and was kept to avoid breaking clients code.
https://www.sidefx.com/docs/houdini/hom/python_states.html [www.sidefx.com] was following the “Loading a state from the Houdini path”. Also you are right it does lead to viewerstate.utils, but some how the documentation just somehow confuse me. Like i just want to know what each function does inside those modules and start building, i have to either test it out or open the modules with pycharm to see what it returns. Also quick question where can i find what “ui_event” does cause i see it with all the states, isnt that the same as hou.UIEvent but i get an error when i put that in the code snippet for the State.
ui_event = kwargs["ui_event"]
Technical Discussion » Viewer State Browser help
- Shadowjonny
- 97 posts
- Offline
mabelzile
Here's an OBJ state I created with the viewer state code generator.Image Not Found
Thank you for the video, got it working but how come the documentation does it different. Are they out of date? also i check what stateutils module has and theres nothing in it also, so why is it in the the code snippet for example?
Edited by Shadowjonny - Jan. 9, 2020 16:41:16
Technical Discussion » Viewer State Browser help
- Shadowjonny
- 97 posts
- Offline
So i been reading all of Writing custom viewer states in Python for the past 2 days and followed the Loading a state from the Houdini path steps. Got everything working but im not seeing anything pop up on the console like it said it would. Also would this be the ideal way to check what the mouse is hovered over?
Technical Discussion » Houdini console Message
- Shadowjonny
- 97 posts
- Offline
mabelzileShadowjonny
Would anyone know how to fix this warning? it pops up when i open a tab with Viewer State Browser or everytime i do open it.
Warning: There is no hotkey for h.pane.scene_view
It was fixed for 17.5. There is probably an invalid entry in $HOUDINI_USER_PREF_DIR/Houdini.keymap.overrides
using Houdini 18.0.318 currently
Edited by Shadowjonny - Jan. 9, 2020 04:11:48
Technical Discussion » Houdini console Message
- Shadowjonny
- 97 posts
- Offline
Would anyone know how to fix this warning? it pops up when i open a tab with Viewer State Browser or everytime i do open it.
Warning: There is no hotkey for h.pane.scene_view
Warning: There is no hotkey for h.pane.scene_view
Technical Discussion » Python Error using the Launcher?
- Shadowjonny
- 97 posts
- Offline
Technical Discussion » Houdini 18 crash
- Shadowjonny
- 97 posts
- Offline
Houdini Engine for Unreal » HDA for team not working
- Shadowjonny
- 97 posts
- Offline
Does everyone in the team need to have a houdini engine license to modify the HDA in UE4 cause it shows up for them but get an error when editing.
Technical Discussion » Just curious dynamic datatype set possible?
- Shadowjonny
- 97 posts
- Offline
Also if anyone is interested on my Pipe Generation that gets from Point A to B. Let me know and ill soon make a breakdown on the algorithm. https://www.artstation.com/artwork/Jl5Av0 [www.artstation.com]
-
- Quick Links