Modify op path2: Difference between revisions

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