Entities.intersect_with
Entities.intersect_with用法2021年10月25日
本帖最后由 tzbm123456 于 2021-10-25 05:45 编辑
mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
arr=sel.to_a;
en1=arr;
en2=arr;
gr_entities1=en1.entities;
gr_entities2=en2.entities;
gr_tran1=en1.transformation;
gr_tran2=en2.transformation;
recurse=true;
hidden=true;
gr_entities1.intersect_with recurse, gr_tran1, en2, gr_tran2, hidden, en2
本帖最后由 tzbm123456 于 2021-10-25 07:23 编辑
entities = Sketchup.active_model.entities
# (!) You created a circle with so many edges that at the scale
# you drew it they where pushing the boundary of how small
# units SketchUp can handle. (1/1000th inch).
# If you has Edge Outline style enabled you could see that
# not all edges where fully merged.
# I reduced the curve segments from 360 to 180.
# (Do you really need such a high mesh density anyway?)
# make tube
tube = entities.add_group
tube_inner = tube.entities.add_circle Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1), 5, 180
tube_outer = tube.entities.add_circle Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1), 6, 180
cross_section_face = tube.entities.add_face tube_outer
inner_face = tube.entities.add_face tube_inner
tube.entities.erase_entities inner_face
cross_section_face.pushpull -10, false
# make a cylinder that punches through the wall
hole_punch = entities.add_group
hole_outer = hole_punch.entities.add_circle Geom::Point3d.new(0,0, 5), Geom::Vector3d.new(0,1,0), 3, 180
face = hole_punch.entities.add_face hole_outer
face.pushpull 10, false
# draw the intersection lines and erase the hole punch
#entities.intersect_with true, hole_punch.transformation, tube, tube.transformation, true, hole_punch
hole_punch.entities.intersect_with true, hole_punch.transformation, tube, tube.transformation, true, tube
hole_punch.erase!
# Find all the edges that belong to the Circle elements drawn
# earlier (including the ones push-pulled).
# (Could also collect these earlier before intersecting by
#collecting all non-smooth edges.)
#<选择Edge实体,并选择其属于curve的Edge实体>
circles = tube.entities.grep(Sketchup::Edge).select { |e| e.curve }.uniq
# Then we pick out all the faces that isn't connected to these edges and erase them.
#<选择Face实体,并选择其Edges集合于circles相交为空的Face实体>
new_faces = tube.entities.grep(Sketchup::Face).select { |f| (f.edges & circles).empty? }
entities.erase_entities( new_faces )
页:
[1]