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

    maricanis

    @maricanis

    10
    Reputation
    1
    Profile views
    43
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    maricanis Unfollow Follow
    registered-users

    Latest posts made by maricanis

    • RE: [Plugin] UV Toolkit

      @thomthom said:

      Hm... I think this relate to projected textures. The API doesn't have good support for that type of mapping. πŸ˜•

      You are right. I've checked and these are projected textures.
      I know not much useful things in API on mapping of projected textures.

      Do you think there is some possibility to 'extract' that info and use it for pasting. Something with get_texture_projection() and set_texture_projection().

      Marija

      posted in Plugins
      M
      maricanis
    • RE: [Plugin] UV Toolkit

      Hi Thom,

      I was playing with UV Toolkit on a model from warehouse:
      https://3dwarehouse.sketchup.com/model.html?id=1c056259336d676cf69f18f886bbb404

      I tried to copy come textures from one face to another and get next error:

      @unknownuser said:

      Could not compute valid matrix from points
      C:/Users/Marija/AppData/Roaming/SketchUp/SketchUp 2016/SketchUp/Plugins/tt_uv_toolkit2/clipboard.rb:230:in position_material' C:/Users/Marija/AppData/Roaming/SketchUp/SketchUp 2016/SketchUp/Plugins/tt_uv_toolkit2/clipboard.rb:230:in block (2 levels) in paste_uv'
      C:/Users/Marija/AppData/Roaming/SketchUp/SketchUp 2016/SketchUp/Plugins/tt_uv_toolkit2/clipboard.rb:197:in each' C:/Users/Marija/AppData/Roaming/SketchUp/SketchUp 2016/SketchUp/Plugins/tt_uv_toolkit2/clipboard.rb:197:in block in paste_uv'
      C:/Users/Marija/AppData/Roaming/SketchUp/SketchUp 2016/SketchUp/Plugins/TT_Lib2/simpletask.rb:59:in block in run' C:/Users/Marija/AppData/Roaming/SketchUp/SketchUp 2016/SketchUp/Plugins/TT_Lib2/simpletask.rb:58:in each'
      C:/Users/Marija/AppData/Roaming/SketchUp/SketchUp 2016/SketchUp/Plugins/TT_Lib2/simpletask.rb:58:in run' C:/Users/Marija/AppData/Roaming/SketchUp/SketchUp 2016/SketchUp/Plugins/tt_uv_toolkit2/clipboard.rb:188:in paste_uv'
      C:/Users/Marija/AppData/Roaming/SketchUp/SketchUp 2016/SketchUp/Plugins/tt_uv_toolkit2/clipboard.rb:34:in block in <module:UV_Toolkit>' SketchUp:1:in call'

      Surfaces I'm talking about are rectangles, below arches Problematic surfaces

      I've inspected them a bit, it is definitely rectangle, and seems problem is that for UVQ coordinates we get 2 pairs of identical coordinates.

      ` face=Sketchup.active_model.selection[0]
      face.vertices.each{|v| puts v.position}
      (-81.244783m, 48.236298m, 29.144603m)
      (-81.244783m, 48.236298m, 25.126711m)
      (-78.64126m, 46.296916m, 25.126711m)
      (-78.64126m, 46.296916m, 29.144603m)

      tw=Sketchup.create_texture_writer
      uvh = face.get_UVHelper( true, false, tw )
      uvq = face.vertices.collect { |v|
      uvh.get_front_UVQ( v.position )}
      [Point3d(-0.77926, 0.615652, 1.07232), Point3d(-0.77926, 0.615652, 1.07232), Point3d(-0.770337, 0.611328, 1.07188), Point3d(-0.770337, 0.611328, 1.07188)]`

      Is there some solution for surfaces with such coordinates?

      I've tried slight change in plugin code: removing of duplicates (and their corresponding vertices coordinates) and then position_material -> no error, but final texture not positioned as original one.

      Thanks in advance,
      Marija

      posted in Plugins
      M
      maricanis
    • RE: Changing Command Icons of the Toolbar

      Thanks Anton,
      I was thinking, that I'm doing something wrong, but it seems that this behaviour is not changed yet.

      posted in Developers' Forum
      M
      maricanis
    • RE: Changing Command Icons of the Toolbar

      I've found this rather old topic, and have a question is it possible now to change toolbar icons.

      I would like to change tool icon when some variable (@@active_extension) is changed.

      [ruby]@@activateCmd.set_validation_proc(){
        puts "Active #{@@active_extension}"
        puts "before #{@@activateCmd.small_icon}"
        if @@active_extension == 'ext1'
          @@activateCmd.small_icon = File.join(icons_dir,"ext1_16.png")
          @@activateCmd.large_icon = File.join(icons_dir,"ext1_24.png")
        elseif @@active_extension == 'ext2'
          @@activateCmd.small_icon = File.join(icons_dir,"ext2_16.png")
          @@activateCmd.large_icon = File.join(icons_dir,"ext2_24.png")
        end
        puts "after #{@@activateCmd.small_icon}"
        MF_ENABLED
      }[/ruby]
      

      This part of code validates command and prints correct icon path (which is changed in accordance with @@active_extension variable), but tool image in toolbar is not updated.

      I've also tried to put this change not in set_validation_proc(), but in code after variable is changed. Again correct values are printed, but image remains the same.

      Thanks in advance,
      Marija

      posted in Developers' Forum
      M
      maricanis
    • RE: Detect if cpoint is clicked

      Hi Dan,

      Good point for defining pick helper only once, and then use it. I was concerned what would happen if user select other Scene for example while tool is active, but it seems it is working fine.

      
      def activate
          view = Sketchup.active_model.active_view
          @ph = view.pick_helper
      end
      
      def onMouseMove(flags, x, y, view)
          @ph.do_pick(x, y)
          @ph.count.times { |index|
          ent = @ph.leaf_at(index)
          if ent.class == Sketchup;;ConstructionPoint
               view.tooltip = ent.to_s
               break
           end
          }
          view.refresh
      end
      
      

      Thanks again,
      Marija

      posted in Developers' Forum
      M
      maricanis
    • RE: Detect if cpoint is clicked

      Hi,

      I've managed to make it work, with help of Thom Thom's Pick It tool and PickHelper and this thread http://sketchucation.com/forums/viewtopic.php?f=180%26amp;t=48919%26amp;p=439766%26amp;hilit=tooltip#p439766

      Idea is to detect leaf with PickHelper, and if it is cpoint then print whatever needed

      def onMouseMove(flags, x, y, view)
            ph = view.pick_helper
            ph.do_pick(x, y)
            ph.count.times { |index|
              ent = ph.leaf_at(index)
              if ent.class == Sketchup;;ConstructionPoint
                  view.tooltip = ent.to_s
                  break
              end
            }
            view.refresh
      end
      

      Thanks Thom,
      Marija

      posted in Developers' Forum
      M
      maricanis
    • Detect if cpoint is clicked

      Hi,

      I'm reading API and it seems that InputPoint class can't detect if cpoint is clicked? It there some other method to detect it?

      Description of my problem
      I'm calculating some values for numerous sensors in the model. When importing data back into model, plugin create cpoint for each sensor, and idea is when user click on cpoint to show its value (in tooltip, if possible, or in some other report dialog, if not possible).

      My current implementation creates cpoints and also add text into model (containing value for the point). Problem is that such text entities (one for each sensors, and there can be 10000 sensors or so), make model overcrowded and difficult to explore.

      New idea is to add only cpoints into model, and then show values to user 'on demand' - click or mouse move.

      Back to the problem, I can detect current mouse position, but how to check if it is on cpoint or not?

      Any ideas? Is there some plugin that does similar import of numerical values, since I'm searching for some solution comfortable for user and efficient!

      Thanks in advance,
      Marija

      posted in Developers' Forum
      M
      maricanis
    • RE: OnElementAdded inside Group or Component

      Hi,

      I've been experimenting on adding/removing EntitiesObservers when groups/components are opened/closed, and I've found difference in behavior in old and new Sketchup versions.

      When I have few nested groups and I open/close them multiple times (without leaving top parent group):

      • Sketchup 8 and Sketchup 2013 - observers are added/removed as expected and each new entity is detected only once
      • Sketchup 2014 and Sketchup 2015 - it seems like observers aren't removed each time 'onActivePathChanged' is called (although in console is printed that they are removed). When I add new face inside some nested group it is detected multiple times. Number of times EntitiesObserver is called is increased each time I open/close some subgroup.
        Below it the code which is independent from my plugin and can be simply loaded in Sketchup for testing purposes:
      
      module DL;;Daylighting
      
      #Attach observers to model, entities and materials
      class DLAppObserver < Sketchup;;AppObserver
          def initializeObservers(model)
              model_observer = DL;;Daylighting;;DLModelObserver.new()
              model_observer.initializeObservers(model)
              model.add_observer(model_observer)
          end
      	
          def onNewModel(model)
              initializeObservers(model)
          end
          
          def onOpenModel(model)
              initializeObservers(model) 
          end
      end
      
      class DLModelObserver < Sketchup;;ModelObserver
          @@observers = {}
          @@entitiesObserver = nil
      	
          def initializeObservers(model)
              @@entitiesObserver = DL;;Daylighting;;DLEntitiesObserver.new()
              model.entities.add_observer(@@entitiesObserver)
          end
      
          #When new group is opened remove old observers and add new observer for active_entities
          def onActivePathChanged(model)
              puts "active path changed"
              #remove all previous observers
              @@observers.each_pair{|entities,observer|
                  begin
                      puts "***entities #{entities} remove observer #{observer}; #{entities.remove_observer(observer)}"
                  rescue Exception => e  
                      puts "Can't remove observer",e.message  
                      end
              }
              @@observers={}
      
              #if all groups are closed -> don't add observers
              if !Sketchup.active_model.active_path
                  return
              end
              entitiesObserver = DL;;Daylighting;;DLEntitiesObserver.new()
              entities = Sketchup.active_model.active_entities
              puts "***entities #{entities} add observer #{entitiesObserver}"
              if entities.add_observer(entitiesObserver)
                  @@observers[entities] = entitiesObserver
              end
          end
      end
      
      class DLEntitiesObserver < Sketchup;;EntitiesObserver
          def onElementAdded( ents, new_ent )
              #detect only Sketchup;;Face entities
              if new_ent.class == Sketchup;;Face 
                  puts "onElementAdded #{ents}; #{new_ent}"
              end    
          end 
      end 
      
      end #DL;;Daylighting
      

      To attach these observers to the application just in call in Ruby console

      app_observer = DL;;Daylighting;;DLAppObserver.new()
      app_observer.initializeObservers(Sketchup.active_model)
      Sketchup.add_observer(app_observer)
      

      I don't understand what I'm doing wrong, because printed messages in ruby console show that old observer is always removed from entities when Active path is changed, but still new faces are detected multiple times.
      Once I leave all groups and go back to model (active_path=nil), all observers are like reset and I have only one EntitiesObserver.
      When I go inside groups and subgroups again, the number of observers increases again.

      And to repeat, in Sketchup 8 and Sketchup 2013 - this problem doesn't exist.

      Any suggestion is welcome, because I'm moving in circles with this observers.

      Thanks in advance,
      Marija

      posted in Developers' Forum
      M
      maricanis
    • RE: OnElementAdded inside Group or Component

      Thanks TIG,

      Your post give me the idea and after few modifications and tests code looks like this:

      
      class DLModelObserver < Sketchup;;ModelObserver
          @@observers = {}
      
          def onActivePathChanged(model)
              #if active_path is nill (no group or component is opened)
              #skip adding new observer to model entities - since it is added on startup
              if !Sketchup.active_model.active_path
                  return
              end
              Sketchup.active_model.active_entities.remove_observer(@@observers[Sketchup.active_model.active_entities])
              #define observer object and try to add it to active_entities
              #if it is successfully added, update class variable @@observers
              observer = DLEntitiesObserver.new()
              if Sketchup.active_model.active_entities.add_observer(observer)
                  @@observers[Sketchup.active_model.active_entities] = observer
              end
          end
      end
      
      

      It works correctly and each time only single observer is defined for active_entities.

      Thanks again,
      Marija

      posted in Developers' Forum
      M
      maricanis
    • OnElementAdded inside Group or Component

      Hi,

      I've defined EntitiesObserver class to observe when new Face object is added to entities collection.

      class DLEntitiesObserver < Sketchup;;EntitiesObserver
          def onElementAdded( ents, new_ent )
              if new_ent.class == Sketchup;;Face 
                 puts "Face added #{new_ent}"
              end
          end
      end
      Sketchup.active_model.entities.add_observer(DLEntitiesObserver.new() )
      
      

      This code catches when Face is added directly in model, but doesn't catch when face is added inside some Group or Component instance.
      I tried to add another observer to catch when active path is changed and to attach observer to active_entities.

      
      class DLModelObserver < Sketchup;;ModelObserver
          def onActivePathChanged(model)
              Sketchup.active_model.active_entities.add_observer(DLEntitiesObserver.new())
          end
      end
      
      

      This catches faces added inside group, but when I open and close group multiple times it adds each time new observer -> so each new face is detected multiple times.

      I've tried to find solution on forum, but didn't have success (or used wrong keywords πŸ˜„.

      So my question is how to detect when new face is added in model, or inside any group, component instance, and how to detect that exactly once?

      Thanks in advance,
      Marija

      posted in Developers' Forum
      M
      maricanis