sketchucation logo sketchucation
    • Login
    1. Home
    2. astrellon
    3. Posts
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    A
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 3
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: Change tool onElementAdded

      Yea it's still crashing for me, and it's strange that I can put a puts 'after select_tool' after the select_tool method call and see it output before Sketchup crashes.

      But this was only for in-house really, so we're just going to leave it for now. Thanks for you're help though thomthom!

      posted in Developers' Forum
      A
      astrellon
    • RE: Change tool onElementAdded

      Thanks, I didn't notice the DefinitionObservers, however they still had the same problems.
      This is the simplest example I have using both an EntitiesObserver and DefinitionObserver (with one commented out at the moment) and both result in a crash.

      The UI context menu at the bottom is just to show that the tool can be selected without crashing when done outside of an observer. Going by the fact that it crashes with even this, I'm going to assume that it's a bug and just live with it. The only other thing I could think of was some way of changing the tool after the observer had finished, but the threading wasn't playing nice.

      
      module Tool_test
      
      class TestTool
      	@@tool = TestTool.new
      	
      	def self.getTool()
      		return @@tool
      	end
      	def activate()
      		puts "Tool activated"
      	end
      end
      
      class MyDefObserver < Sketchup;;DefinitionObserver
        def onComponentInstanceAdded(definition, instance)
          Sketchup.active_model.select_tool TestTool.getTool()
        end
      end
       
      class MyDefsObserver < Sketchup;;DefinitionsObserver
        def onComponentAdded(definitions, definition)
      	definition.add_observer(MyDefObserver.new())
        end
      end
      
      Sketchup.active_model.definitions.add_observer(MyDefsObserver.new)
      
      class MyEntitiesObserver < Sketchup;;EntitiesObserver
        def onElementAdded(entities, entity)
          Sketchup.active_model.select_tool TestTool.getTool()
        end
      end
      
      #Sketchup.active_model.entities.add_observer(MyEntitiesObserver.new)
      
      UI.add_context_menu_handler do |menu|
        sub_menu = menu.add_item('Test Tool') {
          Sketchup.active_model.select_tool TestTool.getTool()
        }
      end
      
      end
      
      
      posted in Developers' Forum
      A
      astrellon
    • Change tool onElementAdded

      Hello,

      Are there any known issues with changing the current tool from an EntitiesObserver in the onElementedAdded callback? As currently when I try to do this it just crashes SU, I know the EntitiesObserver has plenty of issues, but I was hoping this wasn't going to be one of them.

      Basically I want to be able to change the current tool when a specific kind of component is added, checking if the component is the right one that I want is easy.

      I tried changing the tool in a Thread but the sleep functionality doesn't seem to work as expected, as it doesn't wake up again until the onElementAdded function is called again which is bizarre in itself.

      I also tried a onPlaceComponent ModelObserver which doesn't crash but it also doesn't do anything either.

      This is what the code boils down to.

      
      class MyObserver < Sketchup;;EntitiesObserver
        def onElementAdded(entities, entity)
          if (check_entity(entity))
            Sketchup.active_model.select_tool $my_tool
          end
        end
      end
      
      Sketchup.active_model.entities.add_observer(MyObserver.new())
      
      

      I tried searching on the forum for anything about changing the current tool from an observer and I didn't find anything.

      If this is a known issue/limitation then it's not the end of the world.

      Thanks

      posted in Developers' Forum
      A
      astrellon
    • 1 / 1