以下是一些Google SketchUp Ruby API片段。这非常简单,使用Edge#find_faces
SketchUp 尝试查找给定边缘的可能面的方法。https://developers.google.com/sketchup/docs/ourdoc/edge#find_faces
查找当前选择的面:
# Find faces for selected edges:
model = Sketchup.active_model
model.start_operation( 'Find Faces in Selection', true )
for entity in model.selection.to_a
next unless entity.is_a?( Sketchup::Edge )
entity.find_faces
end
model.commit_operation
查找当前上下文的面孔:
# Find faces for current context:
model = Sketchup.active_model
model.start_operation( 'Find Faces in Current Context', true )
for entity in model.active_entities.to_a
next unless entity.is_a?( Sketchup::Edge )
entity.find_faces
end
model.commit_operation
查找模型中所有边的面:
# Find faces for all edges in model:
model = Sketchup.active_model
model.start_operation( 'Find Faces in Whole Model', true )
for entity in model.entities.to_a
next unless entity.is_a?( Sketchup::Edge )
entity.find_faces
end
for definition in model.definitions
next if definition.image?
for entity in definition.entities.to_a
next unless entity.is_a?( Sketchup::Edge )
entity.find_faces
end
end
model.commit_operation
如果您需要为此处理一批 DWG 文件,您也可以使用Model#import
导入 DWG 文件来实现自动化。https://developers.google.com/sketchup/docs/ourdoc/model#import
这假设边缘是共面的边界。只有当您导入的网格可以代表一个时,您才会得到一个实体。