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

    Posts

    Recent Best Controversial
    • RE: Remove_observer bug?

      It's a pseudo-code. The actual code implies that observer object is a class instance variable:

      
      class Scene
      
        attr_accessor(;observer)
      
        def initialize
          @observer = MyEntitiesObserver.new
        end
      
        def observe
          Sketchup;;active_model.definitions.each do |definition|
            definition.entities.add_observer @observer
          end
        end
      
        def unobservre
          Sketchup;;active_model.definitions.each do |definition|
            definition.entities.remove_observer @observer
          end
        end
      
      end
      
      
      posted in Developers' Forum
      fuzzybroF
      fuzzybro
    • Remove_observer bug?

      Hi,

      I have found following strange behaviour:

      I have one EntitiesObserver object and multiple definitions which are bound to the very same EntitiesObserver:

      
        observer = MyEntitiesObserver.new
        Sketchup;;active_model.definitions.each do |definition|
          definition.entities.add_observer observer
        end
      
      

      and it works OK.

      But when I try to remove observer from the entities I'm able to remove it only from the first definition in the list. Other definition.entities.remove_observer(observer) are giving me the 'false' result and entities are still being observed by this observer.

      How do I properly unobserve multiple objects pointing to a single observer?

      posted in Developers' Forum
      fuzzybroF
      fuzzybro
    • RE: How to know if user has stopped orbiting camera?

      Thanks, Thom!

      Solved it using timer to merge quick calls and camera.xaxis to determine if OrbitTool was used

      
      class MyViewObserver < Sketchup;;ViewObserver
      
        def initialize
          #used to determine if camera has been rotated around z axis or not
          @old_xaxis = nil
          @update_timer_id = -1
          @update_delay = 0.07 # seconds
        end
      
        def onTimerDone
          @update_timer_id = -1
      
          # DO UPDATE STUFF HERE
        end
      
        def onViewChanged(view)
          return if !view
      
          if camera.xaxis != @old_xaxis
            UI.stop_timer(@update_timer_id) if @update_timer_id != -1
            @update_timer_id = ;;UI.start_timer(@update_delay, false) {onTimerDone}
            @old_xaxis = camera.xaxis
          end
      
        end 
      
      end
      
      
      
      posted in Developers' Forum
      fuzzybroF
      fuzzybro
    • RE: How to know if user has stopped orbiting camera?

      @chris fullmer said:

      Inside your own tool, you use the .resume and .suspend methods. suspend will tell you if the user has started using orbit or pan, and resume will tell you when you are back into your tool.

      http://www.sketchup.com/intl/en/developer/docs/ourdoc/tool.php#resume

      Thanks! Tried that approach. Unfortunately one would need to .resume custom tool manually or by some specific event which I didn't manage to find so I sticked with the time solution.

      posted in Developers' Forum
      fuzzybroF
      fuzzybro
    • RE: How to know if user has stopped orbiting camera?

      Maybe something is wrong, but I don't get any onToolStateChanged messages when using Orbit Tool. I do get them for a move tool though.

      posted in Developers' Forum
      fuzzybroF
      fuzzybro
    • How to know if user has stopped orbiting camera?

      Hi all,

      is there a way to know if User has stopped using OrbitTool to navigate camera?
      Or some way to know that Mouse Up event occurred, that might help but I'm not sure how to track it.

      I need to know if this event occurred to get transformations of instances whose definitions have always_face_camera flag after the camera has changed. I can do this by listening to ViewObserver but onViewChanged event fires too often.

      posted in Developers' Forum
      fuzzybroF
      fuzzybro
    • RE: ComponentInstance global transformation problem

      False alarm - it was a bug in my code. Sorry about that, everything works like a charm.

      posted in Developers' Forum
      fuzzybroF
      fuzzybro
    • RE: ComponentInstance global transformation problem

      hmmm.. something goes wrong, I can reproduce this behaviour only in half of the runs.. please, never mind this message till I'll figure out the problem.

      Cheers,
      V.

      posted in Developers' Forum
      fuzzybroF
      fuzzybro
    • RE: ComponentInstance global transformation problem

      @tt_su said:

      @fuzzybro said:

      So I have identical inst3 transformations for both selected and deselected cases but inst1 and inst2 transformations are different in case of inst3 being selected and deselected.

      You say selected, but do you mean open?
      Selection doesn't affect transformation at all.

      Hi Thomas,

      This instance isn't opened, at least I don't open it myself but maybe SketchUp performs some sort of similar operation while creating a new Definition, Instance and placing components into it.

      I'm using following code to get transformations of scene entities after new ComponentDefinition and Instance was created:

      
          @model = Sketchup.active_model
          # close all active edit sessions to prevent crashes
          while (!@model.active_path.nil?)
            @model.close_active
          end
          @model.selection.clear
            
          # recursive function to go through all of the instances
          export_component(@model.entities)
      
          ... 
      
          def export_component(entities)
      
            if entities.class == Sketchup;;ComponentInstance
              return if entities.hidden? or !entities.layer.visible?
              # remember entityID, get instance local transformation and use it somehow
              entity_list = definition.entities 
            else
              entity_list = entities
            end
      
            entity_list.each { |entity| 
              if entity.layer.visible?
                export_component(entity) if !entity.hidden?          
              end
            }
          end
      
      

      This way I'm getting all the local transformations and the hierarchy of the model. Then I just have to go through the hierarchy and accumulate local matrices to get the global matrix as I described earlier.

      But when I try to track changes via EntitiesObserver on create new component event I get 2 calls of onElementRemoved which removes instances inst1 and inst2, 1 call of onElementAdded, which creates inst3 and 2 calls of an onElementModified - one for ComponentIstance which has been added and one for ComponentDefinition for this instance. Oddly enough, I don't get any events for inst1 and inst2 as they have been removed before creating new component but they are present in new ComponenDefinition.entities. In onElementAdded I'm getting the transformation of a newly created inst3 and getting transformations of child Instances inst1 and inst2 which are present in the definition of inst3. At this stage I'm getting completely different transformations for inst1 and inst2 which results in a wrong global transformation when I' doing the multiplication.

      I think than at onElementAdded call stage inst1 and inst2 might have not changed their matrices from model root space to inst3 local space, I'll check it in couple of minutes and report you in that.

      But the other question is why I'm failing to receive events that removed instances inst1 and inst2 have been added or modified? I'm adding an EntityObserver to a newly created definition of an inst3 but don't receive any messages. I guess that I could use these events to get a proper matrices of a newly created inst1 and inst2 in the inst3 space.

      posted in Developers' Forum
      fuzzybroF
      fuzzybro
    • ComponentInstance global transformation problem

      Hi all,

      I have a simple situation when I have 2 ComponentInstances selected in the editor and I'm making a new Component out of them. The problem is that I'm unable to calculate a proper global transformation for each instance in the definition.

      Say, I had two instances of a one definition:

      model.entities -> [inst1, inst2]
      

      Then I select them and make a new component, so model looks like this:

      model.entities -> [inst3]
      inst3.definition.entities -> [inst1, inst2]
      

      Then i simply need to go through the hierarchy to get global transformations:

      glob1 = inst3.transformation * inst1.transformation
      glob2 = inst3.transformation * inst2.transformation
      

      This works fine when I'm making a new component, deselect it and go through all of the entities. But everything goes wrong when the component is being active. I know that SketchUp has an edit_transformation space for all the model.active_entities but it is inst3 that is active. Inst3 is placed in the model root and the edit_transformation is an identity matrix. So I have identical inst3 transformations for both selected and deselected cases but inst1 and inst2 transformations are different in case of inst3 being selected and deselected. How do I get global transformations for inst1-2?

      posted in Developers' Forum
      fuzzybroF
      fuzzybro
    • RE: How to get Model Entities change event once?

      Thanks, Dan!

      Your idea worked out very well using "onTransactionCommit" event of the Model Observer. On every commit event I simply reset the "changed" flag and then do the rest as you proposed.

      posted in Developers' Forum
      fuzzybroF
      fuzzybro
    • RE: How to get Model Entities change event once?

      Thanks for the detailed answer, but I'm afraid that won't work properly: once a model is opened the @changed flag will be set to 'false' which is good, but when one will change model.entities it will get to the "# DO SOMETHING HERE" section only once. To set @changed to 'true' again I'll have to open/create a new model, but I need to track if this very model is changed per event. I guess it wont be possible to track the creation of new faces/instances in the model.entities that way. Please correct me if I'm wrong.

      posted in Developers' Forum
      fuzzybroF
      fuzzybro
    • RE: How to get Model Entities change event once?

      oddly enough, I don't see a proper observer which corresponds to def onElementAdded(model). Which one should I use? EntitiesObserver? I've noticed that PagesObserved also has a onElementAdded callback, but like EntitiesObserver it throws 2 variables: entities and entity.

      posted in Developers' Forum
      fuzzybroF
      fuzzybro
    • How to get Model Entities change event once?

      Hello all,

      I'm trying to track if faces located in the model node had been modified (i.e. model.entities collection has been changed). I can track changes via EntitiesObserver but I'm receiving too many calls. It would be just great to get only one event telling that model itself or model.entities had changed. Is there a way to do this?

      Regards,
      Bro

      posted in Developers' Forum
      fuzzybroF
      fuzzybro
    • RE: &quot;Enter&quot; key is not working in SU WebDialogs. Bug?

      Ah, so simple 😳
      Thank you guys!

      posted in Developers' Forum
      fuzzybroF
      fuzzybro
    • &quot;Enter&quot; key is not working in SU WebDialogs. Bug?

      Hello,

      I've encountered a problem while making a GUI for a SketchUp plugin. I need to get an input confirmation from the user by pressing "Enter key", but I have found out that no KeyDown event is firing in SketchUp WebDialogs, but it is firing in a regular browser (IE/Chrome/Firefox)

      the simple code if here:

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml;lang="en">
        <head>
          <meta http-equiv="content-type" content="text/html; charset=utf-8" />
          <!--<meta http-equiv="X-UA-Compatible" content="EmulateIE8"> -->
          <title>Test Window</title>
      
          <script type="text/javascript">
      
            document.onkeypress = function (e) { 
              e = e || window.event; 
              var charCode = e.charCode || e.keyCode;
              if(charCode == 13) {
                alert("key pressed");
              }			  
          };		
          </script>
      
        </head>
        <body>
        </body>
      </html>
      

      Is it a common thing or I'm the only one who is getting the restriction?
      I've checked this behaviour in SketchUp 8 and 2013 on Win7 and Win8 and have got consistent results.
      How WebDialog web browser is different from regular IE on the system?

      posted in Developers' Forum
      fuzzybroF
      fuzzybro
    • 1
    • 2
    • 2 / 2