Hello All,
I am working on a script that, until Sketchup does this natively, allows me to assign a material (with pattern) to a section cut.
It creates a cutting plane (basically a giant circle using the model bounds) at the level of certain section planes and intersects it with objects in the model meeting my criteria.
So first it descends into certain groups and collects qualifying child entities into an array called @@ents_to_cut
. Qualifying child entities may be nested within several parent entities.
Then using intersect_with()
it creates edges where the cutting plane meets @@ents_to_cut
.
Iâm having problems getting the resulting section to end up in the correct location, I think because I am not tracking transformations correctly as I descend into each parent.
Here is how I am doing it currentlyâŚ
# track transformations as ents are probed
@@transformation_array = [Geom::Transformation.new()]
def self.probe_for_solids(parent_ent)
#print "\n------------probe_for_solids for parent_ent: #{parent_ent}------------\n\n"
# probe ents meeting main criteria
if
parent_ent.is_a? Sketchup::Group &&
(
parent_ent.layer.name.include?('EXIST') ||
parent_ent.layer.name.include?('PROP') ||
parent_ent.layer.name.include?('OPT') ||
)
print "probing #{parent_ent.name} - containing #{parent_ent.entities.length} children\n"
#iterate children to find manifold solids
parent_ent.entities.each_with_index{|child_ent, index|
if child_ent.is_a?(Sketchup::Group) && child_ent.manifold?
print "keeping child group #{index}: #{child_ent.name} because it is manifold\n"
this_transformation = child_ent.transformation
@@ents_to_cut.push([child_ent,parent_ent.layer.name,this_transformation])
elsif child_ent.is_a?(Sketchup::ComponentInstance) || child_ent.is_a?(Sketchup::Group)
print "child #{index}: is non-manifold group or component - probing deeper\n"
#store the transformation of the current parent entity
@@transformation_array.push(child_ent.transformation);
#send back to this function for deeper probing
probe_for_solids(child_ent)
end
}
else
print "#{parent_ent} - skipping non qualifying entity \n"
end
end
And here is the actual intersectionâŚ
cutting_circle.entities.intersect_with(
false,
ent_to_cut[2],
@@section_container,
@@section_container.transformation,
false,
ent_to_cut[0]
)
So, I have tried all of the following definitions of `this_transformationâ and Iâm not having any success.
#this_transformation = parent_ent.transformation * child_ent.transformation
#this_transformation = parent_ent.transformation
#this_transformation = ORIGIN
and these actually do not produce a section at all!
#this_transformation = @@transformation_array.inject(:*) * child_ent.transformation
#this_transformation = @@transformation_array.inject(:*) * parent_ent.transformation
#this_transformation = @@transformation_array.inject(:*)
Any tips would be greatly appreciated. Thanks.