1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
pload OCAF
pload TOPTEST
pload XDE
cpulimit 1000
# Create a new document and set UndoLimit
NewDocument D BinXCAF
UndoLimit D 100
# Local length unit value
set lengthunit_start ""
# Open a transaction
NewCommand D
# Reads resource file, returns options from file as key-value dict
proc parse_resource_file {theFileName} {
# Creating empty dictionary
set aDict [dict create];
# Check for resource file
if { [info exists theFileName] == 0 } {
puts "Error: resource file \"${theFileName}\" isn't found"
return $aDict
}
# Open a resource file
set aFD [open "${theFileName}" "rb"]
set aLineNo 0
# Read line by line
while {[gets $aFD aLine] !=-1 } {
incr aLineNo
# Clear the line from comment
if {[regexp {(^[^!]+)} $aLine match aClearLine]} {
# remove spaces
set aClearLine [string trim $aClearLine]
if {[string length $aClearLine] != 0} {
if {[regexp {(\S+)\s*:\s*(\S*)} $aClearLine match aKey aValue]} {
dict set aDict $aKey $aValue
} else {
puts "Error: syntax error in resource file at line: ${aLineNo}"
}
}
}
}
close $aFD
return $aDict
}
# Creates new resource file with options as key-value dict
proc create_resource_file {theFileName theOptions} {
# Open a resource file
set aFD [open "${theFileName}" "wb"]
set aLineNo 0
# Write line by line
dict for {aKey aValue} $theOptions {
puts $aFD "${aKey} : ${aValue}"
}
close $aFD
}
|