sketchucation logo sketchucation
    • Login
    1. Home
    2. maricanis
    3. Posts
    ℹ️ 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

    Posts

    Recent Best Controversial
    • 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
    • RE: Distinct between entities in instances

      Thanks,

      I came to the same conclusion after various forum's posts reading and my experiments with code. Just wanted to be sure if I understood it well.

      posted in Developers' Forum
      M
      maricanis
    • Distinct between entities in instances

      Hi,

      I've came to a problem, I don't have idea how to solve.
      Is it possible to treat entities inside instances separately or each change in one instance necessary leads to changes in all other instances?

      In a plugin I'm working on, I should make distinction between surfaces which are part of various component's instances. My goal is to attach unique id value to each face (as an attribute), but whenever I try that, corresponding faces in all instances are updated to.

      Example code
      User selects some face in one instance (it is also selected in other instances).
      Run next code in Ruby console:

      [pre:1gler01f] index=0 selection = Sketchup.active_model.selection face = selection[0] #selected face parent = face.parent if parent.class == Sketchup::ComponentDefinition and parent.count_instances>1 #go through all instances and find selected faces parent.instances.each{ |inst| inst.definition.entities.each{ |ent| if selection.contains?(ent) #attach id to face ent.set_attribute("faceData", "id",index) puts index index = index + 1 end } } end[/pre:1gler01f]

      when I have 3 instances of the component output is :
      0 1 2
      Based on this it seems like in each instance, selected face should have unique attribute value, but it is not the case in fact.

      After this code when I select face in any instance and type in console
      Sketchup.active_model.selection[0].get_attribute("faceData", "id")
      Result is always 2 - which means that each time I set attribute it was in fact set in all instances, and only the last value from look is the one saved.

      Note, I don't want to make instances unique, because it would effect on model geometry (and plugin users don't want that).

      Thanks in advance,
      Marija

      posted in Developers' Forum
      M
      maricanis
    • RE: Set_position for modal dialog

      Hi,

      Dan, IE version is 11. In my html file I tried to set different IE versions from 8 - 11, but all give the same problem with empty dialog opened.

      Here is the part of the code. This code as result opens dialog on correct position but sometimes dialog is empty (and when I go over it with mouse controls inside dialog appear one by one).

      class LocationDialog  
      	#parent - parent WebDialog object
      	#locationValues - array of values used to initialize dialog contents
      	def initialize(parent, locationValues)
      		@parent = parent
      		@locationValues = locationValues
      		
      		#calculate dialog position in the center of parent dialog
      		#arguments are dialog width and height
      		pos = calculateDialogPosition(250,200)
      		if pos == nil
      			pos = [300, 300]
      		end
      		
      		#create and show dialog
      		options = {
      			;dialog_title => TRANS.tr("Location"),
      			;scrollable => false,
      			#;preferences_key => 'SELocationDialog',
      			;height => 300,
      			;width => 200,
      			;left => 300,
      			;top => 300,
      			;resizable => false,
      		}
      		@wd = UI;;WebDialog.new(options)
              	f=File.join(DL_DAYLIGHTING_PATH,"html_files\\Dialogs\\locationdialog.html")
      		if not File.file?(f)
      			UI.messagebox(text,MB_OK,"Dialog definition file #{f} doesn't exist")
      			return
      		end
      		
      		@wd.set_file(f)
      		@wd.set_size(250,220)
      		@wd.set_position(pos[0], pos[1])
      				
      		#add callbacks
      		@wd.add_action_callback('onload') { |dialog, params|
      			TRANS.webdialog(@wd) #translate GUI before loading
      			@wd.execute_script("initializeLocation(#{to_json(@locationValues)});")	
      		}
      		#other callbacks ...
      
      		@wd.show_modal() {}
      	end
      	
      

      And part of html code is

      
      <!DOCTYPE html>
      <html >
      <head>
      <meta http-equiv="X-UA-Compatible" content="IE=8">
      <meta http-equiv="MSThemeCompatible" content="Yes">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Location dialog</title>
      
      <link rel="stylesheet" href="./dl_dialog.css" media="screen" type="text/css">
      </head>
      
      <body>
      	<div>
      		<div class="label_text_row">
      			<div class="floatLeft"><label for="location_text" >Location</label></div>
      			<div class="floatLeft"><input type="text" id="location_text" value=""></div>
      		</div>
      	...		
      	</div>
      <script type='text/javascript' src='json2.js'></script>
      <script type='text/javascript'>
      
      	//initialize dialog
      	rubyCalled( 'onload',"" );
      	
      	function rubyCalled( cb_name, msg ) {
      		//alert ("JD;rubyCalled");
      		fake_url = 'skp;' + cb_name + '@' +msg;
      		window.location.href = fake_url;
      	}
      	
      	function initializeLocation(json_location_string){
              var json_location = eval(json_location_string);
              document.getElementById("location_text").value = json_location.location;
      		...
      	}
      </script>
      
      	</body>
      </html>
      
      

      I suppose there is some problem with loading - as it is not finished when dialog is shown in some cases. But mystery remains why dialog is shown correctly when dialog is not modal (when show() function is used instead of show_modal().

      Thanks in advance,
      Marija

      posted in Developers' Forum
      M
      maricanis
    • Set_position for modal dialog

      Hi,

      I have a strange difference between WebDialog behavior when show() and show_modal() are used.
      I'm using Windows 7 and have the same behavior both in Sketchup 2013 and 2014

      My goal is to create modal dialog (WebDialog) and position it in the center of its parent dialog (which is also WebDialog).
      In code coordinates for modal dialog are calculated before it is created, and I get next problem.

      Test1

      1. create WebDialog
      2. set_position()
      3. callback 'onload' is called - dialog contents are loaded
      4. show_modal()
        result: Modal dialog is opened on correct position, but its contents aren't always loaded - when I go with mouse over dialog contents are shown one by one

      Test2

      1. create WebDialog
      2. callback 'onload' is called - dialog contents are loaded
      3. set_position() inside callcack 'onload'
      4. show-modal()
        result: Dialog is shown on its last position for a second and then 'jumps' to correct position. all contents are loaded correctly.

      What else I've tried:

      • Call set position inside show_modal() block -> the same 'jumping' of dialog as in Test2
      • Use show() instead of show_modal() in Test1 -> dialog is always loaded correctly, no jumping.
      • Initialize WebDialog with hash argument, and exclude 'preferences_key' inside Test2 -> 'jumping' of dialog remains, as if last position is saved.

      From all my tests it seems that position should be set before onload and show_modal() are called; but how to avoid problem of not showing dialog contents in this case.
      Note again that using of show() instead of show_modal() solves the problem, but I really need modal dialog here.

      I've gone through Thom's lost manual, tried some stuffs but no success.

      Ideas?

      posted in Developers' Forum
      M
      maricanis
    • RE: Center Webdialog over Sketchup window

      Hi TIG,

      I know about active_view, but problem is if dialog is not maximized and if/when it is moved from screen center.
      Definitely Windows system calls are needed. I'm now experimenting on that and I hope to find some solution soon.

      Thanks

      posted in Developers' Forum
      M
      maricanis
    • Center Webdialog over Sketchup window

      Hi,

      I need my WebDialog to be centered over SketchUp window each time it is opened.

      I've tried to find similar posts, without success (I found how to center over screen
      http://www.sketchucation.com/forums/scf/viewtopic.php?f=26%26amp;t=6067, but not how to center over Sketchup window). Are there some functions in Ruby API for that or should use some Windows API functions?

      So my question is how to get position and size of Sketchup application window?
      Once I have that info I can easily do WebDialog positioning.

      Marija.

      posted in Developers' Forum
      M
      maricanis
    • RE: Average color pasted instead of texture. Why?

      Thanks Dan,

      That is exactly what I needed!

      posted in Developers' Forum
      M
      maricanis
    • RE: Average color pasted instead of texture. Why?

      I've found the problem 2 minutes after I've sent the question πŸ˜„

      In "Styles" toolbar "Shaded" option was toggled on instead of "Shaded with textures" when I created and saved Sketchup model for the first time.

      When I switched to correct style, everything shows as it should be!

      I'll check if there is a way to set this "Style" automatically when user works inside plugin, so correct textures are shown.

      posted in Developers' Forum
      M
      maricanis
    • Average color pasted instead of texture. Why?

      Hi,

      I try to paste some images as textures on SketchUp Face objects.
      I calculate coordinates for material positioning and create new material with texture and past on the face. And this procedure works very well on numerous test models I've experimented with.

      But I've created new model yesterday, and got strange material pasting results.
      Instead of image texture, I got pasted image average color.
      This is not a problem with material positioning, because when average color is pasted I don't have in context menu 'Texture' submenu.

      Note, I haven't changed my code for pasting, I tried this same model in Sketchup 8, 2013 and 2014 and always the same result.
      If I copy complete geometry and paste it in some other model or even "Paste in place" in the same model, textures are positioned correctly.

      Code snippet to give idea what I'm doing. All variables on right side of statements are already calculated:
      material = Sketchup.active_model.materials.add("new_material") material.texture = filename material.texture.size = [width,height] on_front = true position = [coords[0],image_pt_array[2],coords[1],image_pt_array[1]] face.position_material(material,position,on_front)

      I also tried to inspect face when texture is pasted as average color and when it is pasted as image and in both cases I get the same output
      Vertices (3.65m, 0m, 0.71m) (3.65m, 1.3m, 0.71m) (2.53m, 1.3m, 0.71m) (2.53m, 0m, 0.71m) Material color Color(150, 208, 32, 255) Material type 1 material name fc_sunexp_2966303 Texture average color Color(150, 208, 32, 255) Texture filename C:/Users/Marija/MyPrograms/Daylighting_plugin/test_model/sunexposure_output/fc_images/Layer0_f_2966303_0_simple_exposure_standard_summarized_year_total_sunexposure_final.jpg Texture image width, height 100, 116 Texture width, height 51.1811023622047, 59.3700787401575 Texture valid true Front UV u=~ 0.03m v=~ 0.03m u=~ 0.03m v=0.00m u=0.05m v=-0.00m u=0.05m v=~ 0.03m Back UV u=3.65m v=0.00m u=3.65m v=1.30m u=2.53m v=1.30m u=2.53m v=0.00m

      My question is:

      • Why is material pasted as its average color instead of original image?
      • Have I accidentally set some faces' property/flag while I was creating Sketchup model, so materials are pasted wrong?

      Since I've tried this same code numerous times, and never had problem like this, so I suspect I've done something 'wrong' while creating a model.

      I'm sending image with example in attachment.

      Thanks in advance,
      Marija


      Image for both cases (note yellow surface should look yellow in both cases, but other 2 are wrong)

      posted in Developers' Forum
      M
      maricanis
    • RE: Width problems with select option in WebDialog

      @tt_su said:

      Are you familiar with the different document modes rendering engines use depending whether the HTML is valid or not? That specific section describes that the IE engine, when embedded is much more conservative and will keep on using an older document mode even if you have a newer IE engine installed. This differ from how the browser version of IE picks the render mode.

      Frankly, no experience and knowledge about document modes, I've just used the default ones till now.
      Any suggested readings on this?
      Especially related to embedded vs. browser mode?

      Thanks again!

      posted in Developers' Forum
      M
      maricanis
    • 1 / 1