sketchucation logo sketchucation
    • Login
    1. Home
    2. rossthompson
    3. Posts
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download
    R
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 19
    • Posts 35
    • Groups 1

    Posts

    Recent Best Controversial
    • Directly apply a material

      Hi,
      I am working on a script that activates the paint bucket tool with a predefined material of a certain colour and transparency. The code I have written works fine except on every use it creates a copy of the material eg. 'window1', 'window2' etc. which makes a bit of a mess of the materials palette.

      I think it just needs a simple if statement to avoid creating the material if it already exists. Does anyone know how to do this?

      Thanks Ross

      
      toolbar = UI;;Toolbar.new "Window"
           cmd = UI;;Command.new("Test") { window }	
           cmd.small_icon = "CBG/window_sm.png"
           cmd.large_icon = "CBG/window.png"
           cmd.tooltip = "Paint Window"
           toolbar = toolbar.add_item cmd
           toolbar.show	 
      	 
      def window
       model = Sketchup.active_model
       materials = model.materials
       m = materials.add "Window"	 					# Adds a material to the "in-use" material pallet.
      
      m.color = Sketchup;;Color.new(100, 150, 240)	# Specify the colour
      color = m.color
      alpha = m.alpha=0.5								# Set transparency
      
      materials.current = materials["Window"]			# Set to the current material
      Sketchup.send_action "selectPaintTool;"			# Start the paint tool
      end	 
      
      
      
      posted in Plugins
      R
      rossthompson
    • RE: Re: [Plugin] Flatten to Plane v1.2 20101023

      Hi TIG,

      That worked a treat. Thank you - this is going to save me a lot of time!

      Ross

      posted in Plugins
      R
      rossthompson
    • RE: Re: [Plugin] Flatten to Plane v1.2 20101023

      Hi,

      It looks like I am coming to the thread a little late.... I was just wandering weather it would be easy to change the script slightly so it deleted the originally selected entities and didn't create a group for the flattened entities. So bascially the selection just gets replaced with a flattened version.

      This would be beneficial as I use the tool a lot for cleaning up imported geometry where the faces aren't quite coplanar - hence the original entities are of little use.

      Ive had a look through the script and the code is a bit above my head.

      Ross

      posted in Plugins
      R
      rossthompson
    • Project Entities onto an off-axis face.

      Hi guys,

      I am frequently required to build up 3D models (of buildings) from 2D Elevations. I sometimes encounter elements of buildings that are off axis to the rest of the model and the provided elevation drawings.

      In these situations I have difficultly adding elements like windows to the off axis model. I have experimented with scripts such as 'flattentoplane.rb', but the projection angle for this script is always parallel to the workplane so not useful.

      The drape tool is close to performing the job but is only effective at projecting along the Z-axis and sends the projected profile all the way through 'solids' rather than just projecting onto the outer surface.

      The attached image hopefully explains the problem much better than I can with words!

      Are there any scripts available for this task? Could the drape or flatten to plane tools be simply modified to solve the problem?

      Ross


      Projection on to off axis surface.JPG

      posted in Plugins
      R
      rossthompson
    • File Path Problem

      Hi guys,

      I am trying to organise my plugins folder. As a result of this I have moved the location of some cursor files into a subfolder. Hence the code snipet below is no longer valid.

      
       c = File.join(File.dirname(__FILE__), "clinetool_cursor.png")
       ltcursor = UI;;create_cursor(c, 1, 30)
      
      

      The cursor file is now stored in a folder with this path: 'C:\Program Files (x86)\Google\Google SketchUp 7\Plugins\CBG'
      How can I adapt the code to the new path?

      My thoughts were:

      
      c = File.join(File.dirname("/CBG"),"clinetool_cursor.png")
      ltcursor = UI;;create_cursor(c, 1, 30)
      
      

      Any help would be greatly appreciated - I am sure the solution is very simple!

      Ross

      posted in Plugins
      R
      rossthompson
    • RE: Edit raw vertex data

      Hi Thom Thom,

      Thanks for the response. I dabble in writing my own scripts, but I wouldn't know where to start on this one! So I guess I'm asking as more of a user.

      I came across a situation this morning where I was working with some imported geometry from another company. There was a long row of pillars all with slightly different Z-coordinates, I wanted to normalise them to a certain position in Z. Hopefully the attached image illustrates this.

      I know this could easily be done with the move tool or the push/pull tool, but I reckon using a vertex table would have to be quickest/most direct. It could also have applications for checking geometry i.e. when you can't create a face because the bounding edges are not co-planar.

      Ross


      Pillars.JPG

      posted in Plugins
      R
      rossthompson
    • Edit raw vertex data

      Hi guys,

      I have worked with a couple of other CAD programs that provide you with a window for editing raw vertex data. See attached image. I was wandering if something similar would be possible in SketchUp?

      I appreciate this doesn't actually add any functionality, but it is a very direct way of moving points to absolute positions.

      I hope this makes sense.

      Ross


      Vertex Table.JPG

      posted in Plugins
      R
      rossthompson
    • RE: Rotation about the origin

      Sam,

      Thanks very much that works perfectly.

      Ross

      posted in Developers' Forum
      R
      rossthompson
    • Rotation about the origin

      Hi guys,

      I am trying to write a script that very simply rotates selected objects by 90 degrees in the Z axis. I have put together some code but it isn't working. Can anyone help? I am new to Ruby so I have probably made some really basic mistakes.

      Ross

      
      require 'sketchup.rb'
      
      
      # Add a menu item
      UI.menu("PlugIns").add_item("rotate90") {  
        rotate90	# Call method.
      }
      
      def rotate90
      	rv = Geom;;Vector3d.new(0,0,1)
      	ra = 90.degrees
      	rp = Geom;;Point3d.new(0,0,0) 
      
      	Sketchup.active_model.Transformation.rotation(rp, rv, ra))
      	
      end
      
      
      posted in Developers' Forum
      R
      rossthompson
    • RE: Move points to a '3D grid'

      Hi guys, I have had a play with Dan's Beta version and for me it works really well. The verticies are adjusted in X,Y and Z directions and the undo function works fine!

      The only slight problem: it adjusts all the geometry in the model, rather than just the active selection. The original module just adjusted the active selection.

      Any ideas?

      Again thanks for the support - this script should be a realy time saver!

      Ross

      posted in Developers' Forum
      R
      rossthompson
    • RE: Move points to a '3D grid'

      ThomThom thanks so much for your support! I have had a go at running your test module. My understanding is that it should shift the points in the active selection to a 0.25m grid as specified in the code.

      However I am having problems running the module. I have attempted to add it to the tools menu as below, but I am not 100% sure how to 'call' the routine. Appologies if I'm being an idiot - I am new to ruby scripting!

      
          module GridSnap
      
            def self.round_point( point, tolerance )
              grid_pt = point.to_a.map { |n|
                b = ( n / tolerance ).to_i * tolerance
                r = n % tolerance
                (r > tolerance / 2) ? b + tolerance ; b
              }
              Geom;;Point3d.new( *grid_pt )
            end
            
            def self.test_it
              pt = Geom;;Point3d.new( 3.976879.m, 3.760209.m, 1.002568.m )
              tolerance = 0.25.m
              grid_pt = self.round_point( pt, tolerance )
              
              puts "Original; #{pt}"
              puts "Tolerance; #{tolerance}"
              puts "Grid Point; #{grid_pt}"
            end
            
            def self.adjust_vertices( tolerance = 0.25.m )
              model = Sketchup.active_model
              vertices = []
              # Collect vertices.
              for e in model.active_entities
                vertices << e.vertices if e.is_a?( Sketchup;;Edge )
              end
              vertices.flatten!
              vertices.uniq!
              # Calculate grid adjustments.
              vectors = []
              entities = []
              for vertex in vertices
                pt = vertex.position
                grid_pt = self.round_point( pt, tolerance )
                vector = pt.vector_to( grid_pt )
                next unless vector.valid?
                entities << vertex
                vectors << vector
              end
              # Apply transformations
              model.active_entities.transform_by_vectors( entities, vectors )
              puts "#{entities.size} adjusted to grid."
            end
      
          end
      
      # Menu Entry;
      
      UI.menu("Tools").add_item("GridSnap") { GridSnap } if not file_loaded?("GridSnap.rb") 
      file_loaded("GridSnap.rb")
      
      
      
      

      I think this could be a very useful tool for cleaning many types of imported geometry.

      Ross

      posted in Developers' Forum
      R
      rossthompson
    • Move points to a '3D grid'

      Hi,

      I am trying to write a script for cleaning up geometery created from another program (IES VE). Essentially what I want to achieve is to move each vertex so it sits on a '3D grid'. I believe this could be achieved by applying a rounding function to the X,Y and Z coordinates of each point.

      The attached image hopefully illustrates what I am trying to achieve. Ideally the degree of rounding would be a user input variable.

      Any help on this would be greatly appreciated.

      Ross


      Model on 3D Grid.PNG

      posted in Developers' Forum
      R
      rossthompson
    • Create new layer with an RGB colour

      Hi,

      I was wandering if it is possible to write a script to generate a set of layers with specific RGB colours. Google developers provides code for creating a new layer with a certain name:

      
           model = Sketchup.active_model
           layers = model.layers
           new_layer = layers.add "test layer"
      

      However I can't figure out the colour aspect. Looking at similar scripts it appears people have had to use a work around passing the layers through a DXF file. Surely it can't be that complicated?

      Any help would be greatly appreciated.

      Ross

      posted in Developers' Forum
      R
      rossthompson
    • RE: Name a Group after its Layer

      Thanks Sam

      That works a treat. Your help is much appreciated.

      Ross

      posted in Plugins
      R
      rossthompson
    • Name a Group after its Layer

      Hi,

      Is it possible to automatically name a group (or a component) after the layer it is on?

      I understand this should be possible with a fairly simple ruby script. Has anyone come across one?

      Any help would be greatly appreciated.

      Ross

      posted in Plugins
      R
      rossthompson
    • 1 / 1