REM 交点分割
echo off
REM #jww
REM #cd
REM #h2
REM #c切断間隔(実寸mm) 無指定=0 :/_/a
REM #e
copy jwc_temp.txt temp.txt > nul
cscript //nologo 交点分割.rb temp.txt %1 > jwc_temp.txt
◎スクリプトファイル(ファイル名 交点分割.rb)
# 直線の交点分割 外部変形Rubyスクリプト
BEGIN{
print "hd\n" # 選択したデータの削除
$kankaku =0 #デフォルト値
while ARGV.length > 1
case argument=ARGV.pop
when/^\/a/
$kankaku=argument[2..-1].to_f
end
end
$tate=Array.new;$tatey1=Array.new
$tatey2=Array.new;$yoko=Array.new
$yokox1=Array.new;$yokox2=Array.new
$lyy=Array.new;$lyt=Array.new
$lcy=Array.new;$lct=Array.new
$lty=Array.new;$ltt=Array.new
}
def main
while ARGF.gets
xy =split
if xy[0]=~/^ci|^pt|^ch|^cs|^cn/;print $_;end
if xy[0]=~/^ly/;$senly=xy[0];end
if xy[0]=~/^lc/;$senlc=xy[0];end
if xy[0]=~/^lt/;$senlt=xy[0];end
if xy[0]=~ /^[0-9]|^-/
xy.collect!{ |item| item.to_f }# 数値化
if xy[0]==xy[2]
if xy[3] < xy[1];y=xy[3];xy[3]=xy[1];xy[1]=y;end
$tate.push(xy[0]);$tatey1.push(xy[1]);$tatey2.push(xy[3])
$lyt.push($senly);$lct.push($senlc);$ltt.push($senlt)
end
if xy[1]==xy[3]
if xy[2] < xy[0];x=xy[2];xy[2]=xy[0];xy[0]=x;end
$yoko.push(xy[1]);$yokox1.push(xy[0]);$yokox2.push(xy[2])
$lyy.push($senly);$lcy.push($senlc);$lty.push($senlt)
end
end
end
$ta=$tate.sort;$tay1=$tatey1.sort;$tay2=$tatey2.sort;$x=$tate.size
n=-1;while (n < $yoko.size-1);n += 1
print $lyy[n]+"\n";print $lcy[n]+"\n";print $lty[n]+"\n"
yokosen($yokox1[n],$ta[0]-$kankaku,$yoko[n])
yokosen($yokox2[n],$ta[$x-1]+$kankaku,$yoko[n]);end
m=-1;while (m < $tate.size-2);m +=1
w=-1;while (w < $yoko.size-1);w +=1
print $lyy[w]+"\n";print $lcy[w]+"\n";print $lty[w]+"\n"
yokosen($ta[m]+$kankaku,$ta[m+1]-$kankaku,$yoko[w])
end
end
$yo=$yoko.sort;$yox1=$yokox1.sort;$yox2=$yokox2.sort;$y=$yoko.size
r=-1;while (r < $tate.size-1);r += 1
print $lyt[r]+"\n";print $lct[r]+"\n";print $ltt[r]+"\n"
tatesen($tatey1[r],$yo[0]-$kankaku,$tate[r])
tatesen($tatey2[r],$yo[$y-1]+$kankaku,$tate[r]);end
s=-1;while (s < $yoko.size-2);s +=1
t=-1;while (t < $tate.size-1);t +=1
print $lyt[t]+"\n";print $lct[t]+"\n";print $ltt[t]+"\n"
tatesen($yo[s]+$kankaku,$yo[s+1]-$kankaku,$tate[t]);end;end
end
def yokosen( x1,x2, y1)
printf("%e %e %e %e\n", x1, y1, x2, y1)
end
def tatesen( y1,y2, x1)
printf("%e %e %e %e\n", x1, y1, x1, y2)
end
main()