sketchup ruby 将面的颜色修改成淡黄色

def change_face_color

获取选中的面

selection = Sketchup.active_model.selection if selection.empty? UI.messagebox('请先选择一个面。') return end face = selection[0] unless face.is_a?(Sketchup::Face) UI.messagebox('所选实体不是面,请选择一个面。') return end

创建新的材质对象,并将其颜色设置为淡黄色

yellow_color = Sketchup::Color.new(255, 255, 153) yellow_mat = Sketchup.active_model.materials.add('Yellow') yellow_mat.color = yellow_color

将面的材质替换为新的材质对象,或向面添加自定义属性

if Sketchup.version.to_i >= 2021 face.material = yellow_mat else face.set_attribute('SketchUp_FaceAttributes', 'face_color', 'yellow') end

刷新视图

Sketchup.active_model.active_view.refresh end