Sketchup 的选取物体进行移动旋转的脚本
Submitted by hubdog on Wed, 2021-10-27 12:24
def rotate(ent, axis, angle) rv = ent.transformation.zaxis if axis == "z" rv = ent.transformation.yaxis if axis == "y" rv = ent.transformation.xaxis if axis == "x" rp = ent.transformation.origin ent.transform!(Geom::Transformation.rotation(rp, rv, angle)) end mod = Sketchup.active_model # Open model ent = mod.entities # All entities in model sel = mod.selection # Current selection componame="abc" compo = Sketchup.active_model.definitions[componame] if compo puts "#{componame} found: doing something else..." ### do something with 'compo' definition else puts "#{componame} does NOT exist!" return end entity=compo.instances[0] targetPoint = Geom::Point3d.new(1000.mm, 1000.mm, 0) entity.transformation = Geom::Transformation.new(targetPoint) angle = 30.degrees rotate(entity, "z", angle) rotate(entity, "x", angle) rotate(entity, "y", angle)