sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Edge observer

    Scheduled Pinned Locked Moved Developers' Forum
    2 Posts 1 Posters 564 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • inteloideI Offline
      inteloide
      last edited by

      Hello,

      For one of my plugin, I want to catch when a component is modified (ie entities inside the component are moved, stretched, erased, added, etc).

      My problem is to trigger an observer when moving an edge (single edge not attached to a face) using moving tool.

      Do do so, I placed an observer on model to catch when the active path is changed, and then add on observer on entities within active_entities :

      
      class MyModelObserver < Sketchup;;ModelObserver
      	
      	@@observers = {}
      	@@previous_path=nil
      
      
      	def onActivePathChanged(model)
      		puts "onActivePathChanged "+Sketchup.active_model.active_entities.to_s
      		#remove previous observer if exist
      			if @@previous_path!=nil then
      				puts "Remove observers of "+@@previous_path.to_s
      				p @@previous_path.remove_observer(@@observers[@@previous_path])
      				@@previous_path=nil
      			end
      		
      		#Quit if active_path is nill (no group or component is opened)
      			return if !Sketchup.active_model.active_path
      		
      		#define observer object and try to add it to active_entities
      		#if it is successfully added, update class variable @@observers
      			observer = MyEntitiesObserver.new()
      			if Sketchup.active_model.active_entities.add_observer(observer)
      				#Save observers data
      					@@observers[Sketchup.active_model.active_entities] = observer
      					@@previous_path=Sketchup.active_model.active_entities
      				
      				#Add observers to each entity of active_entities
      					for entity in Sketchup.active_model.active_entities
      						entity.add_observer(MyEntityObserver.new)
      					end
      			end
      	end
      end
      
      
      class MyEntityObserver < Sketchup;;EntityObserver
      	def onEraseEntity(entity)
      		puts "onEraseEntity; #{entity}"
      	end
      	def onChangeEntity(entity)
      		puts "onChangeEntity; #{entity}"
      	end
      end
      
      class MyEntitiesObserver < Sketchup;;EntitiesObserver
      	def onElementAdded(entities, entity)
      		puts "onElementAdded "
      	end
      	def onElementModified(entities, entity)
      		puts "onElementModified "
      	end
      	def onElementRemoved(entities, entity_id)
      		puts "onElementRemoved"
      	end
      	def onEraseEntities(entities)
      		puts "onEraseEntities" 
      	end
      	
      	def onChangeEntity(entity)
      	  puts "onChangeEntity; #{entity}"
      	end
      end
      

      Then running the script :

      Sketchup.active_model.add_observer(MyModelObserver.new)
      

      I cannot see any "modification" observer triggers when when moving a simple edge not attached to a face, within a component...

      If someone can help me...
      Inteloide

      Humanity will do a huge step when the IT professionals will understand that computers are tools...

      1 Reply Last reply Reply Quote 0
      • inteloideI Offline
        inteloide
        last edited by

        Well, a start of explaination and solution, here :
        http://forums.sketchup.com/t/edge-change-observer/8184 :

        Put an observer on edge.start and edge.end

        Thanks TT !

        Humanity will do a huge step when the IT professionals will understand that computers are tools...

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement