概要
windows11に、sketchup6を入れてみた。
rubyで、3Dを書く。
スクリプト見つけたのでやってみた。
参考にしたページ
写真
サンプルコード
def show_selected2(o)
if o.is_a? Sketchup::Face
no = get_attrib(o, 'objno')
if no
no += 1000000;
no = no.to_s
msg = "面番号=" + no[1..2] + '.' + no[3..4] + '.' + no[5..6] + "\n"
else
msg = ""
end
msg += "辺数 : " + o.edges.length.to_s
msg += "\n面積 : " + sprintf('%.3f', o.area.to_sqm) + "㎡"
ro = Sketchup.active_model.rendering_options
ma = o.material;
ma = ro['FaceFrontColor'] unless ma
ma = ma.color if ma.is_a? Sketchup::Material
ma = ma.to_s;
ma = ma.gsub(' ', '');
ma = ma.sub(',255)',')')
msg += "\n表面 : " + ma
ma = o.back_material;
ma = ro['FaceBackColor'] unless ma
ma = ma.color if ma.is_a? Sketchup::Material
ma = ma.to_s;
ma = ma.gsub(' ', '');
ma = ma.sub(',255)',')')
msg += "\n裏面 : " + ma
elsif o.is_a? Sketchup::Edge
msg = "接面数 : " + o.faces.length.to_s
end
bb = o.bounds
msg += "\n上端 : " + p2c(bb.max)
msg += "\n中央 : " + p2c(bb.center)
msg += "\n下端 : " + p2c(bb.min)
msg += "\n寸法 : " + bb.width.to_s + "×" + bb.depth.to_s + "×" + bb.height.to_s
alert msg
end
class Numeric
# π
def PI
self * Math::PI
end
# ルーメン⇒ワット
def lm
3.0 * self / 40.0
end
# ワット⇒ルーメン
def to_lm
40.0 * self / 3.0
end
# 表示用寸法文字列化(mm固定)
def to_ls
sprintf('%dmm', self.to_mm)
end
# 平方インチ⇒平方メートル
def to_sqm
self.to_sqmm / 1000000.0
end
# 平方インチ⇒平方ミリメートル
def to_sqmm
self * 645.16
end
# 尺ユニット換算
def u
self * 910.mm
end
# 拡張済マーク
def sudaddy_extension
true
end
end
def p2c(p, sep=', ')
'[' + p.x.to_ls + sep + p.y.to_ls + sep + p.z.to_ls + ']'
end
def p2s(p)
p2c(p, ',').gsub('mm', '.mm')
end
def get_attrib(e, k, v=nil)
e.get_attribute('Default', k, v)
end
def get_selected
sel = Sketchup.active_model.selection
if sel.length >= 1
return sel[0]
else
return nil
end
end
def show_selected
o = get_selected
if o.is_a? Sketchup::Face
elsif o.is_a? Sketchup::Edge
elsif o.is_a? Sketchup::Group
c = nil
o.entities.each { |f|
c = f if f.is_a? Sketchup::Face
}
o = c
elsif o.is_a? Sketchup::ComponentInstance
m = o.class.to_s
m += "\nname=" + o.name if o.name
p = get_attrib(o.definition, 'product')
m += "\nproduct=" + p if p
alert m
return
else
alert 'オブジェクトを1つ選択してください。'
return
end
show_selected2(o)
end
以上。