You can mark which pages to ignore by inserting a indicator in the description attribute. Assume the first char of pg.description[0,1] is '!' (… you’ll have to manually marked the pages to ignore.)
model = Sketchup.active_model
model_path = File.dirname(model.path)
model_name = model.name
if model_name.empty?
model_name = "untitled"
ret = UI.inputbox(
["Enter model name: "],
[model_name],
"Model Name"
)
model_name = ret[0] if ret != false
end
enab = model.pages.find_all {|pg|
pg.description[0,1] != '!'
}
if !enab.empty?
filename = File.join(
model_path,
"#{model_name}_camera.txt"
)
File.open(
filename,
mode: "w",
encoding: "UTF-8:UTF-8",
textmode: true,
cr_newline: true
) {|file|
# for each enabled pages
enab.each {|pg|
file.puts "#{pg.name} : #{pg.camera.description}"
}
} # the file is closed automatically
end
EDITED: Changed File.new to File.open, used Ruby 2.0 named arguments.
Sorry, a quirk of Ruby 2.0, I changed the call to use File::open(), (see above.)
It is an example. Change the put statement to whatever you like.
Add in calls to camera attributes, like: #{page.camera.eye.inspect}
etc. See the API on the [Sketchup::Camera][1] class.
UI::inputbox() will return false if the user cancels the window with the “Cancel” or “X” buttons.
But if they do not and click the “OK” button, the method returns an Array of the values from the inputbox window.
The example above, has only 1 text value control for the inputbox, so it will be ret[0] if the user clicked “OK”, but if the user cancelled, ret will NOT be an array, it will be a false value.
So this statement is testing the result from the UI.inputbox() method:
@tt_su: Can we rely upon iterators returning the pages from the pages collection, in user interface order ? (The UI has a move up and move down feature.)
model.pages.each_with_index{|pg,i|
next if pg.description[0,1] == '!'
puts "#{pg.name} : position #{ i+1 }"
}
Full example:
model = Sketchup.active_model
if !model.pages.size == 0
model_path = File.dirname(model.path)
model_name = model.name
if model_name.empty?
model_name = "untitled"
ret = UI.inputbox(
["Enter model name: "],
[model_name],
"Model Name"
)
model_name = ret[0] if ret != false
end
filename = File.join(
model_path,
"#{model_name}_camera.txt"
)
File.open(
filename,
mode: "w",
encoding: "UTF-8:UTF-8",
textmode: true,
cr_newline: true
) {|file|
# for each enabled pages
model.pages.each_with_index {|pg,i|
next if pg.description[0,1] == '!'
file.puts "#{pg.name} : position #{ i+1 }"
}
} # the file is closed automatically
else
UI.messagebox( "Model has no scene pages!" )
end
Hm… Good question. Looking at the API implementation this is undetermined - it just iterates the collection. From a quick glance it looks like it iterates in the order it’s stored in memory. Question is, does the items get re-arranged as pages are moved…