Below is a small chunk of code that reads in my current wall presets, a very simple system really but it is time to move to a more advanced hash system:
@Presetfilename = File.join(APPDATA_MEDEEK_WALL,"presets/WALL_PRESETS.txt")
if (File.exist?(@Presetfilename))
rowarray = preset_to_load.strip.split(',')
presetnum = rowarray[0]
presetname = rowarray[1]
# puts "#{presetnum} #{presetname}"
#############################################
#
# Reads preset file and finds wall to load
datastring = ''
foundkey = 0
begin
File.open(@Presetfilename, 'r') { |file|
file.each_line("\n") do |row|
# if row =~ /^#{presetnum}\|#{Regexp.escape(presetname)}\|/
if row =~ /^#{presetnum}\|#{presetname}\|/
datastring << "#{row}"
foundkey = 1
break
end
end
}
rescue StandardError => e
UI.messagebox(e)
puts "Error Message: #{e}"
end
if foundkey == 1
#############################################
#
# Dumps preset string into class variables
arry = datastring.strip.split('|')
# Basic Options
@Presetnum_p = arry[0].to_i
@Presetname_p = arry[1]
@Presetdate_p = arry[2]
@Walltype_p = arry[3]
@Walljust_p = arry[4]
@Wallhgt_p = arry[5].to_f
@Wallhdrhgt_p = arry[6].to_f
@Stud_depth_p = arry[7].to_f
@Stud_width_p = arry[8].to_f
@Studspacing_p = arry[9].to_f
@Studdir_p = arry[10]
@Std_offset_p = arry[11].to_f
@Plt_top_num_p = arry[12]
@Plt_top_p = arry[13].to_f
@Plt_btm_num_p = arry[14]
@Plt_btm_p = arry[15].to_f
@Plt_btm_pt_p = arry[16]
@Advwalloptions_p = arry[17]
# Corner Options
@Corner_start_p = arry[18]
@Cornerangle1_p = arry[19]
@Cornerstudthk1_p = arry[20].to_f
@Cornerstudqty1_p = arry[21]
@Cornertreatment1_p = arry[22]
@Corneroffset1_p = arry[23]
@Cornertr1_p = arry[24]
@Corner_end_p = arry[25]
@Cornerangle2_p = arry[26]
@Cornerstudthk2_p = arry[27].to_f
@Cornerstudqty2_p = arry[28]
@Cornertreatment2_p = arry[29]
@Corneroffset2_p = arry[30]
@Cornertr2_p = arry[31]
# Advanced Options
@Wallsheathoption_p = arry[32]
@Wallsheaththk_p = arry[33].to_f
@Wallsheathcorner_p = arry[34]
@Wallcladoption_p = arry[35]
@Wallcladthk_p = arry[36].to_f
@Wallcladgap_p = arry[37].to_f
@Wallcladcorner_p = arry[38]
@Wallgypsumoption_p = arry[39]
@Wallgypsumthk_p = arry[40].to_f
@Wallinsuloption_p = arry[41]
@Holdownoption_p = arry[42]
@Wallsheathvertoffset_t_p = arry[43].to_f
@Wallsheathvertoffset_b_p = arry[44].to_f
@Wallcladvertoffset_t_p = arry[45].to_f
@Wallcladvertoffset_b_p = arry[46].to_f
@Clad_mat_offset_p = arry[47].to_f
@Clad_mat_hoffset_p = arry[48].to_f
@Wallsheathmat_p = arry[49]
@Wallcladmat_p = arry[50]
@Wallgypsummat_p = arry[51]
@Wallinsulmat_p = arry[52]
@Blockingoption_p = arry[53]
@Trimoption_p = arry[54]
@Wsct_option_p = arry[55]
@Quoin_option_p = arry[56]
@Wallgypsum2option_p = arry[57]
@Wallgypsum2thk_p = arry[58].to_f
@Wallgypsum2mat_p = arry[59]
@Wallsheath2option_p = arry[60]
@Wallsheath2thk_p = arry[61].to_f
@Wallsheath2corner_p = arry[62]
@Wallsheath2mat_p = arry[63]
# Holdown Options
@Holdowntype_p = arry[64]
@Holdownvertoffset_p = arry[65].to_f
@Holdown_ab_p = arry[66]
@Thd_rod_length_p = arry[67].to_f
@Holdown_location_p = arry[68]
@Holdown_strap_loc_p = arry[69]
# Blocking Options
@Blockinghgt_p = arry[70]
@Staggerblocking_p = arry[71]
@Blockingnum_p = arry[72].to_i
@Blockingspacing_p = arry[73].to_f
# Trim Options
@Trimloc_p = arry[74]
@Trimthk_p = arry[75].to_f
@Trimoutoption_p = arry[76]
@Trimwidthout_p = arry[77].to_f
@Triminoption_p = arry[78]
@Trimwidthin_p = arry[79].to_f
@Trimcut_p = arry[80]
@Walltrimmat_p = arry[81]
@Trim_band_p = arry[82]
@Trim_band_width_p = arry[83].to_f
@Trim_band_thk_p = arry[84].to_f
@Trim_band_cont_p = arry[85]
@Trim_band_hgt_p = arry[86].to_f
@Trim_frieze_p = arry[87]
@Trim_frieze_width_p = arry[88].to_f
@Trim_frieze_thk_p = arry[89].to_f
@Trim_frieze_cont_p = arry[90]
@Trim_skirt_p = arry[91]
@Trim_skirt_width_p = arry[92].to_f
@Trim_skirt_thk_p = arry[93].to_f
@Trim_skirt_cont_p = arry[94]
@Trim_cap_p = arry[95]
@Trim_cap_height_p = arry[96].to_f
@Trim_cap_depth_p = arry[97].to_f
# Wainscot Options
@Wsct_hgt_p = arry[98].to_f
@Wsct_thk_p = arry[99].to_f
@Wsct_gap_p = arry[100].to_f
@Wsct_corner_p = arry[101]
@Wsct_mat_p = arry[102]
@Wsct_ledge_p = arry[103]
@Wsct_ledgeheight_p = arry[104].to_f
@Wsct_ledgedepth_p = arry[105].to_f
@Wsct_ledgewin_p = arry[106]
@Wsct_start_p = arry[107].to_f
@Wsct_end_p = arry[108].to_f
@Wsct_mode_p = arry[109]
@Wsct_ledgemat_p = arry[110]
# Quoin Options
@Q_style_p = arry[111]
@Q_l1_p = arry[112].to_f
@Q_l2_p = arry[113].to_f
@Q_hgt_p = arry[114].to_f
@Q_spc_p = arry[115].to_f
@Q_thk_p = arry[116].to_f
@Q_mat_p = arry[117]
end
else
#######################################
#
# Creates new preset file and folder
presetfoldername = File.join(APPDATA_MEDEEK_WALL,"presets")
unless Dir.exist?(presetfoldername)
puts "Creating Medeek Presets Folder: #{presetfoldername}"
begin
Dir.mkdir(presetfoldername)
rescue StandardError => e
UI.messagebox(e)
puts "Error Message: #{e}"
end
end
begin
File.open(@Presetfilename, 'w') { |file|
file.puts "#{MDK_WALL} Preset File\n"
}
rescue StandardError => e
UI.messagebox(e)
puts "Error Message: #{e}"
end
end