Hello. This is a question about a problem I encountered in a script I prepared using “followme path” in Sketchup. I created a “merge” script that normally works properly and works as I want. But whenever the “followme reference lines” that I set the direction of intersect, a clean surface is not formed as in the “merge” process. The surfaces are intertwined as in the picture.
I created a code of my own to solve this problem. But this time the “merge” process did not work either. I wanted to ask you if i am on the right track. This is my code that works correctly, but after intersecting within itself, it is “nonsense”
class FollowPathRec
def initialize
@input_points = []
@current_input = Sketchup::InputPoint.new
@start_point = nil
end
def activate
@input_points.clear
@start_point = nil
end
def deactivate(view)
create_face if @input_points.length >= 2
view.invalidate
end
def onMouseMove(flags, x, y, view)
@current_input.pick(view, x, y)
view.invalidate
end
def onLButtonDown(flags, x, y, view)
@current_input.pick(view, x, y)
if @current_input.valid?
if @input_points.empty?
@start_point = @current_input.position
end
@input_points << @current_input.position
view.invalidate
end
end
CURSOR_PENCIL = 632
def onSetCursor
UI.set_cursor(CURSOR_PENCIL)
end
def onKeyUp(key, repeat, flags, view)
# I have defined here the tasks to be performed when I press the keys.
end
private
def create_face
# I created "siva" named groups with followme path.
end
def merge_groups
entities = Sketchup.active_model.entities
groups1 = entities.find_all { |e| e.is_a?(Sketchup::Group) && e.name == 'siva' }
merged_group1 = groups1.shift
groups1.each do |group|
intersection1 = merged_group1.bounds.intersect(group.bounds)
if intersection1.valid?
merged_group1 = merged_group1.union(group)
end
end
merged_group1.make_unique
merged_group1.name = 'siva'
end
end
model = Sketchup.active_model
follow_path_rec = FollowPathRec.new
Sketchup.active_model.select_tool(follow_path_rec)
And this is the code fragment where I tried to use “union” and “intersect_with” methods at the same time.
def merge_groups
entities = Sketchup.active_model.entities
groups1 = entities.find_all { |e| e.is_a?(Sketchup::Group) && e.name == 'siva' }
merged_group1 = groups1.shift
groups1.each do |group|
intersection1 = merged_group1.bounds.intersect(group.bounds)
if intersection1.valid?
merged_group1 = merged_group1.union(group)
end
end
groups2 = entities.find_all { |e| e.is_a?(Sketchup::Group) && e.name == 'duvar' }
merged_group2 = groups2.shift
groups2.each do |group|
intersection2 = merged_group2.bounds.intersect(group.bounds)
if intersection2.valid?
merged_group2 = merged_group2.union(group)
end
end
merged_group2.make_unique
merged_group2.name = 'duvar'
merged_group1.make_unique
merged_group1.name = 'siva'
end