######################################################################
#
# Macro Name    : g:/mining/surpac/survey/ug/block_model_dev_for_database.tcl
#
# Version       : Surpac Vision V5.0-K
#
# Creation Date : Mon Feb 28 09:48:56 2005
#
# Description   :  This macro slices an open block model, lays over a grid file (grid1.str) 
#                  and compiles these into one file bm-grid1.str ready to import into the grade
#                  control database
######################################################################
######################################################################
   #start of input form
set form {
GuidoForm exampleForm {
  -label "Block Model Extraction for Grade Control Database"
  -default_buttons

  GuidoField Lwr_Level {
    -label "Lowest Level Slice"
    -display_length 5
    -null false
 }
 GuidoField Upr_Level {
    -label "Upper Level Slice"
    -display_length 5
    -null false
 }

   GuidoField Increments {
    -label "Level Increments to Slice"
    -display_length 5
    -default 10
    -null false
 }

 }}
 SclCreateGuidoForm form_handle $form {}

$form_handle SclRun {}

# End of Input form
 ######################################################################set status [ SclFunction "BM EXTRACT SECTIONS" {
 set status [ SclFunction "BM EXTRACT SECTIONS" {
  frm20042={
    {
      scr_type="NORMAL to Z Axis"
      scr_range="$Lwr_Level,$Upr_Level,$Increments"
      scr_name="defgrp"
    }
  }
  frm20048={
    {
      location="bm-cent"
      extract_type="Centroids"
      scr_coords="Real World"
      constrain="N"
      report_attributes="N"
      attributes={
        {
          attribute="cu"
        }
      }
      class_att_name="cu"
      class_att_rng="0,10,.2"
      class_char_list={
        {
          char_val=""
          string_no="1"
        }
      }
      section_face_block="Previous"
    }
  }
  frm45003={
    {
      _action="Yes to All"
    }
  }
}]


#################################################
# Start of loop

set Level $Lwr_Level
   while {$Level <= $Upr_Level} {

puts "Level $Level"
#############
set status [ SclFunction "RECALL FILE" {
  frm00236={
    {
      location="dummy"
      rid="1"
      string_rng=""
      ftype="S"
      swa_desc="Y"
      append="R"
      styles_file=""
      rescale="Y"
      swa_name="main graphics layer"
    }
  }
}]

set status [ SclFunction "GRAPHICS LAYER MATHS" {
  frm00702={
    {
      strrange="Y"
      main=table { str_range constraint field expr } {
        { "" "" "z" "$Level" }

      }
    }
  }
}]

set status [ SclFunction "RECALL FILE" {
  frm00236={
    {
      location="bm-cent"
      rid="$Level"
      string_rng=""
      ftype="S"
      swa_desc="Y"
      append="A"
      rescale="N"
      swa_name="main graphics layer"
    }
  }
}]

set status [ SclFunction "ZOOM ALL" {} ]

set status [ SclFunction "GRAPHICS CREATE DTM" {
  frm01311={
    {
      _action="apply"
    }
  }
}]

set status [ SclFunction "SAVE FILE" {
  frm00287={
    {
      location="bm-cent"
      rid="$Level"
      ftype="D"
      purpose="Block Model Section"
      range=""
      format="binary"
    }
  }
}]

set status [ SclFunction "EXIT GRAPHICS" {} ]

set status [ SclFunction "STRINGS OVER DTM" {
  frm00209={
    {
      dtmloc="bm-cent"
      dtmid="$Level"
      swadesc="Y"
      bdyopt="N"
      interp="N"
      inploc="grid"
      rinpid="1"
      strange=""
      outloc="bm-grid"
      outid="$Level"
    }
  }
  frm00608={
    {
      strfld1="Z"
      op1="="
      dtmfld1="Z"
      strfld2="D1"
      op2="="
      dtmfld2="D1"
      strfld3=""
      op3="="
      dtmfld3=""
      strfld4=""
      op4="="
      dtmfld4=""
      strfld5=""
      op5="="
      dtmfld5=""
      strfld6=""
      op6="="
      dtmfld6=""
      strfld7=""
      op7="="
      dtmfld7=""
      strfld8=""
      op8="="
      dtmfld8=""
      strfld9=""
      op9="="
      dtmfld9=""
      strfld10=""
      op10="="
      dtmfld10=""
    }
  }
}]


set Level [expr $Level+$Increments]
   }
# End of Loop
# Combines files
set status [ SclFunction "RECALL FILE" {
  frm00236={
    {
      location="bm-grid"
      rid="$Lwr_Level,$Upr_Level,$Increments"
      string_rng=""
      ftype="S"
      swa_desc="Y"
      append="R"
      styles_file=""
      rescale="Y"
      swa_name="main graphics layer"
    }
  }
}]

set status [ SclFunction "SAVE FILE AS" {
  output_file="bm-grid1.str"
  output_type="Surpac String Files"
  output_filenames=""
  surpac_range=""
  surpac_format="text"
  surpac_purpose="Import of BM into Access"
  frm00121={
    {
      _action="apply"
    }
  }
}]

puts "Rename bm-grid1.str to bm-grid1.csv then import into Access"
