Hi,
I wanted to retrieve the saved file name but the following is not working…
model = Sketchup.active_model
name = model.name
The workaround for this was the following…
model = Sketchup.active_model
path = model.path[0...-4]
name = path.split('\\')
name = name.last
Does the API have an easier method to get the file name?
Thanks in advance!
YES. It is Sketchup::Model#title()
, but it returns the filename minus the ".skp"
.
Sketchup::Model#name()
just returns the name attribute that is set manually on the Model Info dialog’s File panel, or via code by the Sketchup::Model#name=()
method.
And BTW, getting the filename from a path string in Ruby is this simple …
filename = File.basename(Sketchup.active_model.path)
# or minus the extension ...
filename = File.basename(Sketchup.active_model.path,".*")
1 Like
Thank you very much!
I wanted to save all SketchUp versions from 8 to 2018 with a single action. If anyone else need this here is a simple script…
model = Sketchup.active_model
path = model.path[0...-4]
title = model.title
versions = {
"8": Sketchup::Model::VERSION_8,
"2013": Sketchup::Model::VERSION_2013,
"2014": Sketchup::Model::VERSION_2014,
"2015": Sketchup::Model::VERSION_2015,
"2016": Sketchup::Model::VERSION_2016,
"2017": Sketchup::Model::VERSION_2017,
"2018": Sketchup::Model::VERSION_2018
}
versions.each do |key, value|
filename = File.join(path, "#{title}_v#{key}.skp")
status = model.save_copy(filename, value)
end
Enjoy!