Sketchup 的选取物体进行移动旋转的脚本

  1. def rotate(ent, axis, angle)
  2. rv = ent.transformation.zaxis if axis == "z"
  3. rv = ent.transformation.yaxis if axis == "y"
  4. rv = ent.transformation.xaxis if axis == "x"
  5. rp = ent.transformation.origin
  6. ent.transform!(Geom::Transformation.rotation(rp, rv, angle))
  7. end
  8.  
  9.  
  10. mod = Sketchup.active_model # Open model
  11. ent = mod.entities # All entities in model
  12. sel = mod.selection # Current selection
  13.  
  14. componame="abc"
  15. compo = Sketchup.active_model.definitions[componame]
  16. if compo
  17. puts "#{componame} found: doing something else..."
  18. ### do something with 'compo' definition
  19. else
  20. puts "#{componame} does NOT exist!"
  21. return
  22. end
  23. entity=compo.instances[0]
  24.  
  25. targetPoint = Geom::Point3d.new(1000.mm, 1000.mm, 0)
  26. entity.transformation = Geom::Transformation.new(targetPoint)
  27.  
  28.  
  29. angle = 30.degrees
  30. rotate(entity, "z", angle)
  31. rotate(entity, "x", angle)
  32. rotate(entity, "y", angle)