sketchucation logo sketchucation
    • Login
    1. Home
    2. sdmitch
    3. Posts
    βŒ› Sale Ending | 30% Off Profile Builder 4 ends 30th September
    Offline
    • Profile
    • Following 0
    • Followers 3
    • Topics 54
    • Posts 1,483
    • Groups 2

    Posts

    Recent Best Controversial
    • RE: Mass Material Importer

      @dillow said:

      I do not have the skm collections. I do have old Sketchup files with materials in them but I thought it'd be just easier to download the jpgs (mostly from manufacturer tileable images). But converting hundreds of jpgs to skis isn't fun.

      Here is a version of the method I use to load materials into a model.

      module DILLOW
      		def self.materials_from_file
      			@mod = Sketchup.active_model
      			@textures_from_file = []; @images = []; @image_path ||= File.dirname(__FILE__)+"/*.*"
      			@image_path = UI.openpanel("Texture Files",@image_path)
      			unless @image_path==nil
      				image_folder = File.dirname(@image_path.gsub('\\','/'));
      				@images = Dir[image_folder+"/*.{jpg,png,tif,bmp,gif,tga,epx}"]
      				@images.each{|i| @textures_from_file<<File.basename(i,'.*')};
      				if @textures_from_file[0]
      					@textures_from_file.each_with_index{|name,i|
      						unless @mod.materials[name]
      							mat = @mod.materials.add(name)
      							mat.texture = @images[i]
      						end
      					}
      				end
      			end
      		end
      end
      DILLOW.materials_from_file
      

      Copy and paste into Ruby Console and press Enter to execute. Select any image file and click Open.

      posted in SketchUp Discussions
      sdmitchS
      sdmitch
    • RE: Importing Bulk Attribute Values from CSV

      Perhaps if you would share a sample model containing the dynamic component and a sample .csv file.

      posted in Developers' Forum
      sdmitchS
      sdmitch
    • RE: [REQ] Rotated Rectangle to Merge with Model

      Check PM for possible solution.

      posted in Plugins
      sdmitchS
      sdmitch
    • RE: Uninitialized class variable

      @pixero said:

      I'm trying to make a script remember the values the user puts in during a SketchUp session so that he wont have to re enter them every time the script is run.

      When for example using:

      module Mymodule
      >   class Myclass
      > 
      >   def initialize
      >     #Setting default values
      >     @myvariable = 25.mm unless @myvariable 
      > 
      >     #And so on......
      

      the script works but wont remember the settings when run again.

      When using @@myvariable = 25.mm unless @@myvariable
      I get a "Uninitialized class variable" error message.

      What am I doing wrong?

      You just need to make a dummy assignment to it just after class declaration.

      module Mymodule
        class Myclass
        @@myvariable=nil
        def initialize
          #Setting default values
          @@myvariable = 25.mm unless @myvariable 
      
          #And so on......
      
      posted in Developers' Forum
      sdmitchS
      sdmitch
    • RE: Uninitialized class variable

      @pixero said:

      Should it be @@myvariable = nil and then @myvariable with just one @ or was that a typo?

      I just copied your code and added the @@myvariable=nil to it. The typo, @myvariable, was in your original code.

      It should be @@myvariable everwhere.

      posted in Developers' Forum
      sdmitchS
      sdmitch
    • RE: Replace Several Textures?

      I have PM'd you a possible solution to #7

      posted in Developers' Forum
      sdmitchS
      sdmitch
    • RE: Replace Several Textures?

      @tntdavid said:

      6. Click the cube icon again, you will see that the sub-components of the middle cube will no longer change.

      7. Click on the color icon, the texture of the middle cube no longer changes. (Unfortunately this is not yet the case and I need your help to write this method.)

      1. I'm not sure why this works at all since we changed to pattern matching of the name to over come the problem with names containing '#'!

      2. This is never going to work because there is only a single 'color' involved and making a component unique has no effect on the material applied.

      I'll keep thinking about it but I'm not optimistic about finding a solution.

      posted in Developers' Forum
      sdmitchS
      sdmitch
    • RE: Replace Several Textures?

      @tntdavid said:

      Here is a simpler idea for the 2nd Objective:

      1 - I select a piece of furniture.

      2 - I Click on the icon "Freeze the model". (The method that is executed makes all unique components and subcomponents of my selection.)

      3 - I can execute the first code without changing the handles of the furniture made unique.

      How to write this method?

      Thanks in advance for your help.[/size]

      Could you post or PM me a sample model,version<=2016, that I could test.

      posted in Developers' Forum
      sdmitchS
      sdmitch
    • RE: Replace Several Textures?

      @tntdavid said:

      [size=110]Thanks for your Sdmitch solution, but the definitions rendered unique "1-HANDLE # 1" still do not change.

      Maybe I made a mistake somewhere?

      def poignee
      >     @@mod = Sketchup.active_model
      >     @@ent = @@mod.active_entities
      >     @@avant = Sketchup.active_model.get_attribute("Handles","Last","1")
      >     @@next = @@avant.next
      >     @@next = '1' if @@next == '19'	
      > 	  
      >     @@last1 = "#{@@avant}-POIGNEE"
      >     @@next_name = "#{@@next}-POIGNEE"
      > 	  
      > if  @@mod.definitions[@@last1]
      >     @@cd = @@mod.definitions[@@next_name]	
      >     unless @@cd
      >     cmp = File.join(Sketchup.find_support_file('plugins'),"TNT_ClickCuisine2/Components/#
      >     {@@next_name}.skp")
      >     @@cd = @@mod.definitions.load cmp
      >     end
      >     @@mod.definitions.find{|cd|cd.name=~/#{@@last1}?/i}.instances.each{|ci|ci.definition=@@cd}
      >     @@avant = @@next
      >     Sketchup.active_model.set_attribute("Handles","Last",@@next)
      >     else
      >     UI.messagebox "#{@@last1} not found."
      >   end
      > end
      

      I think you need to use the same @@mod.definitions.find when checking for existence also.

      if @@mod.definitions.find{|d|d.name=~/#{@@last1}?/}
      	@@cd = @@mod.definitions.find{|d|d.name=~/#{@@next_name}?/}
      	unless @@cd
      		cmp = File.join(Sketchup.find_support_file('plugins'),"TNT_ClickCuisine2/Components/#{@@next_name}.skp")
      		@@cd = @@mod.definitions.load cmp
      	end
      	@@mod.definitions.find{|cd|cd.name=~/#{@@last1}?/i}.instances.each{|ci|ci.definition=@@cd}
      	@@avant = @@next
      	Sketchup.active_model.set_attribute("Handles","Last",@@next)
      else
      	UI.messagebox "#{@@last1} not found."
      end
      
      
      posted in Developers' Forum
      sdmitchS
      sdmitch
    • RE: Replace Several Textures?

      @tntdavid said:

      The current code does not replace the unique handles, such as "1-HANDLE # 1".

      Is it possible to circumvent the problem, if so how?

      @@mod.definitions.find{|cd|cd.name=~/#{@@last1}?/i}.instances.each{|ci|ci.definition=@@cd}
      

      The 2nd Great Steps is to replace the Handles of a single piece of furniture selected, without affecting other furniture.

      How would you do that?
      This would be difficult indeed. The easiest way would be to move the single piece to a new model, make the changes then import it back.

      David

      posted in Developers' Forum
      sdmitchS
      sdmitch
    • RE: Replace Several Textures?

      I would suggest using attributes to keep tract of "next".

      @@avant = Sketchup.active_model.get_attribute("Handles","Last","1")
      @@next = @@avant.next
      Sketchup.active_model.set_attribute("Handles","Last",@@next)

      posted in Developers' Forum
      sdmitchS
      sdmitch
    • RE: How to create a selection window in a tool?

      @ittayd said:

      I want to create a tool that allows to select several entities by either picking them or a selection window. But how do I draw the selection window?

      The "Select by Polygon" plugin you can find on my blog is an example of drawing the selection window then selecting the entities within it.

      posted in Developers' Forum
      sdmitchS
      sdmitch
    • RE: Trouble adding entity to component definition

      I can't tell you why but if you change

      def self.create_component_definition_laddershelves()
        @componentDefinitionLadderShelves=@definitions.add "LadderShelves"
        self.create_component_definition_piece(2.5,48,0.75,0)
        @componentDefinitionLadderShelves.entities.add_instance(@componentDefinitionPiece,@transform000)
      
      

      to

      def self.create_component_definition_laddershelves()
        self.create_component_definition_piece(2.5,48,0.75,0)
        @componentDefinitionLadderShelves=@definitions.add "LadderShelves"
        @componentDefinitionLadderShelves.entities.add_instance(@componentDefinitionPiece,@transform000)
      
      

      it works! I think it is as TIG suggested, you need to complete the creation of one definition before starting the other.

      posted in Developers' Forum
      sdmitchS
      sdmitch
    • RE: Plugin request - show/hide for scene dialog

      @monkers said:

      YES! That looks awesome! Where can I find this plugin? I had a look through your blog but didn't see it.

      No I never put it on the blog but I will send you a copy via Personal Message.

      posted in Extensions & Applications Discussions
      sdmitchS
      sdmitch
    • RE: Plugin or script for batch export

      @rauch86rauch said:

      Hi everybody,
      I just lost about 86 pngs export made in the last weeks, from 86 different Sketchup files.
      Deadline coming, I am asking anybody who is able to suggest a solution to do a batch export of all the files.
      I am trying to learn some about ruby in these days but I have not enough time to get an understanding of it!
      I have seen solutions around that would have been almost perfect for me but I am not able to modify any code and make it work.
      My need would be:
      -open the file,
      -export in .png the scenes as an Image set(to control the export size, everything already set),
      -close the file.
      I know it is probably easy but I don't have any experience of ruby.
      Thanks in advance for any help you can give!

      Maybe the attached plugin will help
      Usage:Extension>SDM Tools>Misc Tool>Export Scene Image
      Select image type, enter image width and image height
      Navigate to the folder of the models, select any one of them and click Open
      Navigate to the folder of the images and click Save.


      Export Scene Image.rb

      posted in Plugins
      sdmitchS
      sdmitch
    • RE: Is there a way to make surface planar

      @mwm5053 said:

      This is a roof line that wasn't completely planer made from several different objects it intersected with. I couldn't get the lines to make a face so I used Sandbox/ From contours I got a face but lots of hidden geometry which makes it hard if not impossible to extrude of use the offset tool. So Is there a way to make surface planer without any hidden geometry?

      I don't have access to SU2017 at the moment but my guess is that, since this is part of a roof, it is sloped so draping or making all z's the same will not work but maybe this will help.
      Open the group for edit and select all. Paste code snippet into the Ruby Console and press Enter.

      @mod = Sketchup.active_model
      @ent = @mod.active_entities
      @sel = @mod.selection
      @vue = @mod.active_view
      vrts = @sel.grep(Sketchup;;Edge).map{|e|e.vertices}.flatten.uniq
      pnts = vrts.map{|v|v.position}
      plane = Geom.fit_plane_to_points pnts
      pnts = vrts.map{|v|v.position.project_to_plane(plane)}
      vecs = []; edgs = []
      vrts.each_with_index{|v,i|vecs<<v.position.vector_to(pnts[i])}
      @ent.transform_by_vectors(vrts,vecs)
      @sel.grep(Sketchup;;Edge).each{|e| next unless e.faces[1];edgs<<e}
      @ent.erase_entities(edgs.reverse)
      
      

      put on plane.gif

      posted in SketchUp Discussions
      sdmitchS
      sdmitch
    • RE: Push/pull (or drag) with increment ?

      @tboy said:

      In scripts when we drag with mouse, code looks like:

      view.draw_line startPossition, endPossition

      'start Position' is defined by click, 'end Position' is moving with mouse.
      Is it possible while dragging mouse to snap on every next 0,5cm or 1cm (for example) instead of smooth dragging.
      What code can I use to obtain such a behavior?

      Here is a simple example of how I would do it.


      By Increment.rb

      posted in Developers' Forum
      sdmitchS
      sdmitch
    • RE: Is there a way to make surface planar

      @pixero said:

      @sdmitch:

      Thanks for the great script snippet.
      Would it be possible to modify it so that it would work on a selection of several non connected surfaces and that it would clean them up at the same time. Now I must select each surface by hand which takes considerably longer.

      I would assume so. Are we talking about normally grouped surfaces that you want to able to select all and process them individually as you are currently doing one at a time?

      posted in SketchUp Discussions
      sdmitchS
      sdmitch
    • RE: Replace Several Textures?

      @tntdavid said:

      **> How to automatically select all the "Box-1" components, even those that are nested in a piece of furniture?
      David

      **

      Following up on TIG's idea of collecting instances, I think this solves the problem of the embedded components.

            @mod = Sketchup.active_model
            @ent = @mod.active_entities
            @last ||= '1'; @next = @last.next; @next = '1' if @next == '4'
            last_name = "#{@last}-Box"; next_name = "#{@next}-Box"
            if @mod.definitions[last_name] && @mod.definitions[last_name].instances[0]
              cd = @mod.definitions[next_name]
              unless cd
               cmp = File.join(Sketchup.find_support_file('plugins'),"TNT_ClickCuisine2/Components/#{next_name}.skp")
               cd = @mod.definitions.load cmp
              end
              @mod.definitions.find{|d|d.name==last_name}.instances.each{|ci|ci.definition=cd}
              @last = @next
            else
              UI.messagebox "#{last_name} not found."
            end
      
      
      posted in Developers' Forum
      sdmitchS
      sdmitch
    • RE: Replace Several Textures?

      @tntdavid said:

      **OK TIG πŸ˜‰

      How to do the same for components?

      Example:

      I have 3 boxes, "1-Box", "2-Box", "3-Box", they are in the folder "Plugins/ Click-Cuisine2/Components".

      I want to create an icon that calls a method of this type:

      1st Click

      Selects all components with the definition "1-Box ##", and replaces with "2-Box", which is in the "Components" folder.

      If no component with the definition " 1-Box" was found, send the message, "Import a Clik-Cuisine 2 furniture, to replace these components ".

      2nd Click

      Selects all components with the definition "2-Box ##", and replaces it with "3-Box".

      3rd Click

      Selects all components with the definition "3-Box ##", and replaces with "1-Box".

      Final objective:

      Click-Cuisine 2, will offer more than 20 IKEA handles that I want to interchange with one click.

      This can be done in Dynamic Components, but it is not suitable for such a large number of 3D models.

      If you can help me write this method, I would be very glad. β˜€**

      thank you

      David

      This seems to work for me.

            @mod = Sketchup.active_model
            @ent = @mod.active_entities
            @last ||= '1'; @next = @last.next; @next='1' if @next=='4'
            last_name = @last + '-Box'; next_name = @next + '-Box'
            cmp_folder = File.join(File.dirname(__FILE__).gsub('\\','/'),"TNT_ClickCuisine2/Components/")
            cis = @ent.grep(Sketchup;;ComponentInstance).find_all{|ci|ci.definition.name[0..4]==last_name}
            unless cis.empty?
              for ci in cis
                cd = @mod.definitions[next_name]
                unless cd
                  cmp = cmp_folder+"#{next_name}.skp"
                  cd = @mod.definitions.load cmp
                end
                ci.definition = cd
              end
              @last = @next
            else
              UI.messagebox "#{last_name} not found."
            end
      
      
      posted in Developers' Forum
      sdmitchS
      sdmitch
    • 1 / 1