I have written the code but it’s not drawing in every face of the model. I have written code for the single inclined line.
def draw_hatch face,line_type,space,direction
=begin
left_bottom=face.bounds.corner(0)
puts left_bottom
right_bottom=face.bounds.corner(1)
puts right_bottom
right_top=face.bounds.corner(5)
puts right_top
left_top=face.bounds.corner(4)
puts left_top
=end
pts = face.vertices.map(&:position)
pts = pts.sort_by {|pt| pt.x }
if pts[0].z<pts[1].z
left_bottom=pts[0]
left_top=pts[1]
else
left_bottom=pts[1]
left_top=pts[0]
end
if pts[2].z<pts[3].z
right_bottom=pts[2]
right_top=pts[3]
else
right_bottom=pts[3]
right_top=pts[2]
end
if(space=="close")
count=20
count_half1=count/2
count_half2=count/2-1
elsif space=="avg"
count=15
count_half1=count/2
count_half2=count/2
else
count=10
count_half1=count/2
count_half2=count/2-1
end
temp1=count_half1
temp2=count_half2
if(line_type=="single" && direction=="right")
len_lt_rt=left_top.distance(right_top)
len_lt_lb=left_top.distance(left_bottom)
gap_lt_rt=len_lt_rt/(count_half1+1)
gap_lt_lb=len_lt_lb/(count_half1+1)
dir_lt_rt=left_top.vector_to(right_top)
dir_lt_lb=left_top.vector_to(left_bottom)
while(count_half1>0)
pt1=left_top.offset(dir_lt_rt,gap_lt_rt*count_half1)
pt2=left_top.offset(dir_lt_lb,gap_lt_lb*count_half1)
line1=Sketchup.active_model.entities.add_line(pt1,pt2)
count_half1=count_half1-1
end
line2=Sketchup.active_model.entities.add_line(left_bottom,right_top)
len_rb_rt=right_bottom.distance(right_top)
len_rb_ld=right_bottom.distance(left_bottom)
gap_rb_rt=len_rb_rt/(count_half2+1)
gap_rb_lb=len_rb_ld/(count_half2+1)
dir_rb_rt=right_bottom.vector_to(right_top)
dir_rb_lb=right_bottom.vector_to(left_bottom)
while(count_half2>0)
pt3=right_bottom.offset(dir_rb_rt,gap_rb_rt*count_half2)
pt4=right_bottom.offset(dir_rb_lb,gap_rb_lb*count_half2)
line3=Sketchup.active_model.entities.add_line(pt3,pt4)
count_half2=count_half2-1
end
end
count_half1=temp1
count_half2=temp2
if(line_type=="single" && direction=="left")
len_rt_rb=right_top.distance(right_bottom)
len_rt_lt=right_top.distance(left_top)
gap_rt_rb=len_rt_rb/(count_half1+1)
gap_rt_lt=len_rt_lt/(count_half1+1)
dir_rt_rb=right_top.vector_to(right_bottom)
dir_rt_lt=right_top.vector_to(left_top)
while(count_half1>0)
pt5=right_top.offset(dir_rt_rb,gap_rt_rb*count_half1)
pt6=right_top.offset(dir_rt_lt,gap_rt_lt*count_half1)
line4=Sketchup.active_model.entities.add_line(pt5,pt6)
count_half1=count_half1-1
end
line5=Sketchup.active_model.entities.add_line(left_top,right_bottom)
len_lb_lt=left_bottom.distance(left_top)
len_lb_rb=left_bottom.distance(right_bottom)
gap_lb_lt=len_lb_lt/(count_half2+1)
gap_lb_rb=len_lb_rb/(count_half2+1)
dir_lb_lt=left_bottom.vector_to(left_top)
dir_lb_rb=left_bottom.vector_to(right_bottom)
while(count_half2>0)
pt7=left_bottom.offset(dir_lb_lt,gap_lb_lt*count_half2)
pt8=left_bottom.offset(dir_lb_rb,gap_lb_rb*count_half2)
line6=Sketchup.active_model.entities.add_line(pt7,pt8)
count_half2=count_half2-1
end
end
end
draw_hatch Sketchup.active_model.selection[0],"single","close","right"
if i give input=‘right’ then output should be like this
if i give input=‘left’ then output should be like this