How to query the number of blocks in the model? For example, after Ordinary Kriging estimation, I want to query the number of blocks for each pass.
How to query the number of blocks in the model? For example, after Ordinary Kriging estimation, I want to query the number of blocks for each pass.
Run a BM report by calculating aggregate value for the pass attribute. Constraint only to one pass value at time. Divide by number of pass to get number of blocks. This methodology expects that you have an integer number stored into an attribute after each pass. This however calculates also all sub blocks, so if you want only user blocks you probably need to use export to CSV function and do the math in Excel.
Yes, the block model report contains sub blocks. I will try other method. Thanks!
Couldn't resist writing code to calculate the user blocks.
Copy and paste code from below to a file.
#========================================================
#
# Calculate estimated user blocks
# -------------------------------
#
# This script can be used to calculate how many user
# blocks have specified value in specified attribute.
# This can be used to calculate for instance the number
# of estimated user blocks.
#
# The script reports both number of all existing blocks
# which have given value, including subblocks.
#
# Usage: change the values of variables ATTRIBUTE_NAME
# and ATTRIBUTE_VALUE to match your requirements.
# Open the block model in Surpac / make sure the model
# you want to report is the active block model.
# Run the script and results are written into the message
# window.
#
# (c) WSP Finland Ltd. 2025 | http://www.wsp.com
# Contact: tuomas.rantanen@wsp.com
#
# Change log:
# -------------------------------------------------------
# Date Version Comments
# 2024-06-25 1.0 Initial release
#
#========================================================
# Change name of the attribute and attribute value you want to count
set ATTRIBUTE_NAME "pass"
set ATTRIBUTE_VALUE "1"
#========================================================
#
# MAIN
#
#========================================================
# Find out the subdivision level at which user blocks exist.
# A block model must already be loaded for this to work.
set bm [SclBlockModelGetCurrentModel]
SclBlockModelGetParameter $bm userblocksubdivisionlevel userLevel
SclBlockModelGetParameter $bm maxblocksubdivisionlevel maxLevel
# Get bit count of maximum subdivision level
# These are the least significant bits of block index
set temp $maxLevel
set msb 1
while {$temp > 1} {
set temp [expr {$temp >> 1}]
incr msb
}
# Calculate bit mask for user block size
set mask [expr {(1 << $userLevel*3)-1}]
# Save a temporary constraint file to speed up the reporting.
set status [ SclFunction "BM MAKE CONSTRAINT" {
frm20111={
{
constraints=table { not op contype location id extension rnga rngb lbound ubound ext } {
{ "" "=" "BLOCK" "$ATTRIBUTE_NAME" "$ATTRIBUTE_VALUE" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
{ "" "" "" "" "" "" "" "" "" "" "" }
}
conexp=""
confile="tempcostraint"
allowOverlapping="N"
keep_blocks="N"
}
}
}]
# Generate iterator
set iterator [SclBlockModelLevelIterateStart $bm $maxLevel [list $ATTRIBUTE_NAME] constraintFile=tempcostraint.con]
# Iterate through the blocks at smallest subdivision level
while {[set index [SclBlockModelIterateNext $iterator blockValue]] != -1} {
if {$ATTRIBUTE_VALUE == $blockValue} {
# Determine user block size block index for this sub block, without division level bits.
set userblockindex [expr {$index >> $msb & $mask}]
# Take a note of the user block
set blocks($userblockindex) ""
}
}
SclBlockModelIterateEnd $iterator
# Report results. Size of the blocks array is equal to number of user blocks
# for which at least one sub block has given value in given attribute.
puts "We have [array size blocks] user blocks where attribute $ATTRIBUTE_NAME = $ATTRIBUTE_VALUE is specified in at least one sub-block."
# Delete temporary constraint file
file delete tempcostraint.con
return