有json文件就拿取路徑,沒有就創(chuàng)建文件
path = Sketchup.active_model.path
poj_ph = File.dirname(path)
poj_ph.gsub!(/\\/, "/") #字符串替換 .rstrip
dir_path = poj_ph + "/render"
FileUtils.mkdir_p(dir_path) unless File.exists?(dir_path)
# 去掉路徑字符串中的雙斜杠
dir_path.gsub!(/\/\//, '/')
file = File.join(dir_path,"gdp_render.json")
unless File.exists?(file)
f=File.new(file,"w+")
#************#創(chuàng)建哈希數(shù)據(jù)
hash = {"tiles":"1"}
json = JSON.generate(hash)
f.puts(json)
#************
f.close
end
json = JSON.parse(File.read(file))
json = JSON.generate(json)
File.open(file,"w"){|f|
f.syswrite(json)
}