|
SketchUp Ruby API Reference |
The Pages class contains methods for manipulating a collection of Pages (scenes) in a model.
Parent: Entity
Methods: add_frame_change_observer, remove_frame_change_observer, [], add_observer,add, count, each, parent, remove_observer, selected_page, show_frame_at , size, slideshow_time
Example Code: pagestests.rb
The add_frame_change_observer method is used to add a new frame change observer for animations
pages.add_frame_change_observer object
object - an object that implements the frameChange method
The argument is an object that implements a method frameChange with the following form:
def frameChange(fromPage, toPage, parameter) ... end
This method is called during a slide show or creation of an animation after the camera has been set up, but before the frame is displayed. It give you a chance to perform your own actions during the animation. The arguments for frameChange method are the Page that you transition from (fromPage), the Page that you transition to (toPage), and a parameter between 0 and 1 that tell you the percentage of the way between the two pages.
The method returns an integer that can be used to remove the observer
number = Sketchup::Pages.add_frame_change_observer FrameChangeObserver.new
class FrameChangeObserver
def frameChange(fromPage, toPage, parameter)
# Just show the information
#s1 = fromPage ? fromPage.name : "NULL"
#s2 = toPage ? toPage.name : "NULL"
#puts "#{s1} to #{s2} at #{parameter}"
if( parameter < 1.0e-3 )
get_entities_to_move(toPage)
else
move_entities parameter
end
end
The remove_frame_change_observer method is used to remove a frame change observer
pages.remove_frame_change_observer(observer_num)
The argument is the number returned from the call to add_frame_change_observer.
number = Sketchup::Pages.remove_frame_change_observer
The [] method retrieves a page by either name or index.
page = pages[index]
page = pages["name"]
index - the index for a specific page
name - the name of the specific page
page - a Page object if successful
model = Sketchup.active_model
pages = model.pages
status = pages.add "Page 1"
status = pages.add "Page 2"
page = pages "Page 2"
if (page)
UI.messagebox page
else
UI.messagebox "Failure"
end
The add_observer method is used to add an observer to the current object.
status = object.add_observer observer
observer - an observer
true if successful, false if unsuccessful.
The add method is used to add a empty Page object
page = pages.add
page = pages.add name
page = pages.add name, flags
name - the name of the specific page
flags -
If no name is given, then a new name is generated using the default name for new Pages.
If a name is given, then a new Page with that name is added.
If flags is given, it controls which properties are saved with the new Page. See Page.update for a description of the flags that can be set.
model = Sketchup.active_model
pages = model.pages
status = pages.add "Page 1"
status = pages.add "Page 2"
if (status)
UI.messagebox status
else
UI.messagebox "Failure"
end
The count method is an alias for size. See also Page.size
num_pages = pages.count
num_pages - the number of pages if successful
model = Sketchup.active_model
pages = model.pages
status = pages.add "Page 1"
status = pages.add "Page 2"
num = pages.count
The each method is used to iterate through pages.
pages.each {| page |...}
page – variables that will hold each page as it is found.
model = Sketchup.active_model
pages = model.pages
status = pages.add "Page 1"
status = pages.add "Page 2"
pages.each {|page| UI.messagebox page}
The parent method is used to determine the model for the pages.
model = pages.parent
model - the model that contains the pages if successful
model = Sketchup.active_model
pages = model.pages
status = pages.add "Page 1"
status = pages.add "Page 2"
model = pages.parent
The remove_observer method is used to remove an observer from the current object.
status = object.remove_observer observer
observer - an observer
true if successful, false if unsuccessful.
The selected_page method is used to retrieve the currently selected page.
page = pages.selected_page
page - the currently selected Page object if successful
model = Sketchup.active_model
pages = model.pages
status = pages.add "Page 1"
status = pages.add "Page 2"
page = pages.selected_page
The show_frame_at method is used to show a frame in animation (of the slide show) at a given time in seconds.
pages.show_frame_at time_in_seconds
time_in_seconds - the time in seconds
model = Sketchup.active_model
pages = model.pages
status = pages.add "Page 1"
status = pages.add "Page 2"
status = pages.show_frame_at 10
The size method is used to retrieve the number of pages.
num_pages = pages.size
num_pages - the number of pages
model = Sketchup.active_model
pages = model.pages
status = pages.add "Page 1"
status = pages.add "Page 2"
size = pages.size
The slideshow_time method is used to retrieve the amount of time that a slideshow of all of the pages will take.
time = pages.slideshow_time
time - the amount of time that a slide show will take if successful
This takes into account the transition time for each Page and the amount of time that each Page is displayed.
model = Sketchup.active_model
pages = model.pages
status = pages.add "Page 1"
status = pages.add "Page 2"
status = pages.show_frame_at 10
time = pages.slideshow_time
|
SketchUp Ruby API Reference: Pages |
© Google Inc. 2007 sketchup.google.com |