Modify op path2

From Macros Wiki
Revision as of 17:47, 27 July 2010 by ConnerO (talk | contribs) (New page: args opnum, dist<br> local numfeat, ifeat, itype<br> local xs, ys, zs, xe, ye, ze, xc, yc, zc, rad, idir<br> local x1, y1, z1, x2, y2, z2, ang1, ang2, ang3<br> <br> <br> ! get a copy of t...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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