The goal is to create a copy of two existing template files (not opened) from "Resource" folder to a different path, the target files should have new names too (previously defined in a inputbox).
templates:
...\Resources\XXX AT Template.skp
...\Resources\XXX AT Template.xlsx
Here it is part of the script of my plugin, at the moment just trying to copy the skp file though:
require 'ftools.rb'
...
...
folder = File.dirname( __FILE__ )
resources = "Resources"
resource_name= "XXXXXX AT Template.skp"
resource_file = File.join(folder, resources, resource_name).tr("\\","/") # the script will be modified to select the directory via a UI.savepanel dialogue
file_name = "123456 AT aa.bb.skp" # the real name will be picked via an inputbox
desti_file = File.join(folder, file_name).tr("\\","/")
if File.exist?(resource_file)
File.copy(resource_file, desti_file, verbose = true)
else
puts "SKETCHUP TEMPLATE FILE NOT FOUND!"
return nil
end
...
...
The above script certainly creates the copy in the correct folder but SU crashes afterwards.
As the move() doesn't crash, I tried to modify it as follow:
def move(from, to, verbose = false)
to = catname(from, to)
$stderr.print from, " -> ", to, "\n" if verbose
# if RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/ and file? to
# unlink to
# end
fstat = stat(from)
begin
# rename from, to
# rescue
begin
ln from, to and unlink from
rescue
from_stat = stat(from)
syscopy from, to and unlink from
utime(from_stat.atime, from_stat.mtime, to)
begin
chown(fstat.uid, fstat.gid, to)
rescue
end
end
end
end
alias mv move
by using above move(), the resource_file is kept and the desti_file is created but SU crashes too.
I tried to use Fileutils.rb instead but there are lots of errors when open SU v.8 (I'm using !AdditionalPluginFolders.rb) and below doesn't work:
FileUtils.copy_file(resource_file, desti_file, preserve = false, dereference = true)