I need the result - the 2D model from the top view. I want to how to achieve it. Firstly, if the Ruby API supports to export as .dxf and to read the lines in the .dxf, it would be easy to get the 2D picture. But it seems no way. Then I want to retrieve the edges, if I can get all the edges that are visible from the top view. Appreciate any suggestion in advanced.
It is obviously just exporting all edges of the chair model, not removing the invisible edges from the top view. So they are different methods - export to dxf by menu and by Ruby api.
SketchUp’s idea of “hidden” is whether the entity is shown or not.
I don’t think that the API has a way to determine what objects are occluded and those that are not.
You might first get the bounding box of the object the code is testing using #bounds.
Then pick points offset above the bounding box and repeatedly fire rays downward toward the object. Perhaps you can glean information you need from the results.
Something like the following … it’s up to you to process the hit arrays.
module Henry12
module PlanScan
extend self
# Scan an instance by firing rays downward.
#
# @param inst [Sketchup::ComponentInstance] The instance to scan.
#
# @return [Array(Geom::Point3d, Array<Sketchup::Drawingelement>)]
# The array of ray hits.
def scan(
inst = Sketchup.active_model.active_entities.grep(Sketchup::ComponentInstance).first
)
x_dim = inst.bounds.width
y_dim = inst.bounds.height
z = inst.bounds.depth + 1
model = inst.model
prev_path = model.active_path
model.active_path = Sketchup::InstancePath.new([inst])
hits = []
resolution = 100
downward = Z_AXIS.reverse
ray = [ Geom::Point3d.new(0, 0, z), downward ]
0.step(to: x_dim, by: x_dim/resolution) do |x|
0.step(to: y_dim, by: y_dim/resolution) do |y|
ray[0]= Geom::Point3d.new(x, y, z)
result = model.raytest(ray)
hits << result if result
end
end
model.active_path= prev_path
return hits
end
end
end