Modify op path2: Difference between revisions
From Macros Wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
args opnum, dist | {| | ||
local numfeat, ifeat, itype | |args opnum, dist | ||
local xs, ys, zs, xe, ye, ze, xc, yc, zc, rad, idir | |- | ||
local x1, y1, z1, x2, y2, z2, ang1, ang2, ang3 | |local numfeat, ifeat, itype | ||
|- | |||
|local xs, ys, zs, xe, ye, ze, xc, yc, zc, rad, idir | |||
! get a copy of the current op path | |- | ||
! --------------------------------- | |local x1, y1, z1, x2, y2, z2, ang1, ang2, ang3 | ||
|- | |||
get_op_num_feat opnum, numfeat ! get the number of features | | | ||
if numfeat<1 then goto done | |- | ||
| | |||
define_path_list 1 | |- | ||
|! get a copy of the current op path | |||
select_op_path_type main | |- | ||
get_op_path opnum get a copy of the op path | |! --------------------------------- | ||
|- | |||
| | |||
<nowiki>get_op_path_start opnum, xs, ys, zs</nowiki> | |- | ||
<nowiki>create_path 1, xs, ys, zs</nowiki> | |get_op_num_feat opnum, numfeat || ! get the number of features | ||
|- | |||
|if numfeat<1 then goto done || ! make sure there is at least 1 | |||
! divide it up | |- | ||
! ------------ | | | ||
|- | |||
for ifeat=1 to numfeat | |define_path_list 1 || ! create path list | ||
|- | |||
:get_op_feat_type opnum, ifeat, itype | | | ||
:progress_set (ifeat / numfeat) | |- | ||
|select_op_path_type main || ! select the main path | |||
:if itype = feat_type_line then goto edit_line | |- | ||
:if itype = feat_type_arc then goto edit_arc | |get_op_path opnum get a copy of the op path | ||
|- | |||
! not a line or arc, just use this feature as it is | |! this will be path zero | ||
|- | |||
:add_path_feat 1, 0, ifeat | | | ||
|- | |||
:continue | |<nowiki>get_op_path_start opnum, xs, ys, zs</nowiki> | ||
|- | |||
<nowiki>:</nowiki>edit_line | |<nowiki>create_path 1, xs, ys, zs</nowiki> || ! start a new path | ||
:get_op_feat_start opnum, ifeat, xs, ys, zs | |- | ||
:get_op_feat_end opnum, ifeat, xe, ye, ze | | | ||
:get_op_feat_angles opnum, ifeat, ang1, ang2, ang3 | |- | ||
| | |||
:x1 = xs + ((xe - xs) / 2) | |- | ||
:y1 = ys + ((ye - ys) / 2) | |! divide it up | ||
:z1 = zs + ((ze - zs) / 2) | |- | ||
|! ------------ | |||
:ang2 = ang1 + 90 | |- | ||
| | |||
:x2 = x1 + dist * cos(ang2) | |- | ||
:y2 = y1 + dist * sin(ang2) | |for ifeat=1 to numfeat | ||
:z2 = z1 | |- | ||
| | |||
:add_path_line 1, x1, y1, z1 | |- | ||
:add_path_line 1, x2, y2, z2 | |:get_op_feat_type opnum, ifeat, itype | ||
:add_path_line 1, x1, y1, z1 | |- | ||
:add_path_line 1, xe, ye, ze | |:progress_set (ifeat / numfeat) | ||
|- | |||
:continue | | | ||
|- | |||
<nowiki>:</nowiki>edit_arc | |:if itype = feat_type_line then goto edit_line | ||
|- | |||
:get_op_feat_start opnum, ifeat, xs, ys, zs | |:if itype = feat_type_arc then goto edit_arc | ||
:get_op_feat_end opnum, ifeat, xe, ye, ze | |- | ||
:get_op_feat_angles opnum, ifeat, ang1, ang2, ang3 | | | ||
:get_op_feat_arc_data opnum, ifeat, rad, idir, xc, yc, zc | |- | ||
:if idir=1 then ang3 = -ang3 | | ||! not a line or arc, just use this feature as it is | ||
|- | |||
:ang1 = ang1 + (ang3 / 2) | | | ||
:if ang1>360 then ang1 = ang1 - 360 | |- | ||
:if ang1<0 then ang1 = ang1 + 360 | |:add_path_feat 1, 0, ifeat || ! copy this feat to the new path | ||
|- | |||
:ang2 = ang1 | | | ||
:if idir=0 then ang2 = ang1 + 180 | |- | ||
:if ang2 > 360 then ang2 = ang2 - 360 | |:continue | ||
|- | |||
:x1 = xc + rad * cos(ang1) | | | ||
:y1 = yc + rad * sin(ang1) | |- | ||
:z1 = zs + ((ze - zs) / 2) | |<nowiki>:</nowiki>edit_line | ||
|- | |||
:x2 = x1 + dist * cos(ang2) | |:get_op_feat_start opnum, ifeat, xs, ys, zs | ||
:y2 = y1 + dist * sin(ang2) | |- | ||
:z2 = z1 | |:get_op_feat_end opnum, ifeat, xe, ye, ze | ||
|- | |||
:if idir=1 then add_path_arc 1, x1, y1, z1, xc, yc, zc, rad, cw | |:get_op_feat_angles opnum, ifeat, ang1, ang2, ang3 | ||
:if idir#1 then add_path_arc 1, x1, y1, z1, xc, yc, zc, rad, ccw | |- | ||
| | |||
:add_path_line 1, x2, y2, z2 | |- | ||
:add_path_line 1, x1, y1, z1 | |:x1 = xs + ((xe - xs) / 2) | ||
|- | |||
:if idir=1 then add_path_arc 1, xe, ye, ze, xc, yc, zc, rad, cw | |:y1 = ys + ((ye - ys) / 2) | ||
:if idir#1 then add_path_arc 1, xe, ye, ze, xc, yc, zc, rad, ccw | |- | ||
|:z1 = zs + ((ze - zs) / 2) | |||
next ifeat | |- | ||
| | |||
|- | |||
! end of path | |:ang2 = ang1 + 90 | ||
! ----------- | |- | ||
| | |||
copy_path 1, 0 | |- | ||
set_op_path opnum | |:x2 = x1 + dist * cos(ang2) | ||
delete_path_list | |- | ||
|:y2 = y1 + dist * sin(ang2) | |||
<nowiki>:</nowiki>done | |- | ||
|:z2 = z1 | |||
|- | |||
| | |||
|- | |||
|:add_path_line 1, x1, y1, z1 || ! mid way along the feature | |||
|- | |||
|:add_path_line 1, x2, y2, z2 || ! out by the given distance | |||
|- | |||
|:add_path_line 1, x1, y1, z1 || ! back to mid point | |||
|- | |||
|:add_path_line 1, xe, ye, ze || ! end of original features | |||
|- | |||
| | |||
|- | |||
|:continue | |||
|- | |||
| | |||
|- | |||
|<nowiki>:</nowiki>edit_arc | |||
|- | |||
| | |||
|- | |||
|:get_op_feat_start opnum, ifeat, xs, ys, zs | |||
|- | |||
|:get_op_feat_end opnum, ifeat, xe, ye, ze | |||
|- | |||
|:get_op_feat_angles opnum, ifeat, ang1, ang2, ang3 | |||
|- | |||
|:get_op_feat_arc_data opnum, ifeat, rad, idir, xc, yc, zc | |||
|- | |||
|:if idir=1 then ang3 = -ang3 | |||
|- | |||
| | |||
|- | |||
|:ang1 = ang1 + (ang3 / 2) || ! angle mid way around arc | |||
|- | |||
|:if ang1>360 then ang1 = ang1 - 360 | |||
|- | |||
|:if ang1<0 then ang1 = ang1 + 360 | |||
|- | |||
| | |||
|- | |||
|:ang2 = ang1 | |||
|- | |||
|:if idir=0 then ang2 = ang1 + 180 | |||
|- | |||
|:if ang2 > 360 then ang2 = ang2 - 360 | |||
|- | |||
| | |||
|- | |||
|:x1 = xc + rad * cos(ang1) | |||
|- | |||
|:y1 = yc + rad * sin(ang1) | |||
|- | |||
|:z1 = zs + ((ze - zs) / 2) | |||
|- | |||
| | |||
|- | |||
|:x2 = x1 + dist * cos(ang2) | |||
|- | |||
|:y2 = y1 + dist * sin(ang2) | |||
|- | |||
|:z2 = z1 | |||
|- | |||
| | |||
|- | |||
|:if idir=1 then add_path_arc 1, x1, y1, z1, xc, yc, zc, rad, cw | |||
|- | |||
|:if idir#1 then add_path_arc 1, x1, y1, z1, xc, yc, zc, rad, ccw | |||
|- | |||
| | |||
|- | |||
|:add_path_line 1, x2, y2, z2 || ! out by the given distance | |||
|- | |||
|:add_path_line 1, x1, y1, z1 || ! back to mid point | |||
|- | |||
| | |||
|- | |||
|:if idir=1 then add_path_arc 1, xe, ye, ze, xc, yc, zc, rad, cw | |||
|- | |||
|:if idir#1 then add_path_arc 1, xe, ye, ze, xc, yc, zc, rad, ccw | |||
|- | |||
| | |||
|- | |||
|next ifeat | |||
|- | |||
| | |||
|- | |||
| | |||
|- | |||
|! end of path | |||
|- | |||
|! ----------- | |||
|- | |||
| | |||
|- | |||
|copy_path 1, 0 || ! copy the new path to path zero | |||
|- | |||
|set_op_path opnum || ! set the op path to use path zero | |||
|- | |||
|delete_path_list || ! delete the list of paths | |||
|- | |||
| | |||
|- | |||
|<nowiki>:</nowiki>done | |||
|- | |||
|} |
Revision as of 20:11, 27 July 2010
args opnum, dist | |
local numfeat, ifeat, itype | |
local xs, ys, zs, xe, ye, ze, xc, yc, zc, rad, idir | |
local x1, y1, z1, x2, y2, z2, ang1, ang2, ang3 | |
! get a copy of the current op path | |
! --------------------------------- | |
get_op_num_feat opnum, numfeat | ! get the number of features |
if numfeat<1 then goto done | ! make sure there is at least 1 |
define_path_list 1 | ! create path list |
select_op_path_type main | ! select the main path |
get_op_path opnum get a copy of the op path | |
! this will be path zero | |
get_op_path_start opnum, xs, ys, zs | |
create_path 1, xs, ys, zs | ! start a new path |
! divide it up | |
! ------------ | |
for ifeat=1 to numfeat | |
:get_op_feat_type opnum, ifeat, itype | |
:progress_set (ifeat / numfeat) | |
:if itype = feat_type_line then goto edit_line | |
:if itype = feat_type_arc then goto edit_arc | |
! not a line or arc, just use this feature as it is | |
:add_path_feat 1, 0, ifeat | ! copy this feat to the new path |
:continue | |
:edit_line | |
:get_op_feat_start opnum, ifeat, xs, ys, zs | |
:get_op_feat_end opnum, ifeat, xe, ye, ze | |
:get_op_feat_angles opnum, ifeat, ang1, ang2, ang3 | |
:x1 = xs + ((xe - xs) / 2) | |
:y1 = ys + ((ye - ys) / 2) | |
:z1 = zs + ((ze - zs) / 2) | |
:ang2 = ang1 + 90 | |
:x2 = x1 + dist * cos(ang2) | |
:y2 = y1 + dist * sin(ang2) | |
:z2 = z1 | |
:add_path_line 1, x1, y1, z1 | ! mid way along the feature |
:add_path_line 1, x2, y2, z2 | ! out by the given distance |
:add_path_line 1, x1, y1, z1 | ! back to mid point |
:add_path_line 1, xe, ye, ze | ! end of original features |
:continue | |
:edit_arc | |
:get_op_feat_start opnum, ifeat, xs, ys, zs | |
:get_op_feat_end opnum, ifeat, xe, ye, ze | |
:get_op_feat_angles opnum, ifeat, ang1, ang2, ang3 | |
:get_op_feat_arc_data opnum, ifeat, rad, idir, xc, yc, zc | |
:if idir=1 then ang3 = -ang3 | |
:ang1 = ang1 + (ang3 / 2) | ! angle mid way around arc |
:if ang1>360 then ang1 = ang1 - 360 | |
:if ang1<0 then ang1 = ang1 + 360 | |
:ang2 = ang1 | |
:if idir=0 then ang2 = ang1 + 180 | |
:if ang2 > 360 then ang2 = ang2 - 360 | |
:x1 = xc + rad * cos(ang1) | |
:y1 = yc + rad * sin(ang1) | |
:z1 = zs + ((ze - zs) / 2) | |
:x2 = x1 + dist * cos(ang2) | |
:y2 = y1 + dist * sin(ang2) | |
:z2 = z1 | |
:if idir=1 then add_path_arc 1, x1, y1, z1, xc, yc, zc, rad, cw | |
:if idir#1 then add_path_arc 1, x1, y1, z1, xc, yc, zc, rad, ccw | |
:add_path_line 1, x2, y2, z2 | ! out by the given distance |
:add_path_line 1, x1, y1, z1 | ! back to mid point |
:if idir=1 then add_path_arc 1, xe, ye, ze, xc, yc, zc, rad, cw | |
:if idir#1 then add_path_arc 1, xe, ye, ze, xc, yc, zc, rad, ccw | |
next ifeat | |
! end of path | |
! ----------- | |
copy_path 1, 0 | ! copy the new path to path zero |
set_op_path opnum | ! set the op path to use path zero |
delete_path_list | ! delete the list of paths |
:done |