我的su不带ruby控制台,大家试试这段代码,能生成一个抽拉沙发床吗?帮我试试,成功的话,可以发给我,谢谢!
- require 'sketchup'
- model = Sketchup.active_model
- entities = model.active_entities
- materials = model.materials
- # 创建材质
- wood_mat = materials.add('Wood')
- wood_mat.color = 'BurlyWood'
- metal_mat = materials.add('Metal')
- metal_mat.color = 'Black'
- # 尺寸(cm)
- length = 195.cm
- width = 113.cm
- height_head = 45.cm
- height_surface = 31.cm
- thickness_board = 65.cm
- pull_depth = 90.cm
- sofa_depth = 50.cm
- wheel_radius = 3.cm
- wheel_height = 3.cm
- # 辅助函数:画矩形
- def draw_box(entities, origin, dx, dy, dz, material)
- pts = [
- origin,
- [origin[0]+dx, origin[1], origin[2]],
- [origin[0]+dx, origin[1]+dy, origin[2]],
- [origin[0], origin[1]+dy, origin[2]]
- ]
- face = entities.add_face pts
- face.pushpull dz
- face.material = material
- end
- # ---- 收起状态(沙发) ----
- group_sofa = entities.add_group
- sofa_entities = group_sofa.entities
- # 座面
- draw_box(sofa_entities, [0,0,0], length, sofa_depth, height_surface, wood_mat)
- # 床头板
- draw_box(sofa_entities, [0,0,height_surface], length, thickness_board, height_head - height_surface, wood_mat)
- # 床尾板
- draw_box(sofa_entities, [0,sofa_depth-thickness_board,height_surface], length, thickness_board, height_head - height_surface, wood_mat)
- # ---- 拉出床体 ----
- group_bed = entities.add_group
- bed_entities = group_bed.entities
- # 床面
- draw_box(bed_entities, [0,sofa_depth,0], length, pull_depth, height_surface, metal_mat)
- # 床头板延伸
- draw_box(bed_entities, [0,sofa_depth,0], length, thickness_board, height_surface, wood_mat)
- # ---- 床脚轮子 ----
- group_wheels = entities.add_group
- wheel_entities = group_wheels.entities
- wheel_positions = [[0,0,0],[length-wheel_radius*2,0,0]]
- wheel_positions.each do |pos|
- wheel = wheel_entities.add_circle [pos[0]+wheel_radius, pos[1]+wheel_radius, 0], [0,0,1], wheel_radius
- face = wheel_entities.add_face wheel
- face.pushpull wheel_height
- face.material = metal_mat
- end
- UI.messagebox('抽拉沙发床模型已生成!\n收起状态:Group_SOFA\n拉出床体:Group_BED\n轮子:Group_WHEELS')
复制代码
|
-
|