Drag Box marker vs Drag Box path

Utilizing the following code below would like to use a Path instead,
I have not have had good result's , would line the marker to follow the path
Example box code below, would like too follow path ...
ideas comments


# Enter your Python code here # Register this macro as "autorun" to enable the plugin # This is the plugin implementation class DragBoxPlugin(pya.Plugin): def __init__(self, view): super(DragBoxPlugin, self).__init__() self.marker = None self.box = None self.start_point = None self.view = view def activated(self): pya.MainWindow.instance().message("Click on point to start dragging a box", 10000) def _clear_marker(self): if self.marker is not None: self.marker._destroy() self.marker = None def _update_marker(self): if self.marker is None: self.marker = pya.Marker(self.view) self.marker.line_style = 2 # short-dashed self.marker.vertex_size = 0 # no vertexes self.marker.set(self.box) def deactivated(self): self._clear_marker() pya.MainWindow.instance().message("", 0) def mouse_click_event(self, p, buttons, prio): if prio: if self.marker is None: self.box = pya.DBox(p, p) self.start_point = p.dup() # Note dup() which creates a copy we can store self._update_marker() self.grab_mouse() pya.MainWindow.instance().message("Drag the box and click again", 10000) else: self._clear_marker() self.ungrab_mouse() self.box_finished(self.box) return True return False def box_finished(self, box): # TODO: put in your code to do what you like to do with the box pya.MainWindow.instance().message("Box finished: " + str(box), 10000) b = str(box) c = re.split('[ ; , ) (]', b) #Get Box Coordinates x1 = c[1] y1 = c[2] x2 = c[3] y2 = c[4] print(f"x1:y1 = {x1},{y1} : x2:y2 = {x2},{y2} ") def mouse_moved_event(self, p, buttons, prio): if prio and self.marker is not None: self.box = pya.DBox(self.start_point, p) self._update_marker() return True return False # Implement a "plugin factory". # This object is asked to provide a plugin for each view class DragBoxPluginFactory(pya.PluginFactory): def __init__(self): super(DragBoxPluginFactory, self).__init__() self.has_tool_entry = True self.register(-1000, "drag_box", "Drag Box") def create_plugin(self, manager, root, view): return DragBoxPlugin(view) # Keeps the singleton instance instance = None # Create and store the singleton instance DragBoxPluginFactory.instance = DragBoxPluginFactory()

Comments

  • I'm not sure if I understand the problem.

    self.marker.set(self.box) should also work if you set a DPath object instead of a DBox.

    Doesn't it?

    Matthias

  • Matthias,

    Sorry the DragBox works as expected,
    I would like to be able to use a Path and follow the mouse clicks,
    instead of drawing a box it would draw a path .
    that make sense ...
    I have tried the DPath Object , I may be missing something or
    just not able to wrap my head or mouse around this

  • @Matthias

    Revisiting this thread as suggest I made changes this does not work like the Box
    I'm not sure if I understand the problem.

    self.marker.set(self.box) should also work if you set a DPath object instead of a DBox.

    Doesn't it?
    I am missing something ....

    import pya
    # Register this macro as "autorun" to enable the plugin
    
    # This is the plugin implementation
    
    class DragPathPlugin(pya.Plugin):
    
      def __init__(self, view):
        super(DragPathPlugin, self).__init__()
        self.marker = None
        self.box = None
        self.start_point = None
        self.view = view
    
      def activated(self):
        pya.MainWindow.instance().message("Click on point to start adding a path", 10000)
    
      def _clear_marker(self):
        if self.marker is not None:
          self.marker._destroy()
          self.marker = None
    
      def _update_marker(self):
        if self.marker is None:
          self.marker = pya.Marker(self.view)
          self.marker.line_style = 2   # short-dashed
          self.marker.vertex_size = 0  # no vertexes
        self.marker.set(self.box)
    
      def deactivated(self):
        self._clear_marker()
        pya.MainWindow.instance().message("", 0)
    
      def mouse_click_event(self, p, buttons, prio):
        if prio:
          if self.marker is None:
            self.box = pya.DPath(p ,p)   #-----> As Suggested 
            #self.box = pya.DBox(p, p)
            self.start_point = p.dup()  # Note dup() which creates a copy we can store
            self._update_marker()
            self.grab_mouse()
            pya.MainWindow.instance().message("Add Point to Path and click again", 10000)
          else:
            self._clear_marker()
            self.ungrab_mouse()
            self.box_finished(self.box)
          return True
        return False
    
      def box_finished(self, box):
        # TODO: put in your code to do what you like to do with the box
        pya.MainWindow.instance().message("Path finished: " + str(box), 10000)
    
      def mouse_moved_event(self, p, buttons, prio):
        if prio and self.marker is not None:
          self.box = pya.DPath(self.start_point, p)   #-----> As Suggested 
          #self.box = pya.DBox(self.start_point, p)
          self._update_marker()
          return True
        return False
    
    
    # Implement a "plugin factory". 
    # This object is asked to provide a plugin for each view
    
    class DragPathPluginFactory(pya.PluginFactory):
    
      def __init__(self):
        super(DragPathPluginFactory, self).__init__()
        self.has_tool_entry = True
        self.register(-1000, "drag_path", "Drag Path")
    
      def create_plugin(self, manager, root, view):
        return DragPathPlugin(view)
    
      # Keeps the singleton instance
      instance = None
    
    # Create and store the singleton instance
    DragPathPluginFactory.instance = DragPathPluginFactory()
    
Sign In or Register to comment.