For Observer onChangeEntity, is there any clue about modification?

:heart:


Yes I agree. Attach a dictionary to the “watched” instance (transforms only apply to group and component instances,) with a "transform" attribute.

To purposely “watch” an instance’s transform, call …

    def watch_entity(entity, observer)
      save_transform(entity) if entity.respond_to?(:transformation)
      entity.add_observer(observer)
    end

    def save_transform(entity, hash = nil)
      if entity.respond_to?(:transformation)
        # Build the transform data hash if not passed as 2nd arg:
        hash = transform_properties(entity.transformation) if hash.nil?
        # Must convert hash to array of nested key/value pair arrays.
        # API dictionaries cannot store symbol keys, only string keys:
        data = hash.transform_keys(&:to_s).to_a
        entity.set_attribute(DICT, "transform", data)
      end
    end

Example, onChangeEntity callback using the transform_properties method from the “How to compare transformations” topic thread …

    def onChangeEntity(entity)
      if entity.respond_to?(:transformation)
        prev = entity.get_attribute(DICT,"transform",nil)
        # Will be nil if no "transform" attribute exists.
        if prev # an array written by "save_transform" method
          hash  = prev.to_h.transform_keys(&:to_sym)
          trans = transform_properties(entity.transformation)
          unless hash == trans # Use Hash#== not Object#!=
            # The entity's transform was changed.
            # ... do something here ...
            # Then update the dictionary with new data:
            save_transform(entity, trans)
          end
        end
      else
        # check other things
      end
    end