!*****************************************************************
! LGS_0306AE_PRE / 2008-03-07 / Vertex Systems UK                  *
!                                                                *
!*****************************************************************

#INPUT#

L = get($LANGUAGE)

It = new_iterator("MACROBJ",0,"ROLED","THIS")
This = next_item(It)

Hdr$ = getprompt("ADD_3HOLE")
Prompt1$ = getprompt("SEL_PCE_OK")
Prompt2$ = getprompt("SEL_HPSTN")

if L==0 then
  then Hdr$ = "Suorakaiderein lisys uumaan"
  Prompt1$ = "Valitse osat valmis"
  Prompt2$ = "Osoita rein paikka"
endif

P = 1
X = 2
Y = 3
Z = 4

vec_to(P) 0,0,0
vec_to(X) 1,0,0
vec_to(Y) 0,1,0
vec_to(Z) 0,0,1

M = new_macro("","",P,X,Y,Z,1,1,0)
set_macro_param(M) "TASK","PICK_PIECES"
set_macro_param(M) "HEADER",Hdr$
set_macro_param(M) "PROMPT",Prompt1$
set_macro_param(M) "ROLE","PCE"

M = new_macro("","",P,X,Y,Z,1,1,0)
set_macro_param(M) "TASK","MARKINGS"
set_macro_param(M) "INPUT","0"

M= new_macro("","",P,X,Y,Z,1,1,0)
set_macro_param(M) "TASK","PICK_POINTS"
set_macro_param(M) "HEADER",Prompt1$
set_macro_param(M) "PROMPT",Prompt2$
set_macro_param(M) "ROLE","PNT"

#INPUT#


#BUILD#

!debug ./build.dbg

# include connection.def

It = new_iterator("MACROBJ",0,"ROLED","THIS")
This = next_item(It)
if !This then exit

HoleSize$= get_obj_param(This,"PRE~SIZE")
Offset= get_obj_param(This,"PRE~OFFSET")
Qty= get_obj_param(This,"PRE~QTY")
Mode= get_obj_param(This,"PRE~MODE")

PH = 1
X =  2
Y =  3
Z =  4
P =  5

Depth= mm_to_dwg(1.6)
Depth$= Depth

It = new_iterator("PROFOBJ",0,"ROLED","PCE")
loop
  Pce = next_item(It)
  exitif (!Pce)

  Hgt = get_section_param(Pce,"HEIGHT")
  if Mode == 1 then
    Offset2 = (Hgt-Offset-Offset)/(Qty-1)
  else
    Offset2 = Offset
  endif

  get_origin_pos(Pce) P,X,Y,Z

  Ip = new_iterator("",0,"ROLED","PNT")
  loop
    Pnt= next_item(Ip)
    exitif !Pnt
    get_origin_pos(Pnt) PH,X,Y,Z

    point_to_piece(P) Pce,PH

    Jnt = new_djoint("","",P,X,Y,Z,0)
    exitif (!Jnt)

    set_djmember(Jnt) Pce,"PCE"
    set_djparam(Jnt) "OFFSET",Offset2
    set_djparam(Jnt) "QTY",Qty

    Hole= new_feature("HOLE")
    if !Hole then exit
    set_djmember(Jnt) Hole,"W",1,Pce
    add_sobj(Pce) Hole
    set_obj_param(Hole) "T","1"
    set_origin_pos(Hole) P,X,Y,Z
    set_feat_param(Hole) "TYPE","CGX"
    set_obj_param(Hole) "SX",Offset2
    set_obj_param(Hole) "QTYX",Qty
    set_obj_param(Hole) "DIA",HoleSize$

    loop Qty
      Box= new_macro("MACRO_SYS","CYLINDER",P,X,Y,Z,1,1,0,0)
      if !Box the exit
      set_djmember(Jnt) Box,"B",1,Pce
      set_obj_param(Box) "DIA",HoleSize$
      set_same_tlink(Box) Pce
      set_same_visib(Box) Pce  
    endloop
  endloop

  set RETURN "1"
endloop

#BUILD#
