Force rounding current model dimensions to nearest 1mm

This works. Less diagonal lines to deal with and no hidden triangles, so far… :stuck_out_tongue_winking_eye:

Sounds like a handy cleanup tool you have created Centaur…

I think it working on a selection gives the user more control

Re non-coplanar I often use :drop Vertices" plugin to force everything to a desired Z height

there is a similar plugin that moves geometry that’s been around since SU v7…

it’s called ‘disruptor’ or similar because it’s primary intention is to make re-use of the geometry extremely frustrating…

people use it when sharing models with clients to increase the difficulty of use if passed on to a third party…

accurate modelling is a far better way to handle your own models…

john

If anyone is finding this script useful, here is an update that works on the selected group or component (as per gsharp’s suggestion).
A few warnings about using this script:

  1. It does not take into account any scaling that the group or component is under.

  2. It will not attempt to modify a component instance within the selected group, for that, select the component instance directly.

  3. Because it can merge geometry, you must run ‘Fix Problems’ from the Window → Model Info → Statistics form, or you will be in danger of a bug splat occurring once you resume modeling.

  4. Always maintain backups of your model, and do not keep backups on the same device.

     require 'sketchup.rb'
    
     class Fix
    
     def Fix::MovePoint(entities, point, diff)
     	movement = Geom::Point3d.new diff[0],diff[1],diff[2]
     	transform = Geom::Transformation.new movement
     	entities.transform_entities transform, point
     end
    
     def Fix::RoundToMm(v,mm)
     	factor = (25.4 / mm)
     	v = v * factor	# convert mm to inches
     	v = v.round(0)	# round to nearest
     	v = v / factor	# convert back to mm
     end
    
     def Fix::RoundPoint(p,mm)
     	x = p.position.x
     	y = p.position.y
     	z = p.position.z
     	pNew = [RoundToMm(x,mm),RoundToMm(y,mm),RoundToMm(z,mm)]
     	pNew[0] = pNew[0] - p.position.x
     	pNew[1] = pNew[1] - p.position.y
     	pNew[2] = pNew[2] - p.position.z
     	return pNew
     end
    
     def Fix::Move(entities, p1,p2,mm)
     	p3 = RoundPoint(p1,mm)
     	p4 = RoundPoint(p2,mm)
     	MovePoint(entities, p1,p3)
     	MovePoint(entities, p2,p4)
     end
    
     def Fix::FixGeometry(entities,mm)
     	entities.each { |e|
     		if(e.class == Sketchup::Group)
     			FixGeometry(e.entities,mm)
     		end
     		if(e.class == Sketchup::Edge)
     			if e.curve == nil	# don't move the edge vertices if it is part of a curve
     				p1 = e.vertices[0]
     				p2 = e.vertices[1]
     				Move(entities, p1,p2,mm)
     			end
     		end
     	}
     end
    
     def Fix::Execute(mm)
     	Sketchup.active_model.start_operation "Fix",true ,false ,false
     	
     	sel = Sketchup.active_model.selection
     	sel.each { |e|
     		if(e.class == Sketchup::ComponentInstance)
     			FixGeometry(e.definition.entities,mm)	
     		end
     		if(e.class == Sketchup::Group)
     			FixGeometry(e.entities,mm)	
     		end
     	}
     	Sketchup.active_model.commit_operation
     	Sketchup.active_model.active_view.invalidate
     end
     end
    
     if(not file_loaded?("Fix.rb"))
     	UI.add_context_menu_handler do |menu|
     	tools = menu.add_submenu("Other Tools")
     	tools.add_item("Round Geometry to 1mm") { Fix.Execute(1) }
     	tools.add_item("Round Geometry to 10mm") { Fix.Execute(10) }
     	end
     end
     file_loaded("Fix.rb")
    

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.