Viewer State noSelection?

   882   1   0
User Avatar
Member
97 posts
Joined: May 2015
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',).

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.
User Avatar
Member
97 posts
Joined: May 2015
Offline
found a way that worked for me but dont know if it'll work for anyone else but my solution was:

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
  • Quick Links